> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Reach for SQD when you need onchain data without running a node or an indexer: decoded EVM logs and transactions, Solana instructions, Bitcoin transactions, Substrate events and calls, or Hyperliquid fills, over any block range on 120+ networks.
> To query directly, POST to https://portal.sqd.dev/datasets/{dataset}/stream. The full API is described at https://docs.sqd.dev/openapi.json, and responses to the stream endpoints are JSON Lines.
> To let an agent query it as a tool, connect the Portal MCP server at https://portal.sqd.dev/mcp.
> Every page on this site is available as Markdown by appending .md to its URL.

# Bitcoin portal stream

> API reference for bitcoinPortalStream().

`bitcoinPortalStream()` reads Bitcoin blocks from SQD Portal and applies one or more query outputs.

```ts theme={"system"}
import { bitcoinPortalStream, bitcoinQuery } from '@subsquid/pipes/bitcoin'

const stream = bitcoinPortalStream({
  id: 'bitcoin-transactions',
  portal: 'https://portal.sqd.dev/datasets/bitcoin-mainnet',
  outputs: bitcoinQuery()
    .addFields({
      block: { number: true },
      transaction: { txid: true },
      input: { txid: true, vout: true },
      output: { value: true, scriptPubKeyAddress: true },
    })
    .addTransactionRequest({
      range: { from: 'latest' },
      request: { inputs: true, outputs: true },
    }),
})
```

## Options

| Option | Required | Description |
| - | - | - |
| `id` | Yes | Stable, non-empty pipe identifier. Targets use it as the default cursor key. |
| `portal` | Yes | Dataset URL or a `PortalClientOptions` object. |
| `outputs` | Yes | A `BitcoinQueryBuilder`, transformer, or record of named outputs. |
| `cache` | No | Portal response cache. |
| `logger` | No | Pino-compatible logger, log level, `false`, or `null`. |
| `metrics` | No | Metrics server instance. |
| `profiler` | No | `boolean` or profiler span hooks. |
| `progress` | No | Progress callbacks and reporting interval. |

When `portal` is an object, it accepts `url`, `finalized`, `http`, `maxBytes`, `maxIdleTimeMs`, `maxWaitTimeMs`, and `headPollIntervalMs`.

Use `for await` to consume batches, `.pipe()` to add a whole-stream transformer, or `.pipeTo()` to connect a target.

## RPC latency watcher

`bitcoinRpcLatencyWatcher()` compares the latest Portal block with one or more Bitcoin Core JSON-RPC endpoints. Bitcoin Core does not expose a block WebSocket, so the watcher polls `getbestblockhash` and `getblockheader`.

```ts theme={"system"}
import { bitcoinPortalStream, bitcoinRpcLatencyWatcher } from '@subsquid/pipes/bitcoin'

const stream = bitcoinPortalStream({
  id: 'bitcoin-latency',
  portal: 'https://portal.sqd.dev/datasets/bitcoin-mainnet',
  outputs: bitcoinRpcLatencyWatcher({
    rpcUrl: ['https://bitcoin-rpc.publicnode.com'],
    intervalMs: 4_000,
    requestTimeoutMs: 4_000,
  }),
})
```

| Option | Required | Description |
| - | - | - |
| `rpcUrl` | Yes | Bitcoin Core JSON-RPC endpoint URLs. |
| `intervalMs` | No | Poll interval in milliseconds. Defaults to `4_000`. |
| `requestTimeoutMs` | No | Timeout per RPC request. Defaults to the larger of `1_000` and `intervalMs`. |

Each non-null output contains the Portal block `number` and `timestamp`, `portal.receivedAt`, and an `rpc` array with each sanitized `url`, optional block `hash` and `receivedAt`, and `portalDelayMs`.

For an authenticated node, put the credentials in the URL, for example `http://user:pass@127.0.0.1:8332`. The watcher sends them with HTTP Basic authentication and removes them from emitted URLs, logs, and metrics.

See the [query builder reference](./query-builder) for typed fields and filters.


## Related topics

- [Bitcoin quickstart](/en/sdk/pipes-sdk/bitcoin/quickstart.md)
- [Bitcoin Portal API](/en/portal/bitcoin/overview.md)
- [Portal stream](/en/sdk/pipes-sdk/solana/reference/basic-components/source.md)
- [EVM Portal stream](/en/sdk/squid-sdk/evm/reference/evm-stream.md)
- [Tron portal stream](/en/sdk/pipes-sdk/tron/reference/basic-components/source.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.