> For the complete documentation index, see [llms.txt](https://docs.squidrouter.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.squidrouter.com/api-and-sdk-integration/chain-integration-guides/bitcoin-intents.md).

# Bitcoin Intents

Squid Intents support for Bitcoin enables fast, solver-driven cross-chain swaps from Bitcoin (BTC) to any supported EVM chain.

## Prerequisites

1. **Integrator ID**: Squid Intents must be enabled for your integrator ID. Contact the Squid team to get this set up.
2. **Bitcoin Wallet Address**: The source wallet must be a Native SegWit (Bech32) address (starting with `bc1q`).

***

## Step 1: Request Route

Request a route using the standard `/v2/route` endpoint (via API or SDK) with Bitcoin parameters:

* `fromChain`: `"bitcoin"`
* `fromToken`: `"satoshi"`
* `fromAddress`: Native SegWit address of the user (e.g. `bc1q...`)

```typescript
const params = {
  fromAddress: "bc1qzea6nfdfmztwjcn8htqn4tk9j3v2uawf4rck0g",
  fromChain: "bitcoin",
  fromToken: "satoshi",
  fromAmount: "70000", // Amount in satoshis
  toChain: "42161", // Arbitrum
  toToken: "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
  toAddress: "0xC601C9100f8420417A94F6D63e5712C21029525e",
  quoteOnly: false
};

// API:
// const routeResult = await axios.post("https://v2.api.squidrouter.com/v2/route", params, { headers: { "x-integrator-id": integratorId } });
// const route = routeResult.data.route;
// const quoteId = route.quoteId;

// SDK:
// const { route, requestId } = await squid.getRoute(params);
// const quoteId = route.estimate.quoteId || route.quoteId;
```

> \[!IMPORTANT] Save the `quoteId` returned in the route response. It is mandatory for tracking transaction status.

## Step 2: Sign the PSBT

The `transactionRequest` object returned in the route response contains the transaction payload. Check the `transaction_request_type` (or `type`) field. For Squid Intents, this will be:

`DEPOSIT_ADDRESS_CALLDATA`

The `transactionRequest.data` field contains a hex-encoded Partially Signed Bitcoin Transaction (PSBT). You must prompt the user's wallet to sign this PSBT.

#### Browser Wallet Example (UniSat Wallet)

```typescript
const transactionRequest = route.transactionRequest;

if (transactionRequest.transaction_request_type === "DEPOSIT_ADDRESS_CALLDATA") {
  const psbtHex = transactionRequest.data;
  
  // Sign and finalize the PSBT with UniSat Wallet
  const signedPsbtHex = await window.unisat.signPsbt(psbtHex, {
    autoFinalized: true
  });
  
  // Broadcast the transaction
  const txHash = await window.unisat.pushPsbt(signedPsbtHex);
  console.log("Broadcasted Tx Hash:", txHash);
}
```

#### Node.js / Backend Example (`bitcoinjs-lib`)

```typescript
import * as bitcoin from 'bitcoinjs-lib';
import ECPairFactory from 'ecpair';
import * as ecc from 'tiny-secp256k1';

bitcoin.initEccLib(ecc);
const ECPair = ECPairFactory(ecc);
const keyPair = ECPair.fromWIF(privateKeyWIF, bitcoin.networks.bitcoin);

const psbt = bitcoin.Psbt.fromHex(transactionRequest.data, { network: bitcoin.networks.bitcoin });
psbt.signAllInputs(keyPair);
psbt.finalizeAllInputs();

const tx = psbt.extractTransaction();
const txHex = tx.toHex();
const txHash = tx.getId();
```

## Step 3: Broadcast Transaction

Submit the raw transaction hex to the Bitcoin network. If using a browser extension wallet like UniSat, this is done automatically using `pushPsbt`. For backend scripts, you can broadcast using a public block explorer API (e.g. Blockstream):

```typescript
const response = await axios.post('https://blockstream.info/api/tx', txHex);
```

## Step 4: Status Polling

You must poll the status API to confirm the completion of the swap.

> \[!WARNING] For all Squid Intent transactions, **you must include the `quoteId` in the status query parameters.** If `quoteId` is omitted, the transaction cannot be correlated with the Intent and will be automatically refunded on the Bitcoin chain after 15 minutes.

#### API Status Polling

```typescript
const getStatus = async (txHash: string, quoteId: string) => {
  const result = await axios.get("https://v2.api.squidrouter.com/v2/status", {
    params: {
      transactionId: txHash,
      fromChainId: "bitcoin",
      toChainId: "42161",
      quoteId: quoteId // Required for Squid Intents
    },
    headers: {
      "x-integrator-id": integratorId
    }
  });
  return result.data;
};
```

#### SDK Status Polling

```typescript
const status = await squid.getStatus({
  transactionId: txHash,
  requestId: requestId,
  integratorId: integratorId,
  fromChainId: "bitcoin",
  toChainId: "42161",
  quoteId: quoteId // Required for Squid Intents
});
```

***

## Complete Examples

Ready-to-run integration examples are available in our GitHub repository:

* **API Example**: [Bitcoin to EVM Intents API Sample](https://github.com/0xsquid/examples/tree/main/V2/api/bitcoinToEVM_Intents)
* **SDK Example**: [Bitcoin to EVM Intents SDK Sample](https://github.com/0xsquid/examples/tree/main/V2/sdk/bitcoinToEVM_Intents)


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.squidrouter.com/api-and-sdk-integration/chain-integration-guides/bitcoin-intents.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
