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
rust [dependencies] electrs-request = "0.1.3"
```rust let electrsserveraddress = "127.0.0.1:50001"; let client = Client::new(electrsserveraddress);
// get the relay fee let response = BlockchainRelayFeeCommand::new().call(&client).unwrap(); println!("relay fee result: {:?}", response);
let p2pkhaddress = "mv7RvNNQ7HpQf2diQai5hgpeuzkFoAQP9G".tostring();
// 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 p2pkhpkhash = getpublickeyhashfromaddress(&p2pkhaddress); let p2pkhscript = format!("{}{}{}", "76a914", p2pkhpkhash, "88ac"); let p2pkhscriptsha256 = bitcoinutils::sha256hex(&p2pkhscript); let p2pkhscriptsha256le = convertbigendianhextolittleendian(&p2pkhscript_sha256);
// get the balance for a p2pkh address let balanceresponse = BlockchainScriptHashGetBalanceCommand::new(&p2pkhscriptsha256le) .call(&client) .unwrap(); println!("balance: {:#?}", balanceresponse); // get utxos for address let unspentresponse = BlockchainScriptHashListUnspentCommand::new(&p2pkhscriptsha256le) .call(&client) .unwrap(); println!("unspent: {:#?}", unspentresponse);
```
List of all electrs commands can be found on exectrumx docs
MIT © Joe Gesualdo