BitVMX Bitcoin RPC is a Rust library that provides a convenient interface for interacting with a Bitcoin Core node.
It uses the bitcoincore-rpc crate and provides additional abstractions and helper functions for easier interaction.
This library is currently under development and may not be fully stable. It is not production-ready, has not been audited, and future updates may introduce breaking changes without preserving backward compatibility.
BitcoinClient::new(url, user, pass)- Connect to a Bitcoin Core node.get_best_block()- Get the current best block height.get_block_by_height(height)- Get block info by height.get_block_by_hash(hash)- Get block info by hash.get_block_id_by_height(height)- Get block hash by height.get_blockchain_info()- Get blockchain info.tx_exists(txid)- Check if a transaction exists.get_raw_transaction_info(txid)- Get raw transaction details.get_raw_transaction_verbosity_two(txid)- Get raw transaction with verbosity=2 details. requires Bitcoin Core version 25.0.0 or higherget_transaction(txid)- Get transaction by txid.send_transaction(tx)- Send a raw transaction.fund_address(address, amount)- Fund an address.get_tx_out(txid, vout)- Get UTXO details.mine_blocks_to_address(num_blocks, address)- Mine blocks to an address.invalidate_block(hash)- Invalidate a block.init_wallet(wallet_name)- Create and initialize a wallet.get_new_address(pk, network)- Generate a new address from a public key.estimate_smart_fee()- Estimate transaction fee rate.
use bitvmx_bitcoin_rpc::BitcoinClient;
let client = BitcoinClient::new(
"http://127.0.0.1:18443",
"user",
"password"
)?let height = client.get_best_block()?;
let info = client.get_blockchain_info()?;
let block_info = client.get_block_by_height(&100)?;
let block_hash = client.get_block_id_by_height(&100)?;
let block = client.get_block_by_hash(&block_hash)?;let address = Address::from_str("bcrt1...")?;
let amount = Amount::from_sat(10_000);
let (tx, vout) = client.fund_address(&address, amount)?;
let txid = client.send_transaction(&tx)?;
let exists = client.tx_exists(&txid);let address = client.init_wallet("test_wallet")?;
let new_address = client.get_new_address(public_key, bitcoin::Network::Regtest)?;client.mine_blocks_to_address(1, &address)?;let fee_rate = client.estimate_smart_fee()?- Clone the repository
- Install dependencies:
cargo build
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License - see LICENSE file for details.
This repository is a component of the BitVMX Ecosystem, an open platform for disputable computation secured by Bitcoin.
You can find the index of all BitVMX open-source components at FairgateLabs/BitVMX.