Orange Connect
Orange Connect offers a streamlined JavaScript library designed to facilitate the integration of Orange Wallet functionalities into decentralized applications (DAPPS). It enables the retrieval of wallet addresses from users, as well as the initiation of transaction signings and message signatures.
This guide outlines the fundamental operations you can perform with Orange Connect, including:
Acquiring wallet address(es) from users
Initiating the signing process for Bitcoin transactions that are partially signed (PSBTs)
Signing arbitrary messages
Conducting Bitcoin transactions to single or multiple recipients
Embedding arbitrary content into satoshis
Begin by incorporating Orange Connect into your project with the following command:
Connecting to the User's Wallet with getAddress
getAddress
Overview
The getAddress
function plays a pivotal role in integrating user wallet connectivity into your application. This method facilitates the acquisition of user wallet addresses from Bitcoin and Stacks networks, requiring user permission through a prompt.
Implementation Steps
Initial Setup: Begin by importing the
getAddress
method from the@orangecrypto/orange-connect
library to leverage its capabilities within your application.
Configuring Request Parameters: Tailor your request to fit your application's needs by specifying desired wallet addresses and custom messages. These parameters are encapsulated within an options object passed to
getAddress
.
Network Selection: Define the Bitcoin network context (Mainnet or Testnet) for the operation.
Address Purposes: Indicate the types of addresses you're requesting: Bitcoin ordinals address, Bitcoin payment address, or Stacks address.
User Prompt Message: Craft a concise message explaining the reason for the address request to be displayed in the wallet connection prompt.
Example Configuration:
Executing the Request: Invoke
getAddress
with the previously defined options. This method returns a promise, resolving upon user approval with their wallet addresses.javascriptCopy code
await getAddress(getAddressOptions);
Understanding the Response
Upon successful request approval, getAddress
returns an object containing an array of wallet address details. Each address object includes:
Address: The wallet address string.
Public Key: A hexadecimal string representing the public key associated with the address.
Purpose: Categorized use of the address (
"payment"
,"ordinals"
, or"stacks"
).Address Type: Specifies the address format (e.g.,
"p2tr"
for Taproot addresses).
Handling User Actions
On Approval: The
onFinish
callback function is executed, where you can handle the received addresses.On Cancellation: If the user declines or dismisses the prompt, the
onCancel
callback is invoked.
Utilizing signMessage
signMessage
To initiate a signature request, use the signMessage
method provided by Orange Connect. This method supports message signing through two distinct signature schemes, depending on the type of Bitcoin address used:
ECDSA Signatures: Utilized for messages signed with BTC payment addresses, specifically those of the type
p2sh(p2wpkh)
.BIP322 Signatures: Employed when signing with Ordinals addresses, or
p2tr
.
Preparing the Signature Request
Your request to sign a message must include details about the network, the address performing the signing, and the message itself. Here's a breakdown of the required fields:
Network: Specifies whether the target Bitcoin chain is Mainnet or Testnet.
Address: The Bitcoin address used to sign the message.
Message: The actual content you wish the wallet to sign.
Example Signature Request
Configure your request as follows, replacing values as necessary to suit your application's needs:
How to Use sendBtcTransaction
sendBtcTransaction
By invoking sendBtcTransaction
, you can specify the details of your transaction, including the recipients, the sender address, and the network (Mainnet or Testnet). Here's a brief overview of the payload parameters:
Recipients: A list detailing the addresses and the corresponding amounts (in satoshis) to be sent.
Sender Address: Specifies the originating address for the transaction funds.
Network: Determines the Bitcoin network over which the transaction is conducted.
Sample Transaction Request
The following example demonstrates how to construct a transaction request, sending Bitcoin to multiple recipients:
Upon request, the user will be prompted to review and confirm the transaction in their wallet, ensuring transparency and user control over the transaction process.
Implementing signTransaction
signTransaction
The signTransaction
method provided by Orange Connect is your gateway to initiating PSBT signings. This method requires a base64-encoded PSBT, which can be prepared using any reputable Bitcoin library. Here's how to define the payload for your signing request:
Network: Indicates the Bitcoin network, choosing between Mainnet and Testnet.
psbtBase64: The PSBT encoded in base64 format.
Broadcast: A boolean flag to determine whether the signed transaction should be automatically broadcasted.
InputsToSign: Details the specific inputs within the transaction that require signing, including the address and index of each input.
Constructing a Signing Request
To prepare your transaction for signing, define your request as follows, adjusting the parameters to fit your transaction's requirements:
javascriptCopy code
This setup ensures you can specify which inputs to sign and which addresses are used for signing, providing flexibility and security for transaction operations.
Initiating Inscriptions
Leveraging the createInscription
function from Orange Connect, your application can help users embed their desired content into the blockchain. This action is executed from the user's wallet address, with the final inscription manifesting in their ordinals address.
For those looking to monetize their services, Orange Connect can incorporate a service fee directly into the inscription transaction. This is achieved through the optional appFee
and appFeeAddress
parameters, adding an additional output to the transaction for the service charge.
Upon user consent, the inscription transaction is promptly broadcasted, and the transaction ID is returned for tracking purposes.
Payload Parameters
network: Designates the Bitcoin network, restricted to Mainnet for inscriptions.
contentType: Specifies the MIME type of the inscribed content, essential for accurate content representation.
payloadType: Defines the content format, which can be either "PLAIN_TEXT" for direct inscriptions or "BASE_64" for binary data.
content: The actual data to be inscribed and tailored according to the payload type.
appFee (optional): The service charge for the inscription, in satoshis.
appFeeAddress (optional): The recipient address for the service fee.
suggestedMinerFeeRate (optional): Proposes an initial miner fee rate, adjustable by the user in their wallet.
Examples
Text Inscription:
Binary Data Inscription:
React Component for File Inscriptions
For applications built with React, the following component provides a user interface for creating inscriptions from files:
This component simplifies the process of uploading and inscribing binary data, providing a straightforward interface for users to interact with the blockchain in an innovative way.
Last updated