Appearance
Read a token's balance and metadata
Ask stETH for its name, symbol, decimals, supply and one holder's balance, in one row.
cql
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;
let wstETH = ethereum:0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;
from stETH with { abi: erc20 } as t
| project {
name: t.name(),
symbol: t.symbol(),
decimals: t.decimals(),
supply: format(t.totalSupply(), 18),
balance: format(t.balanceOf(wstETH), 18)
}| name | symbol | decimals | supply | balance |
|---|---|---|---|---|
| Liquid staked Ether 2.0 | stETH | 18 | 9761717.135365036561936133 | 4574569.089042408733594804 |
You get one row: one contract at the newest block. The row has name Liquid staked Ether 2.0, symbol stETH and decimals 18. It has supply and balance as decimals with the point already moved. The holder is wstETH, the wrapped form of stETH and its largest holder. Close to half of the supply sits in it at the block that answered.
How it reads
with { abi: erc20 } uses the built-in ERC-20 interface, so there is nothing to look up. Every token that follows the standard answers these five calls. If you omit the option, CQL resolves the contract's own verified ABI instead. For stETH, that means CQL follows its proxy to the implementation. The implementation offers these five functions and a good many more.
format(x, 18) turns 1000000000000000000 into 1.0. For a token you do not know, read decimals first. Use that number. format never rounds, so the value is exact.
Variations
- Several holders at once.
let treasury = ethereum:0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c;, thenexpand [wstETH, treasury] as holderbefore theproject, andt.balanceOf(holder). - Several tokens at once.
from [stETH, wstETH] with { abi: erc20 } as tgives one row per token. wstETH is an ordinary ERC-20 and answers the same five calls. - Shares instead of balance. A stETH balance grows once a day. The share count under it does not.
sharesOfis not in the ERC-20 interface. So removewith { abi: erc20 }, and callt.sharesOf(wstETH). - At a past block.
from stETH at 25_800_000 with { abi: erc20 } as t.