GET
/
v1
/
query
/
{queryId}
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": true,
  "is_archived": true,
  "is_unsaved": true,
  "owner": "Dune"
}

To access Query endpoints, a Plus plan or higher is required.

Headers

X-DUNE-API-KEY
string
required

API Key for the service

Path Parameters

queryId
integer
required

unique identifier of the query

Query Parameters

api_key
string

API Key for the service, alternative to using the HTTP header X-DUNE-API-KEY.

Response

200 - application/json
query_id
integer

Unique identifier of the query.

name
string

Name of the query.

description
string

Description of the query.

tags
string[]

Tags associated with the query.

version
integer

Version of the query.

parameters
object[]
query_engine
string

The query engine used to execute the query.

query_sql
string

The SQL query text.

is_private
boolean

Indicates if the query is private.

is_archived
boolean

Indicates if the query is archived.

is_unsaved
boolean

Indicates if the query is unsaved.

owner
string

The owner of the query.