#rpc-client #transport #json-rpc-client #low-level #alloy #request #ethereum

linera-alloy-rpc-client

Low-level Ethereum JSON-RPC client implementation

1 unstable release

0.1.0 Jun 1, 2024

#59 in #json-rpc-client

Download history 109/week @ 2024-07-27 94/week @ 2024-08-03 87/week @ 2024-08-10 98/week @ 2024-08-17 76/week @ 2024-08-24 158/week @ 2024-08-31 210/week @ 2024-09-07 296/week @ 2024-09-14 299/week @ 2024-09-21 128/week @ 2024-09-28 146/week @ 2024-10-05 127/week @ 2024-10-12 274/week @ 2024-10-19 260/week @ 2024-10-26 589/week @ 2024-11-02 463/week @ 2024-11-09

1,602 downloads per month
Used in 7 crates (3 directly)

MIT/Apache

190KB
3.5K SLoC

linera-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 = ClientBulider::default().http(url);

// Prepare a request to the server.
let request = client.request("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 = ClientBulider::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();

Dependencies

~20–33MB
~567K SLoC