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

Method get_balance_by_block

web3/src/account.rs:52–63  ·  view source on GitHub ↗

Retrieve the eth balance for an accout at a given block. See https://eth.wiki/json-rpc/API#eth_getBalance # Examples ```ignore use types::block::BlockNumber; let block = BlockNumber(0.into()); let account = web3.get_all_accounts().await.unwrap()[0]; let balance = web3.get_balance_by_block(account, Some(block)).await; assert!(balance.is_ok()); ```

(
        &self,
        address: Account,
        block_number: Option<BlockNumber>,
    )

Source from the content-addressed store, hash-verified

50 /// assert!(balance.is_ok());
51 /// ```
52 pub async fn get_balance_by_block(
53 &self,
54 address: Account,
55 block_number: Option<BlockNumber>,
56 ) -> Result<U256> {
57 let block_number = Web3::get_hex_blocknumber(block_number);
58 let params = rpc_params![to_hex(address), block_number];
59 let response = self.send_rpc("eth_getBalanceByBlock", params).await?;
60 let balance: U256 = serde_json::from_value(response)?;
61
62 Ok(balance)
63 }
64
65 pub fn sign_transaction(
66 &self,

Callers 2

get_balanceMethod · 0.80

Calls 1

send_rpcMethod · 0.80

Tested by

no test coverage detected