Function ethers_providers::spoof::balance
source · pub fn balance(adr: H160, bal: U256) -> State
Expand description
Returns a state override set with a single element setting the balance of the address.
§Examples
ⓘ
let geth = Geth::new().spawn();
let provider = Provider::<Http>::try_from(geth.endpoint()).unwrap();
let adr1: Address = "0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse()?;
let adr2: Address = "0x295a70b2de5e3953354a6a8344e616ed314d7251".parse()?;
let pay_amt = parse_ether(1u64)?;
// Not enough ether to pay for the transaction
let tx = TransactionRequest::pay(adr2, pay_amt).from(adr1).into();
// override the sender's balance for the call
let state = spoof::balance(adr1, pay_amt * 2);
provider.call_raw(&tx).state(&state).await?;