- Dune API Overview
- API Quickstart
- Authentication
- Client SDKs
- Result Filtering
- Rate Limits
- Troubleshooting Errors
- Billing
- FAQ
Custom Endpoints
SQL Endpoints
- Executions and Results
- Queries
- Materialized Views
- Webhooks
Data Management Endpoints
- Tables
Preset Endpoints
- DEX
- EigenLayer
- EVM Contracts
- Farcaster
- Markets
- Projects
Read Query
This API allows for anyone to read the sql text, parameters, name, tags, and state of a query. For private queries, only the API key generated under the context of the owner of that query will work.
curl --request GET \
--url https://api.dune.com/api/v1/query/{queryId} \
--header 'X-DUNE-API-KEY: <x-dune-api-key>'
{
"query_id": 1252207,
"name": "erc20 balances (user address) API",
"description": "Example Blockchain Query",
"tags": [
"erc20",
"balances",
"user address"
],
"version": 17,
"parameters": [
{
"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"
]
}
],
"query_engine": "v2 Dune SQL",
"query_sql": "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",
"is_private": false,
"is_archived": false,
"is_unsaved": false,
"owner": "Dune"
}
To access Query endpoints, a Plus plan or higher is required.
curl --request GET \
--url https://api.dune.com/api/v1/query/{queryId} \
--header 'X-DUNE-API-KEY: <x-dune-api-key>'
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
Unique identifier of the query.
Name of the query.
Description of the query.
Tags associated with the query.
Version of the query.
The key name of the parameter.
A brief description of the parameter.
The default value used by this parameter during execution, format depends on the type.
An array of string values, used when multiple selections are allowed.
The type of the parameter, determines the format of 'value(s)'. 'number': Numeric parameters, the value must be a number (e.g., '20'). 'text': String parameters, value can be any text including hex 0x-prefixed values (e.g., '0xae2fc...'), an empty value defaults to an empty string. 'datetime': Date and time parameters, value must be in 'YYYY-MM-DD hh:mm:ss' format (e.g., '2021-12-31 23:59:59'). 'enum': Parameters with a specific list of values, 'EnumValues' field is mandatory, providing a JSON list of strings representing valid options, the 'value' must be one of these options (e.g., 'Option1').
number
, text
, datetime
, enum
List of valid options for 'enum' type parameters.
Indicates if multiple selections are allowed for this parameter.
Indicates if freeform input is allowed for this parameter.
The query engine used to execute the query.
The SQL query text.
Indicates if the query is private.
Indicates if the query is archived.
Indicates if the query is unsaved.
The owner of the query.
Was this page helpful?
curl --request GET \
--url https://api.dune.com/api/v1/query/{queryId} \
--header 'X-DUNE-API-KEY: <x-dune-api-key>'
{
"query_id": 1252207,
"name": "erc20 balances (user address) API",
"description": "Example Blockchain Query",
"tags": [
"erc20",
"balances",
"user address"
],
"version": 17,
"parameters": [
{
"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"
]
}
],
"query_engine": "v2 Dune SQL",
"query_sql": "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",
"is_private": false,
"is_archived": false,
"is_unsaved": false,
"owner": "Dune"
}