Developer Guide

Connect ChainBow

Dapp developers can connect the Chainbow Wallet payment API as described below.

Right now all the API are based on WalletConnect 2.0open in new window

The connected project needs to import the code base of WalletConnect 2.0

DAppDemoopen in new window

Preparation

Steps

WalletConnect API

Initialization

await WalletConnectClient.init(
        Object.assign(
          {
            relayUrl: wss://domain
          } as ClientOptions,
          opts ?? {}
        )
      );
1
2
3
4
5
6
7
8

connect

The DApp connects to the WalletConnect server through WalletConnect's Connect () function.

disconnect

The DApp disconnects the WalletConnect server through WalletConnect's disconnect() function.

Wallet APIs

connect wallet

DAPP Structure

FieldDescription
nameDApp's name
descriptionDApp's description
urlDApp's website
iconsDApp's icon
  const wc = useWallet();
  await wc.connect(DAPP);
1
2

Response

FieldDescription
bsv:livenetbsv's mainnet or testnet
aliaspaymail's address
domaindomain
addresswallet's address
signatureRandom publicKey signature in the session
const account = session.state.accounts[0];

"bsv:livenet:test_account 
 | chainbow.io 
 | 1BikvsWbVmLC9R9inrtRLQ7j2qBpMJVUfT
 | Hxj8kJ7ZdDC8zgtCAZopEQ01VUPI4Gl+L8L26IYKcsh/Mp1nhlxniTGFuPYTCPZMNA3ovlHdVED43r+QLiaYwmw="
 
 

1.namespace, network Using the ':' division

2.Account field use '|'

bsv:livenet:alias|domain|address|signature

If there is no alias return structure

bsv:livenet:address| |address|signature

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

SignMessage

Sign any message with the specified address

Sign any non-transactional data with a Bitcoin private key,

which works for any kind of authentication, such as signing a public statement of ownership of a particular bitcoin address.

This standard is sometimes called Bitcoin Signature Message.

Input structure

FieldDescription
addressaddress
messageSignature information
  await wc.signMessage({address: data.address,message: data.message})
1

Response

FieldDescription
signatureThe message after signature of the data

Verify signature

// Verify that the signature data is valid
const result = Message.verify(data.message, data.address, data.sig);

1
2
3

SendTransaction

Creates a transaction: sending Satoshi or Token to specified address.

Input structure

Input array outputs, the output data structure is as follows

FieldDescription
toThe target address(According to the format to fill in)
format'address' or 'paymail' or 'script':
amountamount
  await wc.sendTransaction({
            outputs: [
              {
                to: data.toAddress,
                format: data.format
                  ? (data.format as any).value.toString()
                  : undefined,
                amount: data.amount.toString(),
              },
            ],
          })
1
2
3
4
5
6
7
8
9
10
11

Response

FieldDescription
txIdthe id of transaction
timetime
feefee
amountamount
{
    txId: '91256db99f8756d757fa72f2bf57b6c2bb45e9ce2d6e4a5d78ff70d89b6d53c9', 
    time: 1645501589365, 
    fee: 200,
    amount: 600
}
1
2
3
4
5
6

SignTransaction

Call the method sendRawTransaction

The wallet is requested to sign the transaction, and once the signature is obtained, the transaction can be broadcast using sendRawTransaction .

const res = await wc.sendRawTransaction([rawHex])
1

1.The input data structure

