alloy-rpc-client

Crates.ioalloy-rpc-client
lib.rsalloy-rpc-client
version
sourcesrc
created_at2023-11-15 20:11:18.647553
updated_at2024-12-10 11:18:39.049912
descriptionLow-level Ethereum JSON-RPC client implementation
homepagehttps://github.com/alloy-rs/alloy
repositoryhttps://github.com/alloy-rs/alloy
max_upload_size
id1036789
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
core (github:alloy-rs:core)

documentation

README

alloy-rpc-client

Low-level Ethereum JSON-RPC client implementation.

Usage

Usage of this crate typically means instantiating an RpcClient<T> over some Transport. The RPC client can then be used to make requests to the RPC server. Requests are captured as RpcCall futures, which can then be polled to completion.

For example, to make a simple request:

// Instantiate a new client over a transport.
let client: ReqwestClient = ClientBuilder::default().http(url);

// Prepare a request to the server.
let request = client.request_noparams("eth_blockNumber");

// Poll the request to completion.
let block_number = request.await.unwrap();

Batch requests are also supported:

// Instantiate a new client over a transport.
let client: ReqwestClient = ClientBuilder::default().http(url);

// Prepare a batch request to the server.
let batch = client.new_batch();

// Batches serialize params immediately. So we need to handle the result when
// adding calls.
let block_number_fut = batch.add_call("eth_blockNumber", ()).unwrap();
let balance_fut = batch.add_call("eth_getBalance", address).unwrap();

// Make sure to send the batch!
batch.send().await.unwrap();

// After the batch is complete, we can get the results.
// Note that requests may error separately!
let block_number = block_number_fut.await.unwrap();
let balance = balance_fut.await.unwrap();
Commit count: 1340

cargo fmt