### Install Mintlify CLI (npm) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Installs the Mintlify command-line interface globally using npm, making the `mintlify` command available system-wide. ```Shell npm i -g mintlify ``` -------------------------------- ### Reinstall Mintlify Dependencies (Shell) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Runs the `mintlify install` command to re-install dependencies, often used for troubleshooting issues like the development server not running. ```Shell mintlify install ``` -------------------------------- ### Python SDK Setup Example Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/execute-query.mdx Provides a basic example of setting up the Dune Python SDK client. It shows how to load environment variables and initialize the `DuneClient`. ```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 dotenv, os, json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # change the current working directory where .env file lives os.chdir("/Users/abc/local-Workspace/python-notebook-examples") # load .env file dotenv.load_dotenv(".env") # setup Dune Python client dune = DuneClient.from_env() ``` -------------------------------- ### Run Mintlify Local Development Server (Shell) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Starts the local development server for previewing documentation changes. This command should be run in the root directory containing the `mint.json` file. ```Shell mintlify dev ``` -------------------------------- ### Add New Page Route in mint.json (JSON) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Example JSON structure to add a new page route to the `routes` array in the `mint.json` configuration file. Defines the URL path and the corresponding MDX component file. ```JSON { "routes": [ { "path": "/new-page", "component": "./new-page.mdx" } ] } ``` -------------------------------- ### Python SDK Setup for Request Example Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/get-execution-result.mdx Initializes the Dune Python SDK client by loading environment variables and changing the working directory. This setup is required before making API calls using the SDK, shown here as a prerequisite for subsequent examples. ```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 dotenv, os, json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # change the current working directory where .env file lives os.chdir("/Users/abc/local-Workspace/python-notebook-examples") # load .env file dotenv.load_dotenv(".env") ``` -------------------------------- ### Full Example: Dune Client Setup and Querying - Python Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx A complete example demonstrating how to set up the Dune Python client using environment variables and then how to use the client to either retrieve the latest result of a query without execution or execute the query with parameters and retrieve the fresh result. ```python import dotenv, os from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # change the current working directory where .env file lives os.chdir("/Users/abc/project") # load .env file dotenv.load_dotenv(".env") # setup Dune Python client dune = DuneClient.from_env() """ get the latest executed result without triggering a new execution """ query_result = dune.get_latest_result(3373921) # get latest result in json format # query_result = dune.get_latest_result_dataframe(3373921) # get latest result in Pandas dataframe format """ query the query (execute and get latest result) """ query = QueryBase( query_id=3373921, # uncomment and change the parameter values if needed # params=[ # QueryParameter.text_type(name="contract", value="0x6B175474E89094C44Da98b954EedeAC495271d0F"), # default is DAI # QueryParameter.text_type(name="owner", value="owner"), # default using vitalik.eth's wallet # ], ) query_result = dune.run_query_dataframe( query=query # , ping_frequency = 10 # uncomment to change the seconds between checking execution status, default is 1 second # , performance="large" # uncomment to run query on large engine, default is medium # , batch_size = 5_000 # uncomment to change the maximum number of rows to retrieve per batch of results, default is 32_000 ) # Note: to get the result in csv format, call run_query_csv(); for json format, call run_query(). ``` -------------------------------- ### Using varbinary_starts_with Example SQL Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/varbinary.mdx Provides a simple example demonstrating how varbinary_starts_with checks if a varbinary begins with a specified prefix. The query returns true if the first argument starts with the second. ```SQL -- returns true if starts with 0x3d13f874 SELECT varbinary_starts_with(0x3d13f874abcd,0x3d13f874) ``` -------------------------------- ### Install Dune Python SDK Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx This command installs the Dune Python SDK using pip, the standard package installer for Python. ```bash pip install dune-client ``` -------------------------------- ### Typescript SDK Setup for Execute and Get Result Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/get-execution-result.mdx Initializes the Dune Typescript SDK client using the API key from environment variables. This setup is necessary to interact with the Dune API via the SDK. ```typescript import { QueryParameter, DuneClient } from "@duneanalytics/client-sdk"; const { DUNE_API_KEY } = process.env; const client = new DuneClient(DUNE_API_KEY ?? ""); ``` -------------------------------- ### Get Binary Substring from Start (SQL) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/binary.mdx Returns the rest of binary from the starting position start, measured in bytes. Positions start with 1. A negative starting position is interpreted as being relative to the end of the string. ```SQL substr(binary, start) → varbinary ``` -------------------------------- ### Python SDK Setup for Execute and Get Result Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/get-execution-result.mdx Initializes the Dune Python SDK client by loading environment variables and changing the working directory. This setup is required before making API calls using the SDK. ```python import dotenv, os, json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # change the current working directory where .env file lives os.chdir("/Users/abc/local-Workspace/python-notebook-examples") # load .env file dotenv.load_dotenv(".env") # setup Dune Python client dune = DuneClient.from_env() ``` -------------------------------- ### Example config.py file for Dune Client Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx This is an example of a config.py file structure used to store the Dune API key and request timeout as Python variables. ```python dune_api_key='' request_timeout=300 ``` -------------------------------- ### Simple Single http_get Request Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/live-fetch.mdx A basic example demonstrating a single HTTP GET request to fetch data from the CoinGecko API using the `http_get` function. ```sql SELECT http_get('https://api.coingecko.com/api/v3/coins/list'); ``` -------------------------------- ### Install Dune API SDK (Bash) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/learning/how-tos/crypto-pnl-with-dune.mdx This command installs the necessary Python library, `dune_client`, using pip. This SDK is required to interact with the Dune API from your Python environment. ```bash pip install dune_client ``` -------------------------------- ### Example .env file for Dune Client Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx This is an example of a .env file structure used to store the Dune API key and request timeout for the Python client. ```dotenv DUNE_API_KEY= DUNE_API_REQUEST_TIMEOUT=120 ``` -------------------------------- ### Fetching Dune Execution Results (Go) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/get-execution-result-csv.mdx Provides a Go example for fetching Dune execution results using the standard `net/http` package. It constructs a GET request with the API key header and prints the response status and 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)) } ``` -------------------------------- ### Input Example for size() Method Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/json.mdx Provides an example sequence of JSON arrays used as input for the size() method demonstration. ```text [0, 1, 2], ["a", "b", "c", "d"], [null, null] ``` -------------------------------- ### Paginating Dune Results using Go Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/pagination.mdx This Go snippet uses the standard `net/http` package to make a GET request to the Dune API. It shows how to add `limit` as a query parameter to the request URL for pagination. ```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", "1000") // 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)) } ``` -------------------------------- ### Input Example for keyvalue() Method Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/json.mdx Provides an example sequence of JSON objects used as input for the keyvalue() method demonstration. ```text {"customer" : 100, "region" : "AFRICA"}, {"region" : "ASIA"}, {"customer" : 300, "region" : "AFRICA", "comment" : null} ``` -------------------------------- ### Simple HTTP GET Request (SQL) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/http.mdx Basic example of using the `http_get` function to fetch data from a URL, returning the raw response body as a varchar. ```SQL SELECT http_get('https://api.coingecko.com/api/v3/coins/list'); ``` -------------------------------- ### Filtering Dune Query Results using Go Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/filtering.mdx Shows how to fetch Dune query results in Go using the standard `net/http` package. It builds the URL with query parameters and sets the API key header before executing the GET request. ```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)) } ``` -------------------------------- ### Output Example for size() Method Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/json.mdx Shows the resulting sequence of numeric sizes produced by applying the size() method to the input array example. ```text .size() --> 3, 4, 2 ``` -------------------------------- ### Install Python SDK Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/overview/sdks.mdx Command to install the official Dune Analytics Python client library using the pip package manager. ```bash pip install dune-client ``` -------------------------------- ### Output Example for keyvalue() Method Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/json.mdx Shows the resulting sequence of key-value-id objects produced by applying the keyvalue() method to the input example. ```text {"name" : "customer", "value" : 100, "id" : 0}, {"name" : "region", "value" : "AFRICA", "id" : 0}, {"name" : "region", "value" : "ASIA", "id" : 1}, {"name" : "customer", "value" : 300, "id" : 2}, {"name" : "region", "value" : "AFRICA", "id" : 2}, {"name" : "comment", "value" : null, "id" : 2} ``` -------------------------------- ### Install Typescript SDK Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/overview/sdks.mdx Command to install the community-contributed Dune Analytics Typescript client library using the yarn package manager. ```bash yarn add @duneanalytics/client-sdk ``` -------------------------------- ### Rename File and Update Links (Shell) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Uses the `mintlify rename-file` command to rename a documentation file and automatically update all internal links referencing the old file name. This helps prevent broken links after renaming. ```Shell mintlify rename-file ``` -------------------------------- ### Check for Broken Links (Shell) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/README.md Executes the `mintlify broken-links` command to scan the documentation for broken internal links and output a list to the console. Note that this does not check external `href` links. ```Shell mintlify broken-links ``` -------------------------------- ### Filtering Dune Query Results using Python SDK Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/filtering.mdx Demonstrates fetching the latest results for a specific Dune query using the Python SDK, applying filters, selecting specific columns, and sorting the output. Requires the `dune-client` library and environment setup. ```python import dotenv, os from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase os.chdir("") # load .env file dotenv.load_dotenv(".env") # setup Dune Python client dune = DuneClient.from_env() 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) ``` -------------------------------- ### Paginating Dune Results using cURL Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/pagination.mdx This cURL command demonstrates how to make a GET request to the Dune API results endpoint and limit the number of results returned using the `limit` query parameter. ```bash curl -X GET 'https://api.dune.com/api/v1/query/{{query_id}}/results?limit=1000' -H 'x-dune-api-key: {{api_key}}' ``` -------------------------------- ### Get Execution Status using Dune Python SDK Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/endpoint/get-execution-status.mdx This example shows how to use the official Dune Python SDK to fetch the status of a query execution. It requires installing the SDK (`pip install dune-client`), loading environment variables (like the API key), and providing the execution ID (`job_id`). ```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 dotenv, os, json from dune_client.types import QueryParameter from dune_client.client import DuneClient from dune_client.query import QueryBase # change the current working directory where .env file lives os.chdir("/Users/abc/local-Workspace/python-notebook-examples") # load .env file dotenv.load_dotenv(".env") # setup Dune Python client dune = DuneClient.from_env() result = dune.get_execution_status(job_id = '01HM79YYNXADPK66YWZK5X0NXB') # pass in the execution_id ``` -------------------------------- ### Using SQL Quantifiers ALL, ANY, SOME Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/comparison.mdx Demonstrates the usage of ALL, ANY, and SOME quantifiers with comparison operators in SQL queries. Shows examples returning true and false based on subquery results. ```sql SELECT 'hello' = ANY (VALUES 'hello', 'world'); -- true SELECT 21 < ALL (VALUES 19, 20, 21); -- false SELECT 42 >= SOME (SELECT 41 UNION ALL SELECT 42 UNION ALL SELECT 43); -- true ``` -------------------------------- ### Paginating Dune Results using Java Unirest Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/executions/pagination.mdx This Java snippet uses the Unirest library to perform a GET request to the Dune API. It shows how to easily add `limit` and `offset` as query string parameters for pagination. ```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", 1000) .queryString("offset", 0) .asString(); System.out.println(response.getBody()); } } ``` -------------------------------- ### Set up Dune Python Client (Inline) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx Initialize the DuneClient by providing your API key directly. You can also configure the base URL and request timeout. ```python dune = DuneClient( api_key='', base_url="https://api.dune.com", request_timeout=300 # request will time out after 300 seconds ) ``` -------------------------------- ### SQL LIKE with Percent Wildcard Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/query-engine/Functions-and-operators/comparison.mdx Demonstrates using the LIKE operator with the % wildcard in SQL to find strings that start with a specific character sequence. Filters a list of continents to find those starting with 'E'. ```sql SELECT * FROM (VALUES 'America', 'Asia', 'Africa', 'Europe', 'Australia', 'Antarctica') AS t (continent) WHERE continent LIKE 'E%'; ``` -------------------------------- ### Set up Dune Python Client (using .py file) Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/api-reference/quickstart/results-eg.mdx Initialize the DuneClient by importing configuration variables from a separate Python file (e.g., config.py). This helps organize configuration settings. ```python import config dune = DuneClient( api_key=config.dune_api_key, base_url="https://api.dune.com", request_timeout=(config.request_timeout) ) ``` -------------------------------- ### Example Parameterized Dune Embed URL Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/web-app/embeds.mdx This snippet provides a working example of a Dune embed URL that includes parameters. Parameters must be manually appended to the base embed link using the format '?param1=value1¶m2=value2'. ```url https://dune.com/embeds/118220/238460/aa002dd3-f9e2-4d63-86c8-b765569306c6NFT?address=0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7&rolling_n_trades=500 ``` -------------------------------- ### Embedding an Arcade Software Demo in HTML Source: https://github.com/vy-bewhale/dune/blob/main/dune-docs/quickstart.mdx This HTML snippet demonstrates how to embed an interactive demo from Arcade Software using an iframe within a styled div container. The styling ensures the iframe maintains a responsive aspect ratio. ```HTML