Bitcoin Core Transaction Index: txindex and Historical Transaction Lookup
Bitcoin Core can validate transactions without maintaining a searchable index of every historical transaction ID. The optional transaction index, enabled with txindex=1, provides a lookup mechanism for historical transactions stored by the node. It is useful for explorers and applications that need transaction data beyond their own wallets.
What the index stores
The transaction index associates transaction identifiers with disk locations. It is not an address index, a wallet ledger, or a separate copy of the entire blockchain. Bitcoin Core uses the stored position to retrieve and deserialize transaction data from block files. The transaction ID identifies the transaction's non-witness serialization; it is not the witness transaction ID.
A node still needs its normal block index and chainstate. The block index describes blocks and their relationships, while chainstate tracks currently unspent outputs. A transaction index serves a different query pattern: finding a historical transaction by its identifier.
RPC lookup behavior
A developer can request a decoded transaction using:
````
bitcoin-cli getrawtransaction "$TXID" true
Without txindex, this call can find transactions in the local mempool. For a historical transaction, supplying the containing block hash can permit retrieval without a transaction index, provided the block data remains available:
````
bitcoin-cli getrawtransaction "$TXID" true "$BLOCKHASH"
The wallet RPC gettransaction is different. It queries transactions known to a loaded wallet and does not turn the node into a global transaction search service.
Synchronization and storage
Enabling an index does not make it immediately ready. Bitcoin Core must process historical blocks to populate it. Check getindexinfo before relying on arbitrary historical lookups. A synchronized blockchain does not necessarily imply that every optional index is synchronized.
Standard Bitcoin Core does not support txindex together with pruning. Applications that need arbitrary historical transaction retrieval should provision an archival node and sufficient disk space. Check the documentation for the exact release rather than assuming all indexes share the same pruning constraints.
Application boundaries
A successful transaction lookup is not proof that an output remains unspent. Use gettxout for the current UTXO view and account for its include_mempool option. A missing result can mean an output is spent or unavailable in that view; it does not prove the transaction never existed.
For payment verification, inspect the actual output script and amount, establish active-chain membership, and apply a confirmation policy. Do not treat a transaction ID supplied by a customer as sufficient evidence of payment. Indexes improve retrieval, not consensus security.
Primary references
Bitcoin Core transaction index implementation: https://github.com/bitcoin/bitcoin/blob/master/src/index/txindex.cpp
Bitcoin Core RPC documentation (29.0): https://bitcoincore.org/en/doc/29.0.0/rpc/rawtransactions/getrawtransaction/
