### Python SDK - Quick Start Source: https://docs.dune.com/api-reference/overview/sdks A quick guide to getting started with the Dune Python SDK, including executing queries by ID or raw SQL. ```APIDOC ## Python SDK - Quick Start ### Description This example demonstrates how to initialize the DuneClient and execute a query using either its ID or raw SQL. ### Method ```python from dune_client import DuneClient # DuneClient will read the DUNE_API_KEY environment variable dune = DuneClient() # Execute a query by ID results = dune.execute(query_id=3493826) # Or execute raw SQL results = dune.execute(sql="SELECT * FROM dex.trades LIMIT 10") # Access results for row in results.rows: print(row) ``` ``` -------------------------------- ### Install Dune Go Client Source: https://docs.dune.com/api-reference/overview/introduction Install the Dune Go client library using go get. This is necessary for interacting with the Dune API from Go applications. ```bash go get github.com/duneanalytics/duneapi-client-go ``` -------------------------------- ### Install Dune Go SDK Source: https://docs.dune.com/api-reference/overview/sdks Installs the Dune API client for Go using the go get command. This is the first step to integrating Dune data into your Go applications. ```go go get github.com/duneanalytics/duneapi-client-go ``` -------------------------------- ### Quick Start: Initialize Client and Run Query Source: https://docs.dune.com/api-reference/sdks/typescript Initialize the Dune client with your API key and execute a query using its ID. This example demonstrates setting text, number, date, and enum query parameters. ```typescript import { QueryParameter, DuneClient } from "@duneanalytics/client-sdk"; const { DUNE_API_KEY } = process.env; const client = new DuneClient(DUNE_API_KEY ?? ""); const queryID = 1215383; const params = { query_parameters: [ QueryParameter.text("TextField", "Plain Text"), QueryParameter.number("NumberField", 3.1415926535), QueryParameter.date("DateField", "2022-05-04 00:00:00"), QueryParameter.enum("ListField", "Option 1"), ] }; client .runQuery(queryID, params) .then((executionResult) => console.log(executionResult.result?.rows)); ``` -------------------------------- ### Dune Go SDK Installation Source: https://docs.dune.com/api-reference/overview/sdks Instructions for installing the Dune Go SDK. ```APIDOC ## Installation ### Go Use `go get` to install the Dune Go SDK: ```bash go get github.com/duneanalytics/duneapi-client-go ``` ``` -------------------------------- ### Examples Source: https://docs.dune.com/query-engine/Functions-and-operators/eip-8021 Illustrative examples demonstrating how to use the `call_data_8021` table function with different configurations and data sources. ```APIDOC ## Examples ### Parse transaction calldata from `base.transactions` ```sql SELECT tx_hash, block_time, schema_type, codes_readable, codes_array FROM TABLE(functions.base_l2.call_data_8021( input => TABLE( SELECT hash AS tx_hash, block_time, cast(data as varchar) AS calldata FROM base.transactions WHERE block_time >= now() - interval '7' day ) )) LIMIT 100 ``` ### Use the default `calldata` column name ```sql SELECT tx_hash, schema_type, codes_readable FROM TABLE(functions.base_l2.call_data_8021( input => TABLE( VALUES ( '0xdeadbeef', '0x722c6182000000000000000000000000000000000000000000000000000000000000000163625f77616c6c6574090080218021802180218021802180218021' ) ) AS t(tx_hash, calldata) )) ``` ### Override the calldata column name ```sql SELECT tx_hash, schema_type, codes_readable FROM TABLE(functions.base_l2.call_data_8021( input => TABLE( VALUES ( '0xdeadbeef', '0x722c6182000000000000000000000000000000000000000000000000000000000000000163625f77616c6c6574090080218021802180218021802180218021' ) ) AS t(tx_hash, call_data), calldata => DESCRIPTOR(call_data) )) ``` ### Parse schema 2 CBOR calldata ```sql SELECT schema_type, codes_readable, codes_array, cbor_data FROM TABLE(functions.base_l2.call_data_8021( input => TABLE( VALUES ( '0xabcda26161656d796170706177686d7977616c6c657400140280218021802180218021802180218021' ) ) AS t(calldata) )) ``` ``` -------------------------------- ### Fetch Query Results with Filters (Go) Source: https://docs.dune.com/api-reference/executions/filtering Example in Go demonstrating how to make an HTTP GET request to the Dune API for query results, setting up query parameters for filtering, column selection, and sorting. ```go package main import ( "fmt" "net/http" "io/ioutil" "net/url" ) func main() { url := "https://api.dune.com/api/v1/query/{query_id}/results" // Create query parameters params := url.Values{} params.Set("limit", "10") params.Set("filters", "block_time > '2024-03-01'") params.Set("columns", "tx_from,tx_to,tx_hash,amount_usd") params.Set("sort_by", "amount_usd desc, block_time") // Add parameters to URL fullURL := fmt.Sprintf("%s?%s", url, params.Encode()) req, _ := http.NewRequest("GET", fullURL, nil) req.Header.Add("X-DUNE-API-KEY", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### JSON Path Syntax Examples Source: https://docs.dune.com/query-engine/Functions-and-operators/json Examples demonstrating strict and lax path modes for JSON path evaluation. ```text strict ($.price + $.tax)?(@ > 99.9) ``` ```text lax $[0 to 1].floor()?(@ > 10) ``` -------------------------------- ### Python SDK Example for Sampling Source: https://docs.dune.com/api-reference/executions/sampling Use the Dune Python SDK to fetch a sampled result set for a query. Ensure the dune-client library is installed and configured. ```python from dune_client.client import DuneClient # setup Dune Python client dune = DuneClient() query_result = dune.get_latest_result_dataframe( query=3582296 # https://dune.com/queries/3582296 -> OHLC Price , sample_count = 5000 ) print(query_result) ``` -------------------------------- ### Clone and Install Dependencies Source: https://docs.dune.com/api-reference/connectors/dbt/getting-started Clone the Dune dbt template repository and install project dependencies using uv. ```bash git clone https://github.com/your-org/your-dbt-project.git cd your-dbt-project uv sync ``` -------------------------------- ### Example Query View Usage Source: https://docs.dune.com/query-engine/query-a-query This example demonstrates how to use a specific query (with queryID 1746191) as a view in another query. ```sql select * from query_1746191 ``` -------------------------------- ### Install mppx and viem Dependencies Source: https://docs.dune.com/api-reference/agents/mpp Install the necessary client libraries for manual integration. These include `mppx` for handling the payment protocol and `viem` for EVM account management. ```bash npm install mppx viem ``` -------------------------------- ### Freeform Date Parameter Example Source: https://docs.dune.com/web-app/query-editor/parameters Illustrates the use of freeform parameters for date inputs. The example shows how to define start and end date parameters and cast them to timestamps for range filtering. ```sql -- freeform date parameter Select * from dex.trades where evt_block_time between cast('{{start_date_parameter}}' as timestamp) and cast('{{end_date_parameter}}' as timestamp) ``` -------------------------------- ### Execute and Get Result with Dune Python SDK Source: https://docs.dune.com/api-reference/executions/endpoint/get-query-result Use the Dune Python SDK to execute a query and retrieve its results directly. Ensure the SDK is installed via 'pip install dune-client'. ```python import json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # setup Dune Python client dune = DuneClient() result = dune.run_query( query=query # pass in query to run , performance = 'large' # optionally define which tier to run the execution on (default is "medium") ) ``` -------------------------------- ### Initialize Trino Connection in Go Source: https://docs.dune.com/api-reference/connectors/trino/sdks Demonstrates how to open a SQL database connection to Trino using the trino-go-client library. ```go import "database/sql" import _ "github.com/trinodb/trino-go-client/trino" dsn := "http://user@localhost:8080?catalog=default&schema=test" db, err := sql.Open("trino", dsn) ``` -------------------------------- ### Get Query Execution Status using Python SDK Source: https://docs.dune.com/api-reference/executions/endpoint/get-execution-status Utilize the Dune Python SDK to retrieve the status of a query execution. Ensure you have installed the SDK using `pip install dune-client`. ```python ''' Download Dune Python SDK by running `pip install dune-client` For more info, visit the GitHub repository: https://github.com/duneanalytics/dune-client/tree/d2195b2a9577e2dcae5d2600cb3eddce20987f38 ''' import json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # setup Dune Python client dune = DuneClient() result = dune.get_execution_status(job_id = '01HM79YYNXADPK66YWZK5X0NXB') # pass in the execution_id ``` -------------------------------- ### Single HTTP GET Request to CoinGecko Source: https://docs.dune.com/query-engine/Functions-and-operators/live-fetch A basic example of using http_get to retrieve data from the CoinGecko API. ```sql SELECT http_get('https://api.coingecko.com/api/v3/coins/list'); ``` -------------------------------- ### Fetch Latest Query Results via HTTP GET Request Source: https://docs.dune.com/api-reference/executions/endpoint/get-query-result This example demonstrates how to retrieve the latest query results using a standard HTTP GET request. Replace `{query_id}` with your actual query ID and `` with your Dune API key. ```bash curl --request GET \ --url https://api.dune.com/api/v1/query/{query_id}/results ``` -------------------------------- ### Real-World Example: Whale Transactions (Python) Source: https://docs.dune.com/api-reference/executions/filtering Python example demonstrating how to fetch large USDC transfers within a specific time frame, selecting relevant columns and sorting results. ```python from dune_client import DuneClient dune = DuneClient(api_key="YOUR_API_KEY") # Get large USDC transfers in the last day results = dune.get_latest_result_dataframe( query=3493826, filters="token_symbol = 'USDC' AND amount_usd > 1000000 AND block_time > '2024-03-10'", columns="tx_hash,tx_from,tx_to,amount_usd,block_time", sort_by="amount_usd desc" ) print(f"Found {len(results)} whale transactions") ``` -------------------------------- ### Get Execution Result in CSV using Java Unirest Source: https://docs.dune.com/api-reference/executions/endpoint/get-execution-result-csv Retrieve query execution results in CSV format using the Java Unirest library. This example shows how to set the API key in the request header for a GET request to the Dune API. ```java HttpResponse response = Unirest.get("https://api.dune.com/api/v1/execution/{execution_id}/results/csv") .header("X-DUNE-API-KEY", "") .asString(); ``` -------------------------------- ### Fetch Latest Query Result in CSV via HTTP GET Request Source: https://docs.dune.com/api-reference/executions/endpoint/get-query-result-csv Retrieve the latest query results in CSV format using a simple HTTP GET request. This example demonstrates the basic API call structure, including the endpoint and required headers. ```bash curl --request GET \ --url https://api.dune.com/api/v1/query/{query_id}/results/csv ``` -------------------------------- ### Show Create View Source: https://docs.dune.com/api-reference/connectors/sql-operations Use `SHOW CREATE VIEW` to retrieve the SQL definition of an existing view. ```sql SHOW CREATE VIEW your_team.active_traders; ``` -------------------------------- ### Extract Suffix Varbinary with varbinary_substring Source: https://docs.dune.com/query-engine/Functions-and-operators/varbinary Use varbinary_substring to extract a suffix from a varbinary, starting at a specified index. This example extracts the latter part of a bytearray. ```sql -- using varbinary_substring starting from the 21th index -- this returns 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 SELECT 0x0000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as original_bytearray, varbinary_substring(0x0000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,21) as bytearraysubstring_data ``` -------------------------------- ### json_path Examples Source: https://docs.dune.com/query-engine/Functions-and-operators/json Illustrates different modes and expressions for specifying a JSON path. Use 'strict' for exact matches and 'lax' for more flexible matching. ```text strict $.keyvalue()?(@.name == $cust_id) lax $[5 to last] ``` -------------------------------- ### Fetch Query Results with Go HTTP Client Source: https://docs.dune.com/api-reference/executions/sorting Demonstrates fetching query results using Go's standard net/http package. It shows how to construct the URL with query parameters and set the necessary API key header. Replace {query_id} and . ```go package main import ( "fmt" "net/http" "io/ioutil" "net/url" ) func main() { url := "https://api.dune.com/api/v1/query/{query_id}/results" // Create query parameters params := url.Values{} params.Set("limit", "10") params.Set("filters", "block_time > '2024-03-01'") params.Set("columns", "tx_from,tx_to,tx_hash,amount_usd") params.Set("sort_by", "amount_usd desc, block_time") // Add parameters to URL fullURL := fmt.Sprintf("%s?%s", url, params.Encode()) req, _ := http.NewRequest("GET", fullURL, nil) req.Header.Add("X-DUNE-API-KEY", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Check Varbinary Prefix with varbinary_starts_with Source: https://docs.dune.com/query-engine/Functions-and-operators/varbinary Use varbinary_starts_with to determine if a varbinary value begins with a specified prefix. This example checks if transaction data starts with a specific methodID. ```sql -- get $ARKM claimers -- varbinary_starts_with checks whether -- data starts with 0x3d13f874 (claim methodID) SELECT * FROM ethereum.transactions WHERE block_time >= TIMESTAMP '2023-07-17' AND varbinary_starts_with(data,0x3d13f874) -- returns true if starts with 0x3d13f874 AND success LIMIT 100 ``` -------------------------------- ### Fetch Query Results with Filters (cURL) Source: https://docs.dune.com/api-reference/executions/filtering Example using cURL to make a GET request to the Dune API for query results, including filters, column selection, and sorting. ```bash curl -X GET 'https://api.dune.com/api/v1/query/{{query_id}}/results?limit=10&filters=block_time%3E%272024-03-01%27&columns=tx_from%2Ctx_to%2Ctx_hash%2Camount_usd&sort_by=amount_usd%20desc%2Cblock_time' \ -H 'x-dune-api-key:{{api_key}}’ ``` -------------------------------- ### Initialize Dune Python Client Source: https://docs.dune.com/api-reference/quickstart/results-eg Set up a Dune Python client. The API key can be provided directly or via environment variables like DUNE_API_KEY. ```python from dune_client.client import DuneClient dune = DuneClient( api_key='', base_url="https://api.dune.com", request_timeout=300 ) ``` -------------------------------- ### Execute and Get Latest Dune Query Result Source: https://docs.dune.com/api-reference/quickstart/results-eg A combined example demonstrating how to set up the Dune client and fetch the latest query result in JSON format without re-executing the query. ```python from dune_client.client import DuneClient from dune_client.query import QueryBase # setup Dune Python client dune = DuneClient() # get the latest executed result without triggering a new execution query_result = dune.get_latest_result(3373921) # get latest result in json format ``` -------------------------------- ### Install Dune CLI Source: https://docs.dune.com/api-reference/agents/cli-and-skills Installs the Dune CLI, authenticates with your API key, and adds the Dune Agent Skill. Ensure you have a Dune API key generated beforehand. ```bash curl -sSfL https://dune.com/cli/install.sh | sh ``` -------------------------------- ### Get Execution Results with Dune Python SDK Source: https://docs.dune.com/api-reference/executions/endpoint/get-execution-result Use the `get_execution_results` method from the Dune Python SDK to fetch results for a given execution ID. Ensure the `dune-client` library is installed. ```python ''' Download Dune Python SDK by running `pip install dune-client` For more info, visit the GitHub repository: https://github.com/duneanalytics/dune-client/tree/d2195b2a9577e2dcae5d2600cb3eddce20987f38 ''' import json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # setup Dune Python client dune = DuneClient() result = dune.get_execution_results(job_id = '01HM79YYNXADPK66YWZK5X0NXB') # pass in the execution_id ``` -------------------------------- ### Format String Examples Source: https://docs.dune.com/query-engine/Functions-and-operators/conversion Provides examples of the format() function for creating formatted strings using various specifiers like string, floating-point, integer, and date formatting. ```sql SELECT format('%s%%', 123); -- '123%' ``` ```sql SELECT format('%.5f', pi()); -- '3.14159' ``` ```sql SELECT format('%03d', 8); -- '008' ``` ```sql SELECT format('%,.2f', 1234567.89); -- '1,234,567.89' ``` ```sql SELECT format('%-7s,%7s', 'hello', 'world'); -- 'hello , world' ``` ```sql SELECT format('%2$s %3$s %1$s', 'a', 'b', 'c'); -- 'b c a' ``` ```sql SELECT format('%1$tA, %1$tB %1$te, %1$tY', date '2006-07-04'); -- 'Tuesday, July 4, 2006' ``` -------------------------------- ### Real-World Example: Token-Specific Monitoring (Bash) Source: https://docs.dune.com/api-reference/executions/filtering Bash example using `curl` to monitor recent trades for a specific token pair (WETH/USDC) within a given time range, specifying columns and sorting. ```bash # Monitor recent trades for a specific token pair curl -X GET \ 'https://api.dune.com/api/v1/query/3493826/results?filters=token_bought_symbol%20%3D%20%27WETH%27%20AND%20token_sold_symbol%20%3D%20%27USDC%27%20AND%20block_time%20%3E%20%272024-03-10%27&columns=amount_usd%2Cprice%2Cblock_time&sort_by=block_time%20desc' \ -H 'X-DUNE-API-KEY: YOUR_API_KEY' ``` -------------------------------- ### Get Latest Results with Sorting (Python SDK) Source: https://docs.dune.com/api-reference/executions/sorting Use the Dune Python SDK to fetch the latest query results with custom filters and sorting applied. Ensure the SDK is installed and configured. ```python from dune_client.client import DuneClient # setup Dune Python client dune = DuneClient() query_result = dune.get_latest_result_dataframe( query=3567562 # https://dune.com/queries/3567562 , filters="overtip_amount > 0" , columns=["donor_fname","overtip_amount","days_overtipped","overall_tip_given_amount","overall_avg_tip_amount"] , sort_by=["overall_tip_given_amount desc"] ) print(query_result) ``` -------------------------------- ### Get Cardinality of a Set Digest Source: https://docs.dune.com/query-engine/Functions-and-operators/setdigest This example uses `make_set_digest` to create a set digest from a list of values and then uses the `cardinality` function to return the approximate number of distinct elements within that set digest. ```sql SELECT cardinality(make_set_digest(value)) FROM (VALUES 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5) T(value); -- 5 ``` -------------------------------- ### Optimize Token Transfer Queries with Partition Filters (SQL) Source: https://docs.dune.com/data-catalog/curated/token-transfers/overview This example demonstrates efficient querying of the `tokens.transfers` table by utilizing partition keys. Always include `blockchain` and `block_date` (or a `block_time` range) in your WHERE clause for optimal performance. ```sql -- ✅ Good: chain + date filter SELECT * FROM tokens.transfers WHERE blockchain = 'ethereum' AND block_date = CURRENT_DATE AND contract_address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 -- USDC -- ❌ Slow: no partition filters SELECT * FROM tokens.transfers WHERE "from" = 0x... ``` -------------------------------- ### Fetch Query Results with Java Unirest Source: https://docs.dune.com/api-reference/executions/sorting This Java example uses the Unirest library to make a GET request to the Dune API. It demonstrates setting headers and query parameters for filtering and sorting. Replace {query_id} and . ```java import kong.unirest.HttpResponse; import kong.unirest.Unirest; public class Main { public static void main(String[] args) { HttpResponse response = Unirest.get("https://api.dune.com/api/v1/query/{query_id}/results") .header("X-DUNE-API-KEY", "") .queryString("limit", 10) .queryString("filters", "block_time > '2024-03-01'") .queryString("columns", "tx_from,tx_to,tx_hash,amount_usd") .queryString("sort_by", "amount_usd desc, block_time") .asString(); System.out.println(response.getBody()); } } ``` -------------------------------- ### Fetch Query Results with cURL Source: https://docs.dune.com/api-reference/executions/sorting Example using cURL to make a GET request to the Dune API for query results, specifying filters and sorting via URL parameters. Replace {{query_id}} and {{api_key}} with your actual values. ```bash curl -X GET 'https://api.dune.com/api/v1/query/{{query_id}}/results?limit=100&filters=chain%20in%20(%27base%27%2C%20%27optimism%27)%20and%20token_pair%20like%20%27%25USDC%25%27&sort_by=thirty_day_volume%20desc' \ -H 'x-dune-api-key:{{api_key}}’ ``` -------------------------------- ### Execute Query with Header Authentication (Go) Source: https://docs.dune.com/api-reference/overview/authentication This Go program illustrates how to make an API call to execute a query using the 'X-DUNE-API-KEY' header. Replace '' and '{{query_id}}' with your specific API key and query ID. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.dune.com/api/v1/query/{{query_id}}/execute" req, _ := http.NewRequest("POST", url, nil) req.Header.Add("X-DUNE-API-KEY", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Query Results with Javascript Fetch API Source: https://docs.dune.com/api-reference/executions/sorting An example using the Javascript Fetch API to get query results from Dune. It includes setting the API key in headers and defining query parameters for filtering and sorting. Replace {query_id} and . ```javascript const options = { method: 'GET', headers: { 'X-DUNE-API-KEY': '' } }; const queryParams = new URLSearchParams({ limit: 10, filters: "block_time > '2024-03-01'", columns: "tx_from,tx_to,tx_hash,amount_usd", sort_by: "amount_usd desc, block_time" }); const url = `https://api.dune.com/api/v1/query/{query_id}/results?${queryParams}`; fetch(url, options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err)); ``` -------------------------------- ### Quick Start Dune Python Client Source: https://docs.dune.com/api-reference/overview/sdks Initialize the DuneClient and execute queries by ID or raw SQL. The client automatically reads the DUNE_API_KEY environment variable. ```python from dune_client import DuneClient # DuneClient will read the DUNE_API_KEY environment variable dune = DuneClient() # Execute a query by ID results = dune.execute(query_id=3493826) # Or execute raw SQL results = dune.execute(sql="SELECT * FROM dex.trades LIMIT 10") # Access results for row in results.rows: print(row) ``` -------------------------------- ### Get Execution Result in CSV using Go Source: https://docs.dune.com/api-reference/executions/endpoint/get-execution-result-csv Retrieve query execution results in CSV format using Go's standard `net/http` package. This example demonstrates setting the API key in the request header and reading the response body. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.dune.com/api/v1/execution/{execution_id}/results/csv" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-DUNE-API-KEY", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Execute Query with Parameters (Go) Source: https://docs.dune.com/api-reference/overview/sdks Executes a saved query with parameters using the Go SDK. This example shows how to pass query parameters as a map and specify the performance tier. ```go package main import ( "fmt" "github.com/duneanalytics/duneapi-client-go" ) func main() { client := duneapi.New("YOUR_API_KEY") // Execute a saved query results, err := client.ExecuteQuery(duneapi.ExecuteQueryParams{ QueryID: 3493826, Performance: "medium", Parameters: map[string]interface{}{ "blockchain": "ethereum", "min_volume": 1000, }, }) if err != nil { panic(err) } for _, row := range results.Rows { fmt.Printf("%+v\n", row) } } ``` -------------------------------- ### Example SQL Query for Daily Ethereum Active Addresses Source: https://docs.dune.com/web-app/overview This SQL query calculates the number of unique sender addresses for each day starting from January 1st, 2024. It requires basic SQL knowledge and access to Dune's Ethereum transaction data. ```sql SELECT date_trunc('day', block_time) AS time, COUNT(DISTINCT "from") AS active_senders FROM ethereum.transactions WHERE block_time > DATE '2024-01-01' GROUP BY 1 ORDER BY 1 ``` -------------------------------- ### Create and Query Visit Summaries with HyperLogLog Source: https://docs.dune.com/query-engine/Functions-and-operators/hyperloglog Example of creating a table to store HyperLogLog sketches for daily unique users and querying weekly unique users by merging daily sketches. Requires approximate_set and cardinality functions. ```sql CREATE TABLE visit_summaries ( visit_date date, hll varbinary ) INSERT INTO visit_summaries SELECT visit_date, cast(approx_set(user_id) AS varbinary) FROM user_visits GROUP BY visit_date; SELECT cardinality(merge(cast(hll AS HyperLogLog))) AS weekly_unique_users FROM visit_summaries WHERE visit_date >= current_date - interval '7' day; ```