MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / get_block

Method get_block

web3/src/block.rs:58–65  ·  view source on GitHub ↗

Retrieve the block information using the block number. See https://eth.wiki/json-rpc/API#eth_getBlockByNumber # Examples ```ignore let web3 = web3::Web3::new("http://127.0.0.1:8545").unwrap(); let block_number = U64::from(0); let block = web3.get_block(block_number)).await; assert!(block.is_ok()); ```

(&self, block_number: U64)

Source from the content-addressed store, hash-verified

56 /// assert!(block.is_ok());
57 /// ```
58 pub async fn get_block(&self, block_number: U64) -> Result<Block> {
59 let block_number = to_hex(block_number);
60 let params = rpc_params![block_number];
61 let response = self.send_rpc("eth_getBlockByNumber", params).await?;
62 let block: Block = serde_json::from_value(response)?;
63
64 Ok(block)
65 }
66}
67
68#[cfg(test)]

Callers 1

it_gets_the_latest_blockFunction · 0.80

Calls 2

to_hexFunction · 0.85
send_rpcMethod · 0.80

Tested by

no test coverage detected