get-burn-block-info?
Fetch information about burnchain blocks in Clarity smart contracts.
Function Signature
(get-burn-block-info? prop-name block-height)
- Input:
- prop-name: A BurnBlockInfoPropertyName
- block-height: A uint representing the burnchain block height
 
- Output: (optional buff) | (optional (tuple (addrs (list 2 (tuple (hashbytes (buff 32)) (version (buff 1))))) (payout uint)))
Why it matters
The get-burn-block-info? function is crucial for:
- 1Accessing historical data from the underlying burnchain (Bitcoin).
- 2Implementing cross-chain verification or logic based on Bitcoin block information.
- 3Retrieving PoX (Proof of Transfer) related data for advanced stacking operations.
- 4Enabling contracts to react to or validate burnchain events.
When to use it
Use get-burn-block-info? when you need to:
- Verify Bitcoin block hashes within your Stacks contract.
- Access information about PoX payouts and addresses.
- Implement logic that depends on burnchain block data.
- Build cross-chain applications that reference Bitcoin state.
Best Practices
- Always check if the returned value is none, as it will be for non-existent or future blocks.
- Be aware of the potential for chain reorganizations when using recent block data.
- Use the appropriate property name for the data you need to retrieve.
- Consider caching results for frequently accessed block information to save on execution costs.
Practical Example: Verifying a Bitcoin Block Hash
Let's implement a function that verifies if a given Bitcoin block hash matches a specific height:
(define-read-only (verify-btc-block-hash (height uint) (expectedHash (buff 32)))(match (get-burn-block-info? header-hash height) hash(is-eq hash expectedHash)false));; Usage(verify-btc-block-hash u700000 0x00000000000000000009a11b3972c8e532e964e262c196556bd958b7fd0c55c3)
This example demonstrates:
- 1Using get-burn-block-info?to retrieve theheader-hashof a burnchain block.
- 2Handling the optional return value with match.
- 3Comparing the retrieved hash with an expected value.
Available Properties
- header-hash: Returns a 32-byte buffer representing the header hash of the burnchain block.
- pox-addrs: Returns a tuple containing PoX payout information:- addrs: A list of up to two PoX addresses that received payouts.
- payout: The amount of burnchain tokens paid to each address.
 
Common Pitfalls
- 1Assuming all properties are available for all blocks.
- 2Not handling the nonecase when the block height is invalid or in the future.
- 3Misinterpreting the pox-addrsdata, especially during different PoX phases.
- 4Overlooking the fact that burn addresses may be included in the pox-addrslist.
Related Functions
- get-block-info?: Used to get information about Stacks blocks.
- burn-block-height: Keyword that returns the current burn chain block height.
Conclusion
The get-burn-block-info? function is a powerful tool for accessing burnchain data in Clarity smart contracts. It allows you to incorporate Bitcoin blockchain information into your contract logic, enabling cross-chain verification and advanced PoX-related functionalities. When used correctly, this function provides valuable insights into the underlying Bitcoin blockchain's state and can be used to implement sophisticated, cross-chain aware contract behavior.