Bitcoin (BIP-122)
TrustConnect provides React hooks for Bitcoin wallet interactions using the BIP-122 CAIP namespace.
Installation
pnpm add @trustwallet/connect-bip122-reactSetup
Configure Bitcoin using createBIP122:
import { createBIP122, mainnet as bip122Mainnet } from '@trustwallet/connect-bip122-react'
const bip122 = createBIP122({
chain: bip122Mainnet,
})Then add it to the namespaces array in your TrustConnectProvider configuration. See Quickstart for the full setup.
Sign messages
useSignMessage
Sign a message with the connected Bitcoin wallet. Supports both ECDSA and BIP-322 signing protocols:
import { useSignMessage } from '@trustwallet/connect-bip122-react'
import { useConnection } from '@trustwallet/connect-react'
function BitcoinSignMessage() {
const { isConnected } = useConnection({ namespaceId: 'bip122' })
const {
mutate: sign,
data: signature,
isPending,
isSuccess,
error,
} = useSignMessage()
const handleSign = () => {
if (!isConnected) return
sign({
message: 'Hello from TrustConnect SDK!',
protocol: 'ecdsa', // or 'bip322'
})
}
return (
<div>
<button onClick={handleSign} disabled={isPending || !isConnected}>
{isPending ? 'Signing...' : 'Sign Message'}
</button>
{isSuccess && signature && (
<div>
<p>Message signed!</p>
<code>{signature.signature}</code>
</div>
)}
{error && <p>Error: {error.message}</p>}
</div>
)
}Sign PSBTs
useSignPsbt
Sign a Partially Signed Bitcoin Transaction (PSBT):
Parameter
Type
Description
psbt
string
Base64-encoded PSBT
signInputs
array
Array of input objects with index, optional address, publicKey, and sighashType
finalize
boolean
Whether the wallet should finalize and broadcast the PSBT
Send transfers
useSendTransfer
Send a simple BTC transfer:
Parameter
Type
Description
toAddress
string
Destination Bitcoin address
satoshis
number
Amount in satoshis
Last updated
Was this helpful?