#request #bitcoin-node #electrs


Send RPC commands to an Electrs server

4 releases

0.1.3 Oct 3, 2022
0.1.2 Sep 28, 2022
0.1.1 Sep 28, 2022
0.1.0 Sep 28, 2022

50 downloads per month
Used in 2 crates (via electrs-query)

MIT license

129 lines

Electrs Request

Send RPC commands to an Electrs server.

⚠️ This is experimental. Please use at your own risk.⚠️

This library provides typesafe functions over raw RPC Electrs commands to easily and safely retrieve information from a the server node.

As this library only provides typesafety over raw RPC commands, functions will be mapped 1:1 to RPC commands. See ElectrumX for a list of all commands and what they return.

If you're looking for a higher level api for querying information from electrum (i.e. balance for address, etc) , take a look at electrs-query, which provides higher-level functions to query an electrs server.


Add package to Cargo.toml file

electrs-request = "0.1.3"


let electrs_server_address = "";
let client = Client::new(electrs_server_address);

// get the relay fee
let response = BlockchainRelayFeeCommand::new().call(&client).unwrap();
println!("relay fee result: {:?}", response);

let p2pkh_address = "mv7RvNNQ7HpQf2diQai5hgpeuzkFoAQP9G".to_string();

// And address must be converted to a public key hash, then hashed using sha256 and then converted to little endian before requesting information from electrs.
let p2pkh_pk_hash = get_public_key_hash_from_address(&p2pkh_address);
let p2pkh_script = format!("{}{}{}", "76a914", p2pkh_pk_hash, "88ac");
let p2pkh_script_sha256 = bitcoin_utils::sha256_hex(&p2pkh_script);
let p2pkh_script_sha256_le = convert_big_endian_hex_to_little_endian(&p2pkh_script_sha256);

// get the balance for a p2pkh address
let balance_response = BlockchainScriptHashGetBalanceCommand::new(&p2pkh_script_sha256_le)
println!("balance: {:#?}", balance_response);
// get utxos for address
let unspent_response = BlockchainScriptHashListUnspentCommand::new(&p2pkh_script_sha256_le)
println!("unspent: {:#?}", unspent_response);


List of all electrs commands can be found on exectrumx docs


MIT © Joe Gesualdo


~132K SLoC