Skip to content
Developer Handbook

Dapp connection protocols

WalletConnect for BCH

On this page

To request a BCH signature over WalletConnect v2, pair with a wallet first. The wallet approves the network and methods the app can use in that session. The WC2-BCH specification defines the requests under the bch namespace.

Propose a session

Initialize @walletconnect/sign-client with your project ID and app metadata. Use bch:bitcoincash for mainnet. Use bch:bchtest only when the wallet and dapp agree on the same BCH test chain. The identifier is shared across BCH testnet variants.

const chainId = 'bch:bitcoincash';
const pairing = await client.connect({
  requiredNamespaces: {
    bch: {
      chains: [chainId],
      methods: ['bch_getAddresses', 'bch_signTransaction'],
      events: ['addressesChanged'],
    },
  },
});

if (pairing.uri) showPairingQr(pairing.uri);
const session = await pairing.approval();

const addresses = await client.request({
  topic: session.topic,
  chainId,
  request: { method: 'bch_getAddresses', params: {} },
});

Check the returned session’s approved chain and methods before enabling actions. Store only the session state your SDK requires. Refresh addresses and transaction drafts when the selected account changes or the session ends.

Request transaction approval

Send the proposed transaction plus one record in sourceOutputs per input, in input order. Each record identifies the UTXO being spent by outpoint and includes its BCH value, locking bytecode, and any token data. Use Libauth’s extended JSON encoding where needed for values such as bigint and Uint8Array.

import { stringify } from '@bitauth/libauth';

const result = await client.request({
  topic: session.topic,
  chainId,
  request: {
    method: 'bch_signTransaction',
    params: {
      transaction: rawUnsignedHex,
      sourceOutputs: JSON.parse(stringify(sourceOutputs)),
      broadcast: false,
      userPrompt: 'Review payment',
    },
  },
});

The result of JSON.parse(stringify(sourceOutputs)) is an array containing the protocol’s tagged strings. With broadcast: false, decode the returned signedTransaction, check it against the intended spend and submit it explicitly. The specification defaults broadcast to true.

Message signing and lifecycle

Request bch_signMessage when needed and verify signatures using the BCH signed-message format and the connected address. Handle rejected requests and disconnected or expired sessions. Optional methods, including batch signing and cancellation extensions, require support from the connected wallet.

WC2-BCH protocol reference · WC2-BCH specification · Reference dapp examples