Skip to main content

Reading the Bitcoin state

Bitcoin

ICP smart contracts can query information about the Bitcoin mainnet or testnet programmatically.

Reading unspent transaction outputs (UTXOs)

To read unspent transaction outputs from the Bitcoin network, make a call to the bitcoin_get_utxos Bitcoin API method.

motoko/basic_bitcoin/src/basic_bitcoin/src/BitcoinApi.mo
loading...

Reading current balance

To read the current balance of a Bitcoin address, make a call to the bitcoin_get_balance Bitcoin API method.

motoko/basic_bitcoin/src/basic_bitcoin/src/BitcoinApi.mo
loading...

Reading the fee percentile

The transaction fees on the Bitcoin network change dynamically based on the number of pending transactions. In order to get fee percentiles of the last 10_000 transactions mined into blocks, call bitcoin_get_current_fee_percentiles.

The function returns 101 numbers that are fees measured in millisatoshi per virtual byte. The i-th element of the result corresponds to the i-th percentile fee. For example, to get the median fee over the last few blocks, look at the 50-th element of the result.

motoko/basic_bitcoin/src/basic_bitcoin/src/BitcoinApi.mo
loading...

Reading the block headers

To read the block headers within a provided range of start and end heights, make a call to the bitcoin_get_block_headers Bitcoin API method

rust/basic_bitcoin/src/service/get_block_headers.rs
loading...

Resources