Skip to main content

Learning objectives

  • Read and interpret block and chain data using Bitcoin Core commands
  • Understand chain tips and how re-orgs occur in regtest
  • Track transaction confirmations and understand depth
  • Inspect the mempool for unconfirmed transactions

Reading block data

After mining blocks in regtest or syncing a mainnet/testnet node, you can inspect block data using several bitcoin-cli commands. Get the hash of the most recent block:
Retrieve full block data using the hash:
To get just the header:
This includes:
  • Height
  • Timestamp
  • Version
  • Merkle root
  • Previous block hash
  • Nonce
  • Chainwork
Get block hash by height:
Example:

Using getchaintips and understanding chain re-orgs

The command getchaintips returns all known tips of the blockchain:
This is useful in regtest when you’re simulating chain reorganizations. For example, if you invalidate a block:
Then generate a longer competing chain (replace <miner_address> with your mining address):
Your node will adopt the longer chain tip, causing a re-org. This is how Bitcoin resolves consensus forks.

Understanding confirmations and depth

A transaction’s confirmation count is the block that includes it plus every block on top of that block. To see how many confirmations a transaction has (replace <txid> with an actual transaction ID):
You’ll see:
  • confirmations: number of blocks since inclusion, counting the block it was mined in
  • blockhash: which block it was mined in
Alternatively, use :
To simulate confirmations in regtest, simply mine more blocks (replace <miner_address> with your mining address):
This simulates time passing and increases confirmation depth instantly.

Inspecting mempool transactions

The mempool holds transactions waiting to be mined. In regtest, it’s typically empty unless you send a transaction before mining. List all mempool transactions:
Get details of a specific mempool transaction (replace <txid> with an actual transaction ID):
This shows:
  • Fee
  • Size
  • Ancestor/descendant count
  • Time in pool
You can clear the mempool by mining a block that confirms the pending transactions, or by restarting the node with -persistmempool=0. A plain restart keeps it, because the node saves the mempool to mempool.dat.

Activity

  1. Generate five blocks and get the latest block hash
  2. Use getblock and getblockheader to inspect the block
  3. Send a transaction and observe it in the mempool before mining.
  4. Mine one block and check the transaction’s confirmation count.
  5. Invalidate the block using invalidateblock , then, inspect with getchaintips