Introduction to ChainBow Wallet Integration
Developers and businesses can seamlessly integrate ChainBow Wallet's payment API using the following workflow. All current APIs are built on WalletConnect 2.0, requiring projects to import its dependencies.
👉 Explore WalletConnect integration examples
Preparation Phase
Key Components
- WalletConnect API: The bridge between DApps and wallets.
- DAppDemo Project: A reference implementation available on GitHub.
Initialization Code
await WalletConnectClient.init(
Object.assign(
{
relayUrl: "wss://domain", // Custom or WalletConnect's official server
} as ClientOptions,
opts ?? {}
)
);Connection Management
- Connect: Use
connect()to link with WalletConnect Server. - Disconnect: Use
disconnect()to terminate the session.
Wallet Integration Steps
1. Establishing Connection
DApp Data Structure:
| Field | Description |
|---|---|
name | DApp name |
description | Functional overview |
url | Official website |
icons | DApp icon URL |
const wc = useWallet();
await wc.connect(DAPP);Response Format:
bsv:livenet:alias|domain|address|signatureExample:
bsv:livenet:test_account|chainbow.io|1BikvsWbVmLC9R9inrtRLQ7j2qBpMJVUfT|Hxj8kJ7ZdDC8zgtCAZopEQ01VUPI4Gl+L8L26IYKcsh/Mp1nhlxniTGFuPYTCPZMNA3ovlHdVED43r+QLiaYwmw=2. Signature Verification
Method: signMessage
Purpose: Authenticate DApp-wallet pairing.
Input:
| Field | Description |
|---|---|
address | Bitcoin address |
message | Data to sign |
await wc.signMessage({ address: data.address, message: data.message });Output:
| Field | Description |
|---|---|
signature | Signed message data |
Validation:
const result = Message.verify(data.message, data.address, data.sig);3. Transaction Processing
Single Transaction (sendTransaction)
Input:
| Field | Description |
|---|---|
to | Target address/script |
format | 'address', 'paymail', or 'script' |
amount | Transfer amount in satoshis |
await wc.sendTransaction({
outputs: [{
to: data.toAddress,
format: data.format?.value.toString(),
amount: data.amount.toString(),
}],
});Response:
{
"txId": "91256db99f8756d757fa72f2bf57b6c2bb45e9ce2d6e4a5d78ff70d89b6d53c9",
"time": 1645501589365,
"fee": 200,
"amount": 600
}Batch Transactions (sendRawTransaction)
Input:
| Field | Description |
|---|---|
rawHex | Signed transaction hex |
Response:
| Field | Description |
|---|---|
txId | Transaction ID |
4. Transaction Signing (signTransaction)
Input Structure:
ITransaction:
inputs: PrevTxId, outputIndex, satoshis, lockingScript.outputs: to (script hex), format ('script'), amount.
- signRequests: inputIndex, address, sigtype.
const request: ISignTransaction = {
transaction: {
inputs: [{ prevTxId: data.prevTxId, outputIndex: data.outputIndex, ... }],
outputs: [{ to: script.toHex(), format: 'script', amount: String(data.outputSatoshis) }],
},
signRequests: [{
inputIndex: 0,
address: data.address,
sigtype: bsv.crypto.Signature.SIGHASH_ANYONECANPAY | ...,
}],
};
await wc.signTransaction(request);Output:
"signatures": [{
"prevTxId": "35a7c737b2e39b7b81219cc1628402a795e7e8a48b6e940207b912123f5e43c1",
"outputIndex": 0,
"signature": "304402206738aafa8df6179e2511a08b9646db1c6957d25a48f20134704ef7e84d7c25e10220417fac6e495d006d92519b847874e47519c88e0239ce5cba8e1ffec21d61cd1641",
"pubkey": "03753e4161e7dab8ca0de4350004af544ced8cdd17494df6597d4f7c12e3e0ed2a",
"sigtype": 65,
"inputIndex": 0
}]Error Handling
| Error Code | Description |
|---|---|
User rejected the request | Wallet denied authorization |
UnknownAddress | Invalid Bitcoin address |
Session not approve | Wallet refused login |
JSON-RPC Request timeout | Wallet response timeout (300s) |
👉 Troubleshoot common wallet errors
FAQs
Q1: How do I handle WalletConnect session timeouts?
A1: Implement automatic reconnection logic and notify users to re-authenticate if sessions expire.
Q2: What’s the recommended way to test DApp-wallet interactions?
A2: Use BSV testnet for development and validate all edge cases (e.g., insufficient funds, invalid addresses).
Q3: Can Paymail addresses be used interchangeably with Bitcoin addresses?
A3: Yes, but ensure your DApp resolves Paymail to Bitcoin addresses via Paymail providers.
Q4: How are transaction fees calculated?
A4: Fees depend on transaction size (bytes). ChainBow Wallet auto-calculates this, but you can override it.
Q5: Is WalletConnect 2.0 backward-compatible?
A5: No, migrate existing integrations to WalletConnect 2.0 for enhanced security and features.