Expand description
A lightweight async library for making JSON-RPC calls to Ethereum-compatible
nodes. A Rust port of the Go ethrpc
library, built on the rsurl async HTTP client.
§Quick start
use ethrpc_rs::{Rpc, ValueExt};
let rpc = Rpc::new("https://cloudflare-eth.com");
let block = rpc.call("eth_blockNumber", vec![]).await?.to_u64()?;
println!("block: {block}");All network methods are async and must be awaited inside a Tokio runtime.
Modules§
- abi
- Minimal Ethereum contract-call helpers (behind the default
abifeature). - chains
- Static metadata for known EVM-compatible chains.
Structs§
- Api
- Wraps any
Handlerand provides convenience methods for common Ethereum RPC calls. - Error
Object - A JSON-RPC 2.0 error object returned by a server.
- Forward
Options - Options controlling how
Rpc::forwardbuilds its response. - Forward
Response - A response produced by
Rpc::forward, ready to be written to whatever HTTP framework the caller uses. - Request
- A JSON-RPC 2.0 request object.
- Response
- A JSON-RPC 2.0 response with a raw JSON result.
- Response
Intf - A JSON-RPC 2.0 response where
resultis an arbitrary serializable value, used when encoding a locally-produced (overridden) response. - Rpc
- A connection to an Ethereum JSON-RPC endpoint over HTTP, with optional basic authentication and local method overrides.
- RpcList
- A list of
Rpcendpoints that implementsHandlerwith failover.
Enums§
- Error
- Errors returned by RPC operations.
Traits§
- Handler
- Any backend capable of executing JSON-RPC calls. Implemented by
RpcandRpcList. - Value
Ext - Decoding helpers for Ethereum-encoded
serde_json::Valueresults.
Functions§
- evaluate
- Calls every server with
eth_blockNumber, measures response time, and returns aHandlerbacked by the servers that responded.
Type Aliases§
- Override
Fn - A locally-handled RPC method. Receives the positional parameters and returns
a JSON value (or an error). Registered with
Rpc::set_override. - Result
- The crate’s result alias.