FieldDescription
rawHextransaction
{
  "rawHex": "01000000018cb9bbfd577afc4811381ac5f6b59c849e85699b31efbc292df812bed71a4635020000006a4730440220676c32d64a9826ecca238427ca84fe11b38a3ec26f89f23b5e73c81ec90e96c302201d5a301febe58e8d42ea2aa2ebdb4b02430c284f1f9504cfdb1def601294464c41210200104c2d3a77bfe8c08a639a561f687197e9e25e94f49018e0a5f87275cf1877ffffffff030000000000000000fd5c01006a223143516150395562486f39675965526d36347864326d6f694251426334456f4471660840899be574ff17004ce54249453103d5f4ba7b8a03de98bdc8d6df2b1e5e61c8eb33a9250b8d178afd8bf06d939d662e7a6fb865ba6f5100b54dfd289061ae902eebf946c5701ecd02b38393590ad484a08c0694e5d201519560d472a9f6c64ecfb0dbe942af17a4d1e877bd6593296bda8f3c39fda07ad5d368517c2124705e44a7b228c5425019c3000ce9d66834eccb10fafdd5c6ad382757454c13fc4b8900fba5f44f8bccd63f289837708775cfd4dade9262956e422b66418289931095956717294bef65f5d453c842743c7511ce88efcdb1f5eb2ef05e80422c324401dcbaabab8e01d5ba122de408ae0521463044022024a25971f83367790b12ace5f58f784a41dcb63fddbd2c3084936e9692b02d2b022036407934c5f661577b9a10b55f509848512154ba3d99fbcb69ab5988d54db67022020000000000001976a9142b3d8b2dae6fedb6f038acf357746d1662b05c4988ac79f13400000000001976a914fbae7a3dae29183e1f37bbd48dff68b4c56476a788ac00000000"
}
1
2
3

Response

FieldDescription
txIdTransaction id

Send signed transaction

use signTransaction。 Send the constructed signed transaction, and broadcast to the blockchain through the wallet.

The input data structure

Input ITransaction (contain inputs and outputs of two arrays), signRequest

ITransaction.inputs

FieldDescription
prevTxIdprevTxId
outputIndexoutputIndex
satoshissatoshis
lockingScriptlockingScript

ITransaction.outputs

FieldDescription
toconst script = bsv.Script.buildPublicKeyHashOut(data.toAddress); return script.toHex()
format'script'
amountamount

signRequests Array

FieldDescription
inputIndexinputIndex(0)
addressAddress of the Bitcoin
sigtypebsv.crypto.Signature.SIGHASH_ANYONECANPAY
  const transaction: ITransaction = {
        inputs: [
          {
            prevTxId: data.prevTxId,
            outputIndex: data.outputIndex,
            satoshis: data.satoshis,
            lockingScript: data.lockingScriptHex,
          },
        ],
        outputs: [
          {
            to: script.toHex(),
            format: 'script',
            amount: String(data.outputSatoshis),
          },
        ],
      };


 const request: ISignTransaction = {
        transaction,
        signRequests: [
          {
            inputIndex: 0,
            address: data.address,
            sigtype: bsv.crypto.Signature.SIGHASH_ANYONECANPAY | bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID
          },
        ],
      };

 await wc.signTransaction(request)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Response

Return array of signatures and signature structure is as follows

FieldDescription
prevTxIdprevTxId
outputIndexoutputIndex
satoshissatoshis
sequenceNumbersequenceNumber
signatureAfter the signature of data
pubkeyThe public key
sigtypesigtype
inputIndexinputIndex
"signatures": [
        {
            "prevTxId": "35a7c737b2e39b7b81219cc1628402a795e7e8a48b6e940207b912123f5e43c1",
            "outputIndex": 0,
            "satoshis": 1280900,
            "sequenceNumber": 4294967295,
            "signature": "304402206738aafa8df6179e2511a08b9646db1c6957d25a48f20134704ef7e84d7c25e10220417fac6e495d006d92519b847874e47519c88e0239ce5cba8e1ffec21d61cd1641",
            "pubkey": "03753e4161e7dab8ca0de4350004af544ced8cdd17494df6597d4f7c12e3e0ed2a",
            "sigtype": 65,
            "inputIndex": 0
        }
 ]

1
2
3
4
5
6
7
8
9
10
11
12
13

Error Code

ErrorCodeDescription
Error: User rejected the requestThe wallet rejects the authorization request.
Error: UnknownAddressBitcoin address doesn't match the format
Error: Session not approveThe wallet rejects the log in with authorization.
Error: JSON-RPC Request timeout after 300 secondsWallet response timed out
Last Updated:
Contributors: Ambince, Long Li