Headers
API Key for the service
Path Parameters
unique identifier of the query
Query Parameters
API Key for the service, alternative to using the HTTP header X-DUNE-API-KEY.
Response
OK
Unique identifier of the query.
1252207
Name of the query.
"erc20 balances (user address) API"
Description of the query.
"Example Blockchain Query"
Tags associated with the query.
["erc20", "balances", "user address"]
Version of the query.
17
[
{
"key": "address",
"value": "0x2ae8c972fb2e6c00dded8986e2dc672ed190da06",
"type": "text"
},
{
"key": "blocknumber",
"value": "0",
"type": "number"
},
{
"key": "chain",
"value": "ethereum",
"type": "enum",
"enumOptions": [
"ethereum",
"polygon",
"optimism",
"arbitrum",
"avalanche_c",
"gnosis",
"bnb"
]
},
{
"key": "dust",
"value": "keep",
"type": "enum",
"enumOptions": ["keep", "remove"]
}
]
The query engine used to execute the query.
"v2 Dune SQL"
The SQL query text.
"with\n erc20_balances as (\n WITH erc20_in as ( \n SELECT \n contract_address\n , SUM(tr.value) as token_funded\n FROM erc20_{{chain}}.evt_Transfer tr\n WHERE tr.to = {{address}}\n AND ({{blocknumber}} = 0 OR tr.evt_block_number <= {{blocknumber}})\n GROUP BY 1\n ),\n \n erc20_out as (\n SELECT \n contract_address\n , SUM(tr.value) as token_spent\n FROM erc20_{{chain}}.evt_Transfer tr\n WHERE tr.\"from\" = {{address}}\n AND ({{blocknumber}} = 0 OR tr.evt_block_number <= {{blocknumber}})\n GROUP BY 1\n )\n \n SELECT\n tk.symbol as symbol\n , erc20_in.contract_address\n , (cast(token_funded as double) - COALESCE(cast(token_spent as double), 0))/pow(10,COALESCE(tk.decimals,18)) as balance\n FROM erc20_in\n LEFT JOIN erc20_out ON erc20_in.contract_address = erc20_out.contract_address\n LEFT JOIN tokens.erc20 tk ON tk.contract_address = erc20_in.contract_address\n WHERE cast(token_funded as double) - COALESCE(cast(token_spent as double), 0) > 0\n -- WHERE tk.symbol is not null\n )\n\nSELECT\n bal.symbol\n , round(bal.balance,5) as notional_value\n , round(bal.balance*p.price,3) as total_value\n , p.price as token_price\nFROM erc20_balances bal\nLEFT JOIN prices.usd_latest p \n ON p.contract_address = bal.contract_address\n AND p.blockchain = '{{chain}}' --AND p.rn = 1 \nWHERE bal.balance > 0\nAND ('{{dust}}' = 'keep' OR bal.balance*p.price > 0.01)\nORDER BY total_value DESC\nNULLS LAST"
Indicates if the query is private.
false
Indicates if the query is archived.
false
Indicates if the query is unsaved.
false
The owner of the query.
"Dune"