> For the complete documentation index, see [llms.txt](https://developer.trustwallet.com/developer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.trustwallet.com/developer/trustconnect/bitcoin.md).

# Bitcoin (BIP-122)

TrustConnect provides React hooks for Bitcoin wallet interactions using the BIP-122 CAIP namespace.

## Installation

```bash
pnpm add @trustwallet/connect-bip122-react
```

## Setup

Configure Bitcoin using `createBIP122`:

```tsx
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](/developer/trustconnect/quickstart.md) for the full setup.

## Sign messages

### useSignMessage

Sign a message with the connected Bitcoin wallet. Supports both ECDSA and BIP-322 signing protocols:

```tsx
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):

```tsx
import { useSignPsbt } from '@trustwallet/connect-bip122-react'

function BitcoinSignPsbt() {
    const { mutate: signPsbt, isPending } = useSignPsbt()

    const handleSignPsbt = () => {
        signPsbt({
            psbt: 'cHNidP8BA...', // Base64 encoded PSBT
            signInputs: [
                { index: 0, sighashType: 1 },
            ],
            finalize: false,
        })
    }

    return (
        <button onClick={handleSignPsbt} disabled={isPending}>
            {isPending ? 'Signing...' : 'Sign PSBT'}
        </button>
    )
}
```

| 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:

```tsx
import { useSendTransfer } from '@trustwallet/connect-bip122-react'

function BitcoinTransfer() {
    const { mutateAsync: sendTransfer, isPending } = useSendTransfer()

    const handleTransfer = async () => {
        try {
            const result = await sendTransfer({
                toAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
                satoshis: 10000,
            })
            console.log('Transaction ID:', result.txid)
        } catch (error) {
            console.error('Transfer failed:', error)
        }
    }

    return (
        <button onClick={handleTransfer} disabled={isPending}>
            {isPending ? 'Sending...' : 'Send BTC'}
        </button>
    )
}
```

| Parameter   | Type     | Description                 |
| ----------- | -------- | --------------------------- |
| `toAddress` | `string` | Destination Bitcoin address |
| `satoshis`  | `number` | Amount in satoshis          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.trustwallet.com/developer/trustconnect/bitcoin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
