Skip to content

FairgateLabs/rust-bitvmx-bitcoin-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitVMX Bitcoin RPC

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.

⚠️ Disclaimer

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.

Methods

  • 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 higher
  • get_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.

Usage

Connecting to a Bitcoin Core node

use bitvmx_bitcoin_rpc::BitcoinClient;

let client = BitcoinClient::new(
    "http://127.0.0.1:18443",
    "user",
    "password"
)?

Getting basic blockchain data

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)?;

Sending and retrieving transactions

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);

Wallet operations

let address = client.init_wallet("test_wallet")?;

let new_address = client.get_new_address(public_key, bitcoin::Network::Regtest)?;

Mining blocks (regtest only)

client.mine_blocks_to_address(1, &address)?;

Estimating fees

let fee_rate = client.estimate_smart_fee()?

Development Setup

  1. Clone the repository
  2. Install dependencies: cargo build

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License - see LICENSE file for details.


🧩 Part of the BitVMX Ecosystem

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.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

Languages