ElectrumClient

Struct ElectrumClient 

Source
pub struct ElectrumClient { /* private fields */ }
Expand description

Electrum protocol client.

Provides async methods for querying Bitcoin blockchain data via Electrum protocol.

§Example

use rustywallet_electrum::{ElectrumClient, ClientConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to server
    let client = ElectrumClient::new("electrum.blockstream.info").await?;
     
    // Check balance
    let balance = client.get_balance("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa").await?;
    println!("Balance: {} satoshis", balance.confirmed);
     
    Ok(())
}

Implementations§

Source§

impl ElectrumClient

Source

pub async fn new(server: &str) -> Result<Self>

Create a new client with SSL connection to the specified server.

Uses default port 50002 for SSL.

Source

pub async fn with_config(config: ClientConfig) -> Result<Self>

Create a new client with custom configuration.

Source

pub async fn get_balance(&self, address: &str) -> Result<Balance>

Get balance for a single address.

§Arguments
  • address - Bitcoin address (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
§Returns
  • Balance with confirmed and unconfirmed amounts in satoshis
Source

pub async fn get_balance_scripthash(&self, scripthash: &str) -> Result<Balance>

Get balance using scripthash directly.

Source

pub async fn get_balances(&self, addresses: &[&str]) -> Result<Vec<Balance>>

Get balances for multiple addresses in a single batch request.

This is much more efficient than calling get_balance multiple times.

§Arguments
  • addresses - Slice of Bitcoin addresses
§Returns
  • Vector of Balance in the same order as input addresses
Source

pub async fn get_balances_scripthash( &self, scripthashes: &[String], ) -> Result<Vec<Balance>>

Get balances using scripthashes directly (batch).

Source

pub async fn list_unspent(&self, address: &str) -> Result<Vec<Utxo>>

List unspent outputs (UTXOs) for an address.

§Arguments
  • address - Bitcoin address
§Returns
  • Vector of Utxo for the address
Source

pub async fn list_unspent_scripthash( &self, scripthash: &str, ) -> Result<Vec<Utxo>>

List unspent outputs using scripthash directly.

Source

pub async fn get_transaction(&self, txid: &str) -> Result<String>

Get raw transaction by txid.

§Arguments
  • txid - Transaction ID (hex)
§Returns
  • Raw transaction hex string
Source

pub async fn broadcast(&self, raw_tx: &str) -> Result<String>

Broadcast a signed transaction.

§Arguments
  • raw_tx - Signed transaction in hex format
§Returns
  • Transaction ID if broadcast successful
Source

pub async fn get_history(&self, address: &str) -> Result<Vec<TxHistory>>

Get transaction history for an address.

§Arguments
  • address - Bitcoin address
§Returns
  • Vector of TxHistory entries
Source

pub async fn get_history_scripthash( &self, scripthash: &str, ) -> Result<Vec<TxHistory>>

Get transaction history using scripthash directly.

Source

pub async fn server_version(&self) -> Result<ServerVersion>

Get server version information.

Also performs protocol version negotiation.

Source

pub async fn ping(&self) -> Result<()>

Ping the server to check connection.

Source

pub async fn get_block_height(&self) -> Result<u64>

Get the current block height.

Source

pub async fn estimate_fee(&self, blocks: u32) -> Result<f64>

Get estimated fee rate (satoshis per kilobyte).

§Arguments
  • blocks - Target confirmation blocks (e.g., 1, 6, 144)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.