1 个不稳定版本

0.1.0 2024年6月1日

#36 in #json-rpc-client

Download history • Rust 包仓库 145/week @ 2024-05-26 • Rust 包仓库 133/week @ 2024-06-02 • Rust 包仓库 78/week @ 2024-06-09 • Rust 包仓库 98/week @ 2024-06-16 • Rust 包仓库 23/week @ 2024-06-23 • Rust 包仓库 71/week @ 2024-06-30 • Rust 包仓库 19/week @ 2024-07-07 • Rust 包仓库 79/week @ 2024-07-14 • Rust 包仓库 80/week @ 2024-07-21 • Rust 包仓库 106/week @ 2024-07-28 • Rust 包仓库 97/week @ 2024-08-04 • Rust 包仓库 94/week @ 2024-08-11 • Rust 包仓库 83/week @ 2024-08-18 • Rust 包仓库

391 每月下载量
用于 3 crates

MIT/Apache

190KB
3.5K SLoC

linera-alloy-rpc-client

低级以太坊 JSON-RPC 客户端实现。

用法

使用此包通常意味着在某个 RpcClient<T> 上实例化,其中 Transport 是某种传输。然后可以使用 RPC 客户端向 RPC 服务器发送请求。请求被捕获为 RpcCall future,然后可以轮询以完成。

例如,要发送一个简单的请求

// 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();

也支持批量请求

// 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();

依赖项

~19–32MB
~573K SLoC