ETH Balances
Examples
Note
These examples are crafted as a Jupyter notebook. You can download the original notebook file here.
Also note that inside Jupyter notebooks, await
can be used freely outside of asyncio.run()
.
In [1]:
import ctc
In [2]:
address = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
addresses = [
'0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
'0xf977814e90da44bfa03b6295a0616a897441acec',
]
Get ETH balance of address¶
In [3]:
balance = await ctc.async_get_eth_balance(address)
balance
Out[3]:
1183.9444491905404
Get raw un-normalized ETH balance of address¶
In [4]:
balance = await ctc.async_get_eth_balance(address, normalize=False)
balance
Out[4]:
1183944449190540293798
Get ETH balance of address in specific block¶
In [5]:
balance = await ctc.async_get_eth_balance(address, block=10000000)
balance
Out[5]:
30.625853991434212
Get ETH balance of address across multiple blocks¶
In [6]:
blocks = range(int(10e6), int(14e6), int(1e6))
balances = await ctc.async_get_eth_balance_by_block(address, blocks=blocks)
balances
Out[6]:
[30.625853991434212, 8.262617966894156, 7.209924409854158, 7606.165945835849]
Get ETH balance of multiple addresses¶
In [7]:
balances = await ctc.async_get_eth_balance_of_addresses(addresses)
balances
Out[7]:
[1183.9444491905404, 3957828.2878176, 2436827.477025209]