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

linera-alloy-rpc-client

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

1 个不稳定版本

0.1.0 2024年6月1日

#36 in #json-rpc-client

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

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