Overview
Bitcoin Streams extends Moralis Streams to the Bitcoin network, delivering real-time transaction data via webhooks. Moralis indexes Bitcoin automatically and pushes structured payloads to your endpoint whenever transactions match your criteria. Webhooks typically arrive within seconds of a block being mined — no node, no polling, no missed blocks.Key Features
- Real-time delivery: end-to-end latency is typically under 10 seconds after a block is mined
- Mempool notifications: unconfirmed transactions fire a webhook the moment they hit the mempool — react before the next block is mined
- Three-phase notifications: matches can fire up to three times — first when the transaction is broadcast to the mempool (
block.hash: "mempool"), again when it lands in a block (confirmed: false, near the chain tip), and finally after the 2-block confirmation depth (confirmed: true, reorg-safe) - All address formats supported: P2PKH (legacy,
1...), P2SH (SegWit-wrapped,3...), and Bech32 native SegWit (bc1q...) - Xpub support: attach an extended public key to a stream and Moralis derives and monitors its addresses automatically — ideal for HD wallets
- Flexible monitoring: watch specific addresses, attach an xpub, or enable firehose mode with
allAddressesto receive every Bitcoin transaction - Automatic retries: Moralis retries webhook delivery until it receives an HTTP 200 response
How It Works
- A transaction is broadcast to the Bitcoin mempool. Moralis evaluates every mempool transaction against your registered addresses and xpubs
- Matching mempool transactions fire a webhook with
confirmed: falseand the sentinel valuesblock.height: "0"/block.hash: "mempool"— delivered once per stream - A new Bitcoin block is produced and Moralis evaluates every transaction in it against your registered addresses
- Matching block transactions fire a webhook with
confirmed: falseand the real blockheight/hash— the block is close to the chain tip and could still be reorged - After 2 additional blocks have been mined on top, Moralis re-fetches the block and delivers a third webhook with
confirmed: true— the transaction is now reorg-safe - Your service upserts on
txidto reconcile the lifecycle, branching onblock.hash === "mempool"for the mempool stage
Webhook Payload Structure
Each Bitcoin webhook payload contains:- Block metadata — hash, height, timestamp, difficulty, merkle root, transaction count
- Transaction details —
txid, input/output counts, locktime, version, block reference - Outputs (
vout) — value in BTC (not satoshis), script type, recipient address - Inputs (
vin) — structural fields only;addressandvaluefields remainnull - Confirmation status —
confirmed: falsefor the near-tip delivery,confirmed: trueonce the block has cleared the 2-block confirmation depth
Output values are represented as BTC decimals (e.g.
3.13258866). To convert to satoshis, multiply by 1e8:Mempool Notifications
Bitcoin Streams emit webhook notifications for unconfirmed transactions as soon as they hit the mempool — no need to wait for block inclusion. The payload shape is identical to a confirmed-block webhook, with sentinel fields on theblock object marking it as mempool:
Everything else (
transactions[], vin, vout, addresses, value, fee) is populated normally.
Example payload
Detecting mempool in your handler
Branch on either sentinel field —block.hash is the most explicit:
Behavior
- Delivered at most once per stream per matching mempool transaction
- No follow-up webhook on confirmation from the mempool delivery itself — the regular confirmed-block stream handles
confirmed: false(in-block) andconfirmed: true(reorg-safe) for the sametxid - Mempool transactions are not guaranteed to confirm. They can be evicted, replaced (RBF), or expire on low fee. Treat them as pending, not settled
- Matching covers both sends and receives. In mempool payloads,
vinandvoutaddresses are both populated, so a watched address triggers a match whether it is sending or receiving - Xpub-derived addresses are fully supported — addresses derived from an attached xpub match against the mempool the same way they do against confirmed blocks
Getting started
No new endpoint, parameter, or schema. Existing Bitcoin streams pick up mempool notifications automatically. Just branch onblock.hash === "mempool" (or block.height === "0") in your handler to separate mempool events from confirmed-block events.
Configuration Parameters
When creating a Bitcoin stream you specify:API Endpoints
All Bitcoin Streams endpoints require thex-api-key header.
Streams
Addresses
Xpub
Limitations
- Input data is not populated. Even with
includeInputs: true, inputaddressandvaluefields returnnull. You can reliably detect inbound transfers to watched addresses, not outflows. isCoinbaseis alwaysfalse. TheisCoinbasefield does not reliably identify coinbase transactions. Detect coinbase transactions using a heuristic: the transaction contains anOP_RETURNoutput and has exactly one input.- Values are BTC decimals. Output values are not denominated in satoshis. Convert with
Math.round(btc * 1e8)before feeding integer-based ledger systems. - Mainnet only. The
networkparameter must be["mainnet"].
Processing Patterns
Branching on mempool vs. confirmed block
A singletxid can arrive up to three times: once from the mempool, once on block inclusion, and once on reorg-safe confirmation. Branch on the block.hash sentinel before doing any block-specific work:
Deduplication
Use the transaction id (txid) as your natural deduplication key. Upsert on each delivery, advancing your state machine through mempool → in-block → confirmed as each webhook arrives. Note that the mempool delivery can be skipped entirely for transactions Moralis only observes once they are already mined.
Coinbase detection
SinceisCoinbase is unreliable, detect coinbase transactions like this:
Value conversion
Store both BTC and satoshi values so downstream services can pick whichever representation fits:Common Use Cases
- Exchange deposits — surface deposits the moment they hit the mempool (
block.hash === "mempool"), mark thempendingon block inclusion (confirmed: false), andconfirmedon the reorg-safe delivery (confirmed: true) - Pending balances — show users a pending balance the instant a tx is broadcast, before any block has been mined
- Payment UX — trigger downstream flows on payment broadcast instead of waiting for confirmation
- Mempool analytics — RBF detection, fee analytics, and MEV / arbitrage signals against unconfirmed activity
- Cold wallet surveillance — alert on any inbound transfer to an offline storage address
- Mining pool revenue — watch payout addresses for both standard payments and coinbase block rewards
- Treasury monitoring — real-time accounting for corporate or DAO-held BTC addresses
Setup Checklist
- Generate an API key from admin.moralis.com
- Deploy a publicly accessible HTTPS webhook endpoint
- Create the stream via
PUT /streams/bitcoin - Attach the wallets you want to monitor — either by registering individual addresses (
POST /streams/bitcoin/{id}/address) or by adding an xpub (POST /streams/bitcoin/{id}/xpub) to auto-derive and watch its addresses - Implement the verification handler — respond to the empty-body test
POSTwith HTTP200 - Build upsert logic keyed on
txidto handle theconfirmed: false→confirmed: truetransition - Always return HTTP
200from your handler, even when your own processing errors — Moralis retries on non-200 responses

