evm_rpc_client 0.2.0

Rust client for interacting with the EVM RPC canister
Documentation

Internet Computer portal DFinity Forum GitHub license

Crate evm_rpc_client

Library to interact with the EVM RPC canister from a canister running on the Internet Computer. The alloy feature flag allows using Alloy types in requests and responses.

See the Rust documentation for more details.

Example

Fetching the latest transaction count for a given address using the eth_getTransactionCount JSON-RPC method.

use alloy_primitives::{Adress, U256};
use alloy_rpc_types::BlockNumberOrTag;
use evm_rpc_client::EvmRpcClient;
use evm_rpc_types::RpcResult;

fn get_latest_transaction_count (address: Address) -> RpcResult<U256> {
    let client = EvmRpcClient::builder_for_ic()
        .with_alloy()
        .build();

    client
        .get_transaction_count((address, BlockNumberOrTag::Latest))
        .send()
        .await
        .expect_consistent()
}