ether-rs

Use WVM with ether-rs

In this example we will use the web3 crate. First of all, add the crate to your project by:

[dependencies]
web3 = "0.19.0"

Code Example: Retrieve Address Balance

use web3::types::{H160};

const WVM_TESTNET_RPC: &str = "https://testnet-rpc.wvm.dev";

#[tokio::main]
async fn main() -> web3::Result<()> {
    let address: H160 = "0x544836c1d127B0d5ed6586EAb297947dE7e38a78".parse().unwrap();
    
    let transport = web3::transports::Http::new(&WVM_TESTNET_RPC.to_string())?;
    let web3 = web3::Web3::new(transport);

    let balance = web3.eth().balance(address, None).await?;
    println!("Balance of {:?}: {} tWVM", address, balance);

    Ok(())
}

Last updated