ethers-erc20balances

Crates.ioethers-erc20balances
lib.rsethers-erc20balances
version0.1.4
sourcesrc
created_at2023-07-23 22:02:39.398478
updated_at2024-07-09 11:54:34.230787
descriptionGet many balances in one eth_call
homepage
repositoryhttps://github.com/rlgrpe/ethers-erc20balances
max_upload_size
id924040
size21,044
(rlgrpe)

documentation

README

Call one token balance

let provider = Arc::new(Provider::<Http>::connect(rpc).await);
let balances = provider.get_erc20_balances(vec![Address::zero()], vec![Address::from_str("0xdAC17F958D2ee523a2206206994597C13D831ec7").unwrap()).await.unwrap();

result:

0x0000000000000000000000000000000000000000: {
    0xdac17f958d2ee523a2206206994597c13d831ec7: 17962155817,
}

Call many tokens balance

let tokens = vec![
    Address::from_str("0xdAC17F958D2ee523a2206206994597C13D831ec7").unwrap(), // USDT
    Address::from_str("0x6B175474E89094C44Da98b954EedeAC495271d0F").unwrap(), // DAI
]
let provider = Arc::new(Provider::<Http>::connect(rpc).await);
let balances = provider.get_erc20_balances(vec![Address::zero()], tokens).await.unwrap();

result:

0x0000000000000000000000000000000000000000: {
    0xdac17f958d2ee523a2206206994597c13d831ec7: 17962155817,
    0x6b175474e89094c44da98b954eedeac495271d0f: 9234114788971643034663,
},

Call many tokens balance with many addresses

let tokens = vec![
    Address::from_str("0xdAC17F958D2ee523a2206206994597C13D831ec7").unwrap(), // USDT
    Address::from_str("0x6B175474E89094C44Da98b954EedeAC495271d0F").unwrap(), // DAI
];
let wallets = vec![
    Address::zero(),
    Address::from_str("0xF977814e90dA44bFA03b6295A0616a897441aceC").unwrap(),
];
let provider = Arc::new(Provider::<Http>::connect(rpc).await);
let balances = provider.get_erc20_balances(wallets, tokens).await.unwrap();

result:

0x0000000000000000000000000000000000000000: {
    0x6b175474e89094c44da98b954eedeac495271d0f: 9234114788971643034663,
    0xdac17f958d2ee523a2206206994597c13d831ec7: 17962155817,
},
0xf977814e90da44bfa03b6295a0616a897441acec: {
    0x6b175474e89094c44da98b954eedeac495271d0f: 7000000000000000000000000,
    0xdac17f958d2ee523a2206206994597c13d831ec7: 1429615184000000,
},

Supported chains

1 - mainnet
3 - ropsten
4 - rinkeby
69 - kovan
5 - goerli
56 - binance smart chain mainnet
97 - binance smart chain testnet
137 - polygon 
80001 - mumbai
10 - optimism
69 - optimism kovan
42161 - arbitrum
43114 - avax
250 - fantom
25 - cronos
66 - okt
1666600000 - harmony
17000 - holesky
Commit count: 4

cargo fmt