1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Balance query utilities for EVM accounts
//!
//! Provides functions to query native token (ETH) balances from blockchain state.
use crate::;
use ;
use Result;
use ;
/// Query the native token balance of an address
///
/// Retrieves the ETH balance for the specified address, optionally at a specific block.
///
/// # Arguments
/// - `evm`: EVM instance for state queries
/// - `owner`: Address to query balance for
///
/// # Returns
/// - `Ok(U256)`: Account balance in wei
/// - `Err(BalanceError)`: If balance query fails
///
/// # Example
/// ```no_run
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// use revm_trace::{create_evm, utils::balance_utils::query_balance};
/// use alloy::primitives::address;
///
/// let mut evm = create_evm("https://eth-mainnet.g.alchemy.com/v2/your-key").await?;
/// let balance = query_balance(
/// &mut evm,
/// address!("DFd5293D8e347dFe59E90eFd55b2956a1343963d"),
/// )?;
/// println!("Balance: {} wei", balance);
/// # Ok(())
/// # }
/// ```