<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>0xPhillan</title>
        <link>https://paragraph.com/@phillan</link>
        <description>Blockchain and crypto researcher.</description>
        <lastBuildDate>Wed, 08 Apr 2026 02:50:28 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>0xPhillan</title>
            <url>https://storage.googleapis.com/papyrus_images/d6a8c62193c3bd1f4e7755fea94a854b160f599bf4603ea1f63a310eef82303a.png</url>
            <link>https://paragraph.com/@phillan</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Dune Analytics: A Guide for Complete Beginners]]></title>
            <link>https://paragraph.com/@phillan/dune-analytics-a-guide-for-complete-beginners</link>
            <guid>xCx8QToCnfOJcp06ygsV</guid>
            <pubDate>Tue, 07 Jun 2022 12:39:58 GMT</pubDate>
            <description><![CDATA[Learn how to use Dune Analytics, for complete Dune and SQL beginners. Please consider following me on Twitter @0xPhillan Dune is probably the strongest blockchain data analytics tool currently available to the public, and what&apos;s best is: it&apos;s free! With Dune you get near real-time access to blockchain data through a public database that you can query through Dune&apos;s website using SQL. That&apos;s a lot of power. Dune decodes blockchain data before adding it to their database, me...]]></description>
            <content:encoded><![CDATA[<p><em>Learn how to use Dune Analytics, for complete Dune and SQL beginners. Please consider following me on Twitter</em> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xPhillan"><em>@0xPhillan</em></a></p><p>Dune is probably the strongest blockchain data analytics tool currently available to the public, and what&apos;s best is: <strong>it&apos;s free!</strong> With Dune you get near real-time access to blockchain data through a public database that you can query through Dune&apos;s website using SQL.</p><p><strong>That&apos;s a lot of power.</strong></p><p>Dune decodes blockchain data before adding it to their database, meaning that you don&apos;t have to figure out bytecode communication on your own. Instead, you use Dune&apos;s dataset explorer to browse datasets, specific smart contracts, events, or calls!</p><p>With Dune&apos;s <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dune.com/blog/Dune-Engine-V2">recent announcement</a> of their V2 Engine, which increases performance by 10x, it&apos;s about time you learn how to use Dune.</p><p>In this guide, you will learn:</p><ul><li><p>Part 1: The Dune interface</p></li><li><p>Part 2: Build your own queries and charts with SQL – starting from the very basics</p></li><li><p>Part 3: Organizing it all into a dashboard</p></li></ul><p>In this step-by-step guide we will build the queries of below dashboard for the Pooly NFT series:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3d0ed9689bd41af1d350f0a51a437520d6f1e64f947c59a735c5103f3f8a1cc7.png" alt="@0xPhillan via https://dune.com/phillan/pooly-nft-by-0xphillan" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">@0xPhillan via https://dune.com/phillan/pooly-nft-by-0xphillan</figcaption></figure><p>Let&apos;s get started!</p><h1 id="h-contents" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Contents</h1><ul><li><p>Part 1: Overview of Dune and Functionality</p><ul><li><p>Dashboards</p></li><li><p>Queries</p></li><li><p>Forking</p></li><li><p>Query Editor</p></li><li><p>Dataset Explorer &amp; Data Categories</p></li><li><p>Saving Your Forked Query</p></li></ul></li><li><p>Part 2: Building Your First Query</p><ul><li><p>Deciding Which Queries to Build</p></li><li><p>Finding the Right Information</p></li><li><p>Getting Ready to Build Your First Query in Dune</p><ul><li><p>Query 1: Funds Raised in ETH</p></li><li><p>Query 2: Funds raised in USD</p></li><li><p>Query 2a: Funds raised in USD at Current ETH Value</p></li><li><p>Query 2b: Funds raised in USD at ETH Value at Time of Purchase</p></li><li><p>Query 3: Total Number of Supporters</p></li><li><p>Query 4a: Leaderboard using the erc721. Abstraction</p></li><li><p>Query 4b: Leaderboard using the poolysupporter. Decoded Table</p></li><li><p>Query 5: Max Supply and Remaining Supply of Each of the NFT sets</p></li><li><p>Query 6: Timeseries Chart of ETH Raised Over Time</p></li></ul></li></ul></li><li><p>Part 3: Cleaning up the Dashboard</p></li><li><p>Closing</p></li></ul><h2 id="h-part-1-overview-of-dune-and-functionality" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 1: Overview of Dune and Functionality</h2><p>When you first open the Dune website at Dune.com, you are greeted with below window. This window has a view changer at the top that lets you cycle through dashboards, queries and wizards, and then the detailed view area in which you can see the list of dashboards, queries and wizards (users) on the left as well as some search-related settings on the right.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c827cf089e75e903bde94ffef6ffe87c5eedde366a368222e033570fd3a701c5.png" alt="Dune.com landing page" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dune.com landing page</figcaption></figure><h3 id="h-dashboards" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Dashboards</h3><p>Dashboards are a collection of queries that are arranged as a series of charts, counters, and other information to give the user context about a specific area of interest. Below, I have opened an Ethereum dashboard by the legendary <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dune.com/hildobby/">@hildobby</a>. Here we can see all sorts of data that is being pulled from Dune’s database, shown as sums and timeseries charts.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/6fce272c3bc1e9c8c11169c417b1d4797218e8f3ab8d5828d563c3c886063d03.png" alt="@hildobby via https://dune.com/hildobby/Ethereum-Overview" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">@hildobby via https://dune.com/hildobby/Ethereum-Overview</figcaption></figure><p>In Dune, every dashboard is public. That means everything you build or other people build can be viewed and forked (i.e., copied) by anybody! This severely decreases dashboard creation time and lets you learn from other users&apos; queries.</p><h3 id="h-queries" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Queries</h3><p>If you recall, I mentioned that dashboards are a collection of <em>queries</em>. If you click on the title of any one of the dashboard elements, you&apos;ll be taken to that chart&apos;s SQL query:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c702864902c80aebff73a043f1aee45faa7af8f8aa51efd57eb2a7399b720dc3.png" alt="Two examples of query editor screens from previous Ethereum Dashboard." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Two examples of query editor screens from previous Ethereum Dashboard.</figcaption></figure><p>Here in Here we can see two primary on-screen elements: the query (top; black box) and the output chart (bottom). That’s right: no matter which block or chart you click on, you can see <em>how</em> the user created that chart!</p><h3 id="h-forking" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Forking</h3><p>If you want to save an entire dashboard or only the chart’s query to your own account, you can click “Fork” on the top right, and everything on the forked screen will be duplicated to a new window, in which you can make edits before saving the views to your account.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/36c7a7d288e8e7e31b308534531617c41d935a20ca8bc73469b38f417a339453.png" alt="Ethereum Price Query. @hildobby via https://dune.com/queries/663019/1231425" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Ethereum Price Query. @hildobby via https://dune.com/queries/663019/1231425</figcaption></figure><p>Let&apos;s fork the Ethereum Price chart! Once you press &quot;Fork&quot; on a query, you&apos;ll be taken to the query editor with the previous code already copied in!</p><h3 id="h-query-editor" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query Editor</h3><p>Let me introduce you to the various on-screen elements here:</p><ol><li><p>Query location &amp; name – name can be changed once you hit save!</p></li><li><p>Dataset explorer – search for a specific dataset</p></li><li><p>Query window – input your SQL queries here</p></li><li><p>Visualization selector – choose whether to see query results, the forked line chart or create a new visualization</p></li><li><p>Run – run the query that is in the query window</p></li><li><p>Results/Visualization – see query results or your visualization created with the query results</p></li><li><p>Save – save your (forked) query!</p></li></ol><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/9019807c280fbe90fd94fa9f6bd901806da09c84dde2a45809416372b8a00eb6.png" alt="Overview of the Dune query editor" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Overview of the Dune query editor</figcaption></figure><h3 id="h-dataset-explorer-and-data-categories" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Dataset Explorer &amp; Data Categories</h3><p>Let&apos;s take a closer look at the dataset explorer. There are six functional areas within the dataset explorer:</p><ol><li><p>Chain selection</p></li><li><p>Dataset search</p></li><li><p>Browse raw blockchain data</p></li><li><p>Browse data of decoded contracts</p></li><li><p>Browse abstractions</p></li><li><p>Browse community-supplied data</p></li></ol><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cb6e877caaa027755bba03f535c6fbaabec90bfa988b7729364bdf65889fc0ff.png" alt="Overview of the Dune dataset explorer" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Overview of the Dune dataset explorer</figcaption></figure><h4 id="h-dataset-selection" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Dataset Selection</h4><p>In the dataset selection you can choose which chain you want to parse. Selecting &quot;Dune Engine V2 (Beta)&quot; let&apos;s you use Dune&apos;s latest enhancements which include multichain queries and 10x performance increases.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d619bcd1306e24bf5742121bec2f01160dd3ffb1b89fb8994332d64966100abc.png" alt="Dataset selection options in dataset explorer" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dataset selection options in dataset explorer</figcaption></figure><p>If you choose another chain, you the category selection (items 3-6 in previous image) will disappear and instead you&apos;ll see a list of contract calls and events that you can interact with.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a99e405e2bb0fcb3640c4f368655f0e2187a18ab6318ae9bd06f663e1c743be3.png" alt="Dataset explorer when selecting &quot;1. Ethereum&quot;" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dataset explorer when selecting &quot;1. Ethereum&quot;</figcaption></figure><h4 id="h-search" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Search</h4><p>In the search field you can input your search parameter, and Dune will search through all tables that include that keyword in some form.</p><p><em>Note: The Dune Engine V2 and the old search function return results in a different fashion. The old search returns a list of all results, while Dune Engine V2 returns a nested list of results. We will be using the V2 engine!</em></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cf973f245bf970092070c9a18e4e2563f5544826f6da603f4bd1c3306958061a.png" alt="Comparison of &quot;1. Ethereum&quot; and &quot;7. Dune Engine V2 (Beta)&quot; search results" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Comparison of &quot;1. Ethereum&quot; and &quot;7. Dune Engine V2 (Beta)&quot; search results</figcaption></figure><h4 id="h-raw-blockchain-data" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Raw Blockchain Data</h4><p>If you click into raw blockchain data, you can easily find queries for the various blockchains that Dune supports in a nested data structure where you can first pick your raw table, and from there pick the specific table columns you want to investigate further. Within each level of nesting you are also given the option to filter for specific search results you are looking for.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/44b59702c579c0c4f5a07cd729437117feb30b411a85e42da337b54af7fa5148.png" alt="Dune Engine V2 (beta) raw blockchain data overview" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dune Engine V2 (beta) raw blockchain data overview</figcaption></figure><p>This is a very quick and handy way to get high level blockchain data.</p><h4 id="h-decoded-projects" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Decoded Projects</h4><p>In here you will find projects that have been decoded by Dune. Decoded projects are projects that the Dune team took apart, labelled, and put into tables so that users have an easy and standardized reference for certain data.</p><p>You will notice that again, the search results are nested. At the highest level, we have projects that you can search through, at a lower level you can filter specific smart contracts within that project, and finally we get to the various tables generated from that smart contract. If you click on any of the tables, you will see a list of columns, just like in with the raw blockchain data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f1f7b962cd0de626289e7d5c4cac778354dfc00bd124a12efd33c3b6cbc9f0c8.png" alt="Dune Engine V2 (beta) decoded projects overview" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dune Engine V2 (beta) decoded projects overview</figcaption></figure><h4 id="h-abstractions" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Abstractions</h4><p>Abstractions can be thought of as custom tables that connect and combine various queries and pieces of data to form a unique table. Abstractions help users to query specific data they are looking for more easily, without the trouble of manually combining various pieces of data.</p><p>Generally, abstractions can be split into two main categories:</p><ul><li><p>Sector abstractions: sector-specific data</p></li><li><p>Project abstractions project-specific data</p></li></ul><p>From the abstractions sub-menu, we can see a list of abstractions with labels that specify whether the abstraction is sector-specific or project specific.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/bbd2a7621dcc3a0630b280de0aecca1a5a5c2b9af46455c88993be4981428975.png" alt="Dune Engine V2 (beta) abstractions overview" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dune Engine V2 (beta) abstractions overview</figcaption></figure><h4 id="h-community" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Community</h4><p>The community section can be thought of as an extension of the abstraction section, but with data aggregations being supplied by Dune community members.</p><p>You may wonder why there is only one entry in the community section (&quot;flashbots&quot;) – well, that&apos;s because Dune Engine V2 was just released! Over time, we can expect to see more and more community-built datasets by trusted community members.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/9657c0b16d6d0fe82bf8fe51b888034bede6528abc394d0c20fbad1d99c67718.png" alt="Dune Engine V2 (beta) community overview" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dune Engine V2 (beta) community overview</figcaption></figure><h4 id="h-dataset-explorer-labels" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0">Dataset Explorer Labels</h4><p>In below illustration you can see a summary of how data is summarized within Dune as of launch of Dune Engine V2: the four main data categories are raw blockchain data, decoded projects, abstractions, and community, which hold the data of various blockchains in table format that can hold various data types.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/75eb5153d64a874aefe861679a58184325fec538da9c40d85928a495a39aec4d.png" alt="Overview of labels in the Dune Engine V2 (beta) data explorer" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Overview of labels in the Dune Engine V2 (beta) data explorer</figcaption></figure><h3 id="h-saving-your-forked-query" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Saving Your Forked Query</h3><p>Let&apos;s go ahead and save this query first. After you hit save, a few things will happen. First, you will be asked to give your query a name.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/515231ee3aa25bf4733723ac64c183a2e0505d2f453bd504177f20825c2a8b70.png" alt="Save query pop-up" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Save query pop-up</figcaption></figure><p>Once you&apos;ve chose a name, you will notice (1) the query location and name have been updated to your chosen name and (2) your query is running. That means Dune is fetching the latest data from their database, which is periodically updated with the latest data from various blockchains.</p><p>Once the query is finished running, you&apos;ll see your query results (3).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/178ec25f9e19121f2be77a1c31bae61d141aed1e99b28b7d8b2e499045d27e8f.png" alt="Overview of forked query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Overview of forked query</figcaption></figure><p>From here, if you click any of (1) &quot;Query results&quot;, &quot;Line Chart&quot; or &quot;New visualization&quot;, the (2) result/visualization box will update together with (3) settings for your selection that appear beneath it. Here you also have an &quot;Add to dashboard&quot; button, to quickly add your query results or visualization to new or existing dashboards – just like @hildobby&apos;s Ethereum dashboard from earlier!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/71e22e3034a856cc6f9b085f660e1c0dc28feb30e940792e4baeb783d17215f2.png" alt="Query results and visualization section" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Query results and visualization section</figcaption></figure><p>If you click on (1) the circle in the top right and then on (2) “My queries”, you will open the queries list of your account.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/af0fc50bc653e3f9ba01bff2fce956daea9f7dcee0bb6d5b3fb1581c6ac53be0.png" alt="Navigating to your queries" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Navigating to your queries</figcaption></figure><p>The queries list includes all queries you’ve ever saved on your account. In below screenshot at the top we can see the latest query created:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a515a12db8fd3d98cb6ffdd8a60e2476da50e905cc077f8b99381aa2ec3ec858.png" alt="Your query list with latest query saved at the top" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Your query list with latest query saved at the top</figcaption></figure><p><em>Congratulations, you&apos;ve forked and saved your first query with a visualization!</em></p><p>Forking is a Dune superpower, and it can help you easily and quickly create new queries by building on what other wizards (yes, you&apos;re a wizard now too!) have built before you. You can combine multiple forked queries to build your own dashboard!</p><p>Let&apos;s get our hands dirty and build a dashboard – a collection of queries and visualization – from scratch without forking. This will teach you where to find the right blockchain details to look for your specific project as well as teach you SQL basics.</p><h2 id="h-part-2-building-your-first-query" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 2: Building Your First Query</h2><p>The purpose of this section is to teach you:</p><ol><li><p>How to find the right information you need for your specific project</p></li><li><p>Some basic SQL</p></li></ol><p>But first, we need to decide what we want our dashboard to be about. Pooly NFTs by the Pool Together DeFi protocol are a great first step.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/fc5cbdfd42f9dd4c962ef822e9e44548a516307bd7375cd4262f030a06b15e7e.png" alt="Pooly NFT minting page. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly NFT minting page. Source: https://mint.pooltogether.com/</figcaption></figure><p>If we search for &quot;Pooly&quot; on Dune, sure enough we can find some Pooly NFT trackers created by the community.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7790568dc4ce820a1e109a12aabe7ea85e3232e7431c2384d940280dbe0b5b59.png" alt="Search results for Pooly on Dune.com" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Search results for Pooly on Dune.com</figcaption></figure><p>We could click into one the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dune.com/0xbills/Pooly-NFT">Pooly dashboard</a> created by <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://dune.com/0xbills">@0xbills</a> and click on &quot;Fork&quot; and work from there…</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/97916bbd3bff338af00b6525a8aff77597b2b2398100a50ca2068138b2c4797a.png" alt="@0xbills via https://dune.com/0xbills/Pooly-NFT" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">@0xbills via https://dune.com/0xbills/Pooly-NFT</figcaption></figure><p>However, if we build it from scratch we get to learn how to be a blockchain detective and learn some SQL as well! So instead, we&apos;ll build our own from scratch.</p><h3 id="h-deciding-which-queries-to-build" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Deciding Which Queries to Build</h3><p>First, let&apos;s decide what charts we want on our dashboard. Let&apos;s rebuild the views that Pooly built on their homepage! Taking a closer look at below two screenshots, we can see a few indicators based on on-chain data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d7dfe22adfdae1f71e184699d75bf0130babcab0a3bdcbe381254292d33601ed.png" alt="Pooly NFT landing page with funding tracker. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly NFT landing page with funding tracker. Source: https://mint.pooltogether.com/</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/53f45de718071820cff3ddc7e616d248d5d55b1af8793e3eba10015b318917b2.png" alt="Pooly NFT leaderboard. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly NFT leaderboard. Source: https://mint.pooltogether.com/</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/55c48b620e2a10cdce948aa53c572e7901d5f4b87ad4c6c18552383ef08f36b6.png" alt="Pooly NFT mint options and supply. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly NFT mint options and supply. Source: https://mint.pooltogether.com/</figcaption></figure><p>We can see:</p><ul><li><p>Funds raised vs funding target denominated in ETH</p></li><li><p>Funds raised vs funding target denominated in USD</p></li><li><p>Total number of supporters (unique addresses that purchased a Pooly)</p></li><li><p>Leaderboard including addresses, number of NFTs purchased per address and total ETH spent in descending order</p></li><li><p>Max supply and remaining supply of each of the three NFT types</p></li></ul><p>Awesome! But those are only a snapshot in time. Let&apos;s give ourselves another challenge as well:</p><ul><li><p>Timeseries chart of ETH raised over time</p></li></ul><p>As it stands now, we can&apos;t build the views in the same way as the Pooly website, but we can capture the same amount of data (and more!) to build our dashboard.</p><h3 id="h-finding-the-right-information" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Finding the Right Information</h3><p>Before we get started on Dune, we need to find the right information. From the website we can tell that PoolTogether is selling three sets of NFTs:</p><ul><li><p>Supporter – 1 of 9 random collectible for 0.1 ETH</p></li><li><p>Lawyer – Only one artwork for 1 ETH</p></li><li><p>Judge – Only one artwork for 75 ETH</p></li></ul><p>Is Pooly selling all three NFTs through one contract, or through three different contracts?</p><p>Let&apos;s head to Etherscan and see if we can find a smart contract related to Pooly. Once you open <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/">Etherscan.io</a> type &quot;Pooly&quot; to see if the owner of these smart contract registered them with Etherscan.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ef0e80f21703500a8693310169606e699c1db088eb14cac81107749f32b74e13.png" alt="Searching for Pooly on Etherscan" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Searching for Pooly on Etherscan</figcaption></figure><p>Indeed! There are three smart contracts, likely corresponding to each of the three NFT collections. Furthermore, we now know that each Pooly is an ERC721 token.</p><p>Open each of the three collections and copy the smart contract address by clicking on the copy icon that appears upon hovering over the address. At the bottom of the page we can see all recent transactions as well, which will be helpful for troubleshooting later.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cd999fca4f85d6568a3b693b256ceb8b86e3dfd94f1d92bf23785b82830cbdf0.png" alt="Finding Pooly contract addresses through Etherscan. Source: https://etherscan.io/token/0x90B3832e2F2aDe2FE382a911805B6933C056D6ed" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Finding Pooly contract addresses through Etherscan. Source: https://etherscan.io/token/0x90B3832e2F2aDe2FE382a911805B6933C056D6ed</figcaption></figure><p>We will need these smart contract addresses to pull the right data from Dune, and they form the foundation of all of our queries:</p><p>0.1 ETH Pooly Supporter:</p><pre data-type="codeBlock" text="0x90B3832e2F2aDe2FE382a911805B6933C056D6ed
"><code></code></pre><p>1.0 ETH Pooly Lawyer:</p><pre data-type="codeBlock" text="0x3545192b340F50d77403DC0A64cf2b32F03d00A9
"><code></code></pre><p>75 ETH Pooly Judge:</p><pre data-type="codeBlock" text="0x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523
"><code></code></pre><h3 id="h-getting-ready-to-build-your-first-query-in-dune" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Getting Ready to Build Your First Query in Dune</h3><p>First, navigate to dune.com and click &quot;New Query&quot; on the top right of the screen.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/154e195648297e84a134e70b70b045fafa42024002fd6d548cddb81260896d8b.png" alt="Creating a new query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Creating a new query</figcaption></figure><p>This will open the query editor and we can start working on our query!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7c4c21cad347940c072ecc39e75f716f5b2729ef94e45ca805aa2b4b0418c8e4.png" alt="Fresh and untouched new query window" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Fresh and untouched new query window</figcaption></figure><h3 id="h-query-1-funds-raised-in-eth" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 1: Funds Raised in ETH</h3><p>First, in the top left switch from &quot;7. Dune Engine V2 (Beta)&quot; to &quot;1. Ethereum&quot;. Pooly lives on Ethereum, thus we only need Ethereum data for this query. Plus, the tables in &quot;1. Ethereum&quot; are more mature than than Dune Engine V2, which only just entered beta.</p><p>For our first query, we will build a counter that shows funds raised denominated in ETH. To do this, copy below code into the query field in Dune and press &quot;run&quot; (or CTRL+Enter):</p><pre data-type="codeBlock" text="select SUM(&quot;value&quot;/1e18) from ethereum.transactions
where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
"><code>select SUM(<span class="hljs-string">"value"</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/40ef1d5931c8cbb2bace008812b3cd99c17d77a4150cb1b653d1320f7932efc7.png" alt="@0xPhillan via https://dune.com/queries/882266" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">@0xPhillan via https://dune.com/queries/882266</figcaption></figure><p>The above code is an SQL query that parses through Dune&apos;s database to fetch specific data that we requested. You can imagine Dune&apos;s database to be a collection of various tables, each containing specific information you may want to pull. With SQL, you…</p><ul><li><p>specify what data you want (which column in a table)</p></li><li><p>whether you want to transform that data</p></li><li><p>from which table you want to get the data</p></li><li><p>whether you want to filter the data</p></li></ul><p>To illustrate the above, let us run the above code piece by piece. Copy the below code into Dune&apos;s query editor and run it:</p><pre data-type="codeBlock" text="select * from ethereum.transactions
where &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
"><code>select <span class="hljs-operator">*</span> <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
</code></pre><p>You will get a big table with a lot of information:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/edb02863522c914e7575c42913122c80b70fdc79d928537b12c3ce415b4e97f3.png" alt="Example of using the \* command to return all columns from a table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Example of using the \* command to return all columns from a table</figcaption></figure><p>Now let&apos;s walk through the SQL code:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8e5607ceef4d2d2eebccae03b0222a13051e4fb452628b08086a201ded3fa835.png" alt="Breakdown of SQL code" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Breakdown of SQL code</figcaption></figure><p>What this code says is &quot;select <em>all columns</em> from the <em>transactions</em> table within the <em>ethereum category</em> where the value in the <em>to</em> column is <em>\x3545192b340F50d77403DC0A64cf2b32F03d00A9</em>&quot; or in plain English: show me a table with all smart contract interactions with the Pooly2 (1 ETH) smart contract.</p><p><em>You don&apos;t need to run a query to see the columns within a table. The data explorer let&apos;s you explore the various table headers through their nifty search function:</em></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ad40275caae4b1da32ef71e16e415f54b4fc9aea5286133415b156c7b234b179.png" alt="Using the data explorer to search for tables within &quot;ethereum.&quot;" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Using the data explorer to search for tables within &quot;ethereum.&quot;</figcaption></figure><p>We could have removed line 3 entirely to remove the filter, however, this would have returned a massive table and the query would have taken a long time to complete. The more precise your queries, the faster they will run!</p><p>Because we only want to return funds raised, we don&apos;t need all columns. So let&apos;s adjust our code to only grab the &quot;value&quot; column:</p><pre data-type="codeBlock" text="select &quot;value&quot; from ethereum.transactions
where &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
"><code>select <span class="hljs-string">"value"</span> <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
</code></pre><p>Now we only have one “value” column instead of the many we saw before:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8cc0a06bfc568c8cd4ad6ef7c8461bf0be5fc86bee27f67a01d44ce3f095bec4.png" alt="Returning all entries in the &quot;value&quot; column" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Returning all entries in the &quot;value&quot; column</figcaption></figure><p>You may notice, however, that the values seem to be quite large. That&apos;s because they are denominated in Wei and not ETH! To fix that, we can simply apply an arithmetic operator to the &quot;value&quot; column:</p><pre data-type="codeBlock" text="select &quot;value&quot;/1e18 from ethereum.transactions
where &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
"><code>select <span class="hljs-string">"value"</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span> <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cd0e010f69a676918e8907c8d9838ca63cc904189c8547c438af797f6b740a1c.png" alt="Converting the denomination of the &quot;value&quot; column from wei to ETH" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Converting the denomination of the &quot;value&quot; column from wei to ETH</figcaption></figure><p>That looks better! 1e18 in SQL is the same as 10^18, and we are simply telling Dune to divide the number by 1,000,000,000,000,000,000 so that instead of Wei, we see the values denominated in ETH.</p><p>And since we only want the total value and not a list of value, we can wrap the &quot;value&quot;/1e18 in a SUM() statement:</p><pre data-type="codeBlock" text="select SUM(&quot;value&quot;/1e18) from ethereum.transactions
where &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
"><code>select SUM(<span class="hljs-string">"value"</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4e5b5b9065e196bc5283483678ea0cd891504a79a05325253b43062d08374b6f.png" alt="Using SUM() to consolidate all entries in the &quot;value&quot; column to one sum." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Using SUM() to consolidate all entries in the &quot;value&quot; column to one sum.</figcaption></figure><p>Awesome, we can now see the total number of ETH spent on Pooly2! And since we want to get the total spent on all three Pooly NFT smart contracts, we need to add two more lines to include details about the other smart contracts:</p><pre data-type="codeBlock" text="select SUM(&quot;value&quot;/1e18) from ethereum.transactions
where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
"><code>select SUM(<span class="hljs-string">"value"</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/926b8c8ab5d77d8a9c4eb09c8f0b8acd4c6cfe423b3cee8df2d77c48ea535152.png" alt="Final output. @0xPhillan via https://dune.com/queries/882266" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Final output. @0xPhillan via https://dune.com/queries/882266</figcaption></figure><p>The &quot;<em>or</em>&quot; command works in tandem with the &quot;<em>where</em>&quot; command and specifies that when filtering the values in the &quot;to&quot; column, that the row should be considered if the first value or the second value or the third value are found.</p><p>We now see that in total 773.7 ETH has been spent on all three Pooly contracts. Awesome! Let&apos;s go to the Pooly website to see if that&apos;s right:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d8e4e85c3611f6a94482f77293111e326677226a04b53492bed37171fe1a7058.png" alt="Comparing our output against the official figures on the Pooly NFT page. Funding target hit - congrats!" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Comparing our output against the official figures on the Pooly NFT page. Funding target hit - congrats!</figcaption></figure><p>On the Pooly Website we see 776.5 ETH - congrats on achieving the target! But, oh no, there&apos;s a 2.8 ETH difference! Well – that&apos;s nothing to worry about. Dune syncs blockchain data in regular intervals. And because the dataset they sync to their database is so massive, it takes some time. We can expect the data to be refreshed in the next hour or two.</p><p>Now that our query is complete, we need to set up a counter to display this on our dashboard later. Below the Query results box, click on new visualization, and in the drop down menu that appears click on &quot;counter&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e4e1252f5fbb2d563faf2ec716a22351c73d4dd03083204b5f31fd7d29a8cbac.png" alt="Adding a counter to our query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adding a counter to our query</figcaption></figure><p>And finally, click on &quot;Add visualization&quot;:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/206d31b79af5b12cc381a38412efd5d8f8ce9e7f12b7933f2a36ccebd917a9e7.png" alt="Adding a counter visualization to the query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adding a counter visualization to the query</figcaption></figure><p>A counter will appear and if you scroll down, you&apos;ll see various settings show up. Simply adjust the settings to your liking.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/374caff3b8b96e8b7e4a6d4913694f381f98b09498119aaf2108c39eb14f16ea.png" alt="Counter visualization label and title settings" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Counter visualization label and title settings</figcaption></figure><p>Once done, click on (1) &quot;Add to dashboard&quot; and select (2) &quot;New dashboard&quot;. Then (3) give your dashboard a name and (4) click &quot;Save dashboard&quot;. Your new dashboard will appear in your dashboards list. From here click (5) &quot;add&quot; on the dashboard you wish to add your visualization to. Once added, the label will change from &quot;add&quot; to &quot;added&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f141948e7a04f923d0e34b312aaae2b4dcbfea7ba743d74633f0407632c85d60.png" alt="Adding a visualization to a dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adding a visualization to a dashboard</figcaption></figure><p>If you click on your dashboard&apos;s name in this sub-menu (&quot;Pooly NFT by 0xPhillan&quot;), you will be taken to a dashboard that has our tracker displayed.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/813d1206c4f67b995756982da58fc271ab590da48565bbf406eee4da6296d819.png" alt="Dashboard with the visualization added" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dashboard with the visualization added</figcaption></figure><p><em>Great!</em></p><p>We&apos;ll get back to editing our dashboard once we have completed setting up all queries.</p><h3 id="h-query-2-funds-raised-in-usd" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 2: Funds raised in USD</h3><p>There are two ways that we can approach this:</p><ol><li><p>Use the <em>current</em> value of the funds in USD used to purchase the NFTs</p></li><li><p>Use the USD value of the funds <em>at the time of purchase</em></p></li></ol><p>If we look at the smart contracts on Etherscan, we can see that a large portion of the 776.5 ETH have already been moved out of the smart contracts, leaving 299.2 ETH in the Pooly NFT smart contracts as of time of writing.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2bfa30b4630bfcec09e551ee900a914c6ce5c6540533b45ec37546c69b133ba0.png" alt="Pooly1/2/3 smart contract ETH balances on Etherscan.io" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly1/2/3 smart contract ETH balances on Etherscan.io</figcaption></figure><p>If we look at the Pooly website screenshot from earlier 776.5 ETH is valued at $1,411,249 USD ($1,817 USD/ETH), hinting that possibly the Pooly smart contract owner is keeping the funds as ETH instead of trading for USD.</p><p>Ultimately, it&apos;s difficult to say which approach Pooly is taking, but both approaches to USD value are interesting:</p><ol><li><p>The <em>current value</em> tells us what the funds are worth now</p></li><li><p>The <em>value at time of purchase</em> tells us the intended USD donation amount by purchasers</p></li></ol><p>So… let&apos;s create both!</p><h3 id="h-query-2a-funds-raised-in-usd-at-current-eth-value" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 2a: Funds raised in USD at Current ETH Value</h3><p>For this one, we&apos;ll use our previous code as a base and slot in some additional lines to get the current USD value.</p><p>First, fork the query we just created:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0dae04f6c13c7322f52c2b09ac82c17665dbb45cb8b65d35b24676bf90def8c5.png" alt="Forking the previous query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Forking the previous query</figcaption></figure><p>Then adjust your code to look as follows:</p><pre data-type="codeBlock" text="select SUM(&quot;value&quot;/1e18) * (
        SELECT &quot;price&quot; FROM prices.usd
        WHERE &quot;symbol&quot; = &apos;WETH&apos; 
        AND &quot;minute&quot; &lt; now() - interval &apos;1 hours&apos;
        ORDER BY &quot;minute&quot; DESC 
        LIMIT 1
    )

from ethereum.transactions

where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
"><code>select SUM(<span class="hljs-string">"value"</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) <span class="hljs-operator">*</span> (
        SELECT <span class="hljs-string">"price"</span> FROM prices.usd
        WHERE <span class="hljs-string">"symbol"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'WETH'</span> 
        AND <span class="hljs-string">"minute"</span> <span class="hljs-operator">&#x3C;</span> <span class="hljs-built_in">now</span>() <span class="hljs-operator">-</span> interval <span class="hljs-string">'1 hours'</span>
        ORDER BY <span class="hljs-string">"minute"</span> DESC 
        LIMIT <span class="hljs-number">1</span>
    )

<span class="hljs-keyword">from</span> ethereum.transactions

where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
</code></pre><p>You&apos;ll notice that we have added a multiplication operator <strong>*</strong> and a large code block right after our <strong>SUM(&quot;value&quot;/1e18)</strong> command.</p><p>In Dune, you can highlight specific portions of your query and only run that portion by clicking &quot;Run selection&quot;. Let&apos;s (1) highlight only the lines within the parentheses and (2) run that selection:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/412ed0689d559b573713c3ca8a138f1fbd901dc7907c2bed33fd669f39e6a61e.png" alt="By selecting part of your query, you can run only the selected portion. @0xPhillan via https://dune.com/queries/883725" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">By selecting part of your query, you can run only the selected portion. @0xPhillan via https://dune.com/queries/883725</figcaption></figure><p>In the query results you&apos;ll see the latest USD price of WETH! Our addition here multiplies the latest price of WETH with the amount of ETH raised to give us the USD value.</p><p>Let&apos;s break down this code block:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3bff5af501bb388a72f65567fe6cd091b978792ffcd3628f80aab69c26316e94.png" alt="Breakdown of previous code" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Breakdown of previous code</figcaption></figure><ol><li><p>From the prices.usd table select the &quot;price&quot; column</p></li><li><p>Filter the symbol column for &quot;WETH&quot;</p></li><li><p>Only look at time entries of the past 1 hour (this will significantly speed up the query)</p></li><li><p>Order in descending order (newest first)</p></li><li><p>Limit the query to one result (the first result, i.e., latest price)</p></li></ol><p>To better understand this block of code, let&apos;s make some small adjustments to our query. (1) replace <strong>&quot;price&quot;</strong> with <strong>*</strong> (which returns all columns) and (2) select only the code from lines 2 to 5, then (3) run the selection:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cc3ee355ed328178d7429a18224106c811ed81ac9f4c64c95512965d66234e6e.png" alt="Running the previous query with a minor adjustment" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Running the previous query with a minor adjustment</figcaption></figure><p>In the query results you will see the full table consisting of five columns. First, let&apos;s check the contract address in Etherscan.io:</p><pre data-type="codeBlock" text="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
"><code></code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0cb50f4c9580386d1b9ee26836b11f7b18aab334efec3607259ee30ca8aaec4c.png" alt="WETH smart contract on Etherscan.io" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">WETH smart contract on Etherscan.io</figcaption></figure><p>This smart contract controls the WETH asset on the Ethereum blockchain. Great! Now we know the source of the table from our previous screenshot that shows the WETH price in USD.</p><p>Let&apos;s divert our attention back to the previous table:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/664095bef55338db5d357d82e4a6e88b02d80f6ce43eb60b70d168254a9ffe51.png" alt="Query results table our previous query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Query results table our previous query</figcaption></figure><p>In here we have a column called &quot;minute&quot; which tracks the ETH to USD value every minute. Since we limited the query to &quot;interval – &apos;1 hours&apos;&quot;, we only get the latest hour of data available. Since for our purposes we actually only need the latest data entry, limiting this query to the last hour speeds up the query significantly. You could also change this to &apos;1 days&apos;, &apos;3days&apos; or &apos;1 weeks&apos; for example, to get more historical data.</p><p>What&apos;s important here is that the columns name is &quot;minute&quot;, hence our query refers to the &quot;minute&quot; column, which is not to be mistaken for a time-related command.</p><p>Let&apos;s revert our code back to what we changed it to at the beginning of this section and run the query:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/51a57008051d6644f6c322a7ae92ed2c194beaffe31837302462475d0c145cf3.png" alt="Saving the query. @0xPhillan via https://dune.com/queries/883725" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Saving the query. @0xPhillan via https://dune.com/queries/883725</figcaption></figure><p>The result is the current USD of the ETH that has been transferred to the Pooly1, Pooly2 and Pooly3 smart contracts in exchange for Pooly NFTs.</p><p>For this we will be using a counter again, so scroll down and (1) click on the counter forked from our previous query, (2) adjust the data source and (3) change the labels.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/6d152a62d70270c71628dfce7c1dc4a97fcbf262f82b31b4fe06777d7b7cde3e.png" alt="Adjusting the counter visualization. @0xPhillan via https://dune.com/queries/883725" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adjusting the counter visualization. @0xPhillan via https://dune.com/queries/883725</figcaption></figure><p>Once finished, remember to save and add to our dashboard:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7fec4bb5462768565fbbbd4a441452ae5bf2a2087fe5f25ec618894660de4f1d.png" alt="Saving the query and adding the visualization to our previous dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Saving the query and adding the visualization to our previous dashboard</figcaption></figure><p>After it&apos;s added, it will look like the below screenshot. Don&apos;t worry, at the end of this guide we&apos;ll clean it up. For now, don&apos;t worry about the looks!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/597ad5a1f984827e668abacb0308192c20fc9c421ffd6192af0eaee96f00b494.png" alt="Dashboard with second query added" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dashboard with second query added</figcaption></figure><h3 id="h-query-2b-funds-raised-in-usd-at-eth-value-at-time-of-purchase" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 2b: Funds raised in USD at ETH Value at Time of Purchase</h3><p>This query will be a little more complex, as we will have to query two tables and combine the results. Specifically, we will have to get the individual transactions and convert the ETH value of each transaction using the price of ETH at the time of the transaction.</p><p>Again, let&apos;s first fork our previous query in preparation for our next query:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b50a88c742ca5cac23dfc72f218bf6181092c1efdc06f484772ce1eebfc091ca.png" alt="Forking the previous query. @0xPhillan via https://dune.com/queries/883725" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Forking the previous query. @0xPhillan via https://dune.com/queries/883725</figcaption></figure><p>From the forked code, we want to make the following:</p><pre data-type="codeBlock" text="with poolyTransactions as
(
select
    block_time,
    value/1e18 as value_eth

from ethereum.transactions

where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
)

select 
sum(value_eth * price)
from poolyTransactions tx

left join 
    (select minute, price from prices.usd 
              where symbol = &apos;WETH&apos; and minute &gt; &apos;2022-05-01&apos;) 
              as prices on date_trunc(&apos;minute&apos;, block_time) = minute
"><code>with poolyTransactions <span class="hljs-keyword">as</span>
(
select
    block_time,
    value<span class="hljs-operator">/</span><span class="hljs-number">1e18</span> <span class="hljs-keyword">as</span> value_eth

<span class="hljs-keyword">from</span> ethereum.transactions

where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
)

select 
sum(value_eth <span class="hljs-operator">*</span> price)
<span class="hljs-keyword">from</span> poolyTransactions <span class="hljs-built_in">tx</span>

left join 
    (select minute, price <span class="hljs-keyword">from</span> prices.usd 
              where symbol <span class="hljs-operator">=</span> <span class="hljs-string">'WETH'</span> and minute <span class="hljs-operator">></span> <span class="hljs-string">'2022-05-01'</span>) 
              <span class="hljs-keyword">as</span> prices on date_trunc(<span class="hljs-string">'minute'</span>, block_time) <span class="hljs-operator">=</span> minute
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8a328c74f66f237c6d1a698934d4bec4a566ca17ebce7c767b0820df4a5467d4.png" alt="Query using the ETH-USD exchange rate at the time when an NFT was purchased. @0xPhillan via https://dune.com/queries/884492" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Query using the ETH-USD exchange rate at the time when an NFT was purchased. @0xPhillan via https://dune.com/queries/884492</figcaption></figure><p>If we run this code here, we see that we receive a USD value of 1,4m USD. This is the result of</p><p>Let&apos;s break this code down into three sections:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/201b44afa3400ddb75f29eaf757e027654137f4e1ed7975cb631e111a1af8650.png" alt="Breakdown of query into three sections" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Breakdown of query into three sections</figcaption></figure><p><strong>Section 1</strong></p><p>Here we build the first table that we will reference. What we do here is create an auxiliary table that we call &quot;poolyTransactions&quot; that will hold block_time and value_eth (value in wei divided by 10^18 to convert to ETH, which we give a custom name) from the ethereum.transactions table. For this table, we filter the three Pooly addresses that we know of.</p><p>Here a line by line explanation:</p><ul><li><p>Line 1: <em>with poolyTransaction as</em> – define auxiliary table called &quot;poolyTransaction&quot; as having below properties</p></li><li><p>Line 3-11: select columns and filters to include on the ethereum.transcations table</p></li><li><p>Line 5: <em>value/1e18 as value_eth</em> – here we rename the column as &quot;value_eth&quot; so that we can reference it directly in section 2 instead of doing another calculation</p></li></ul><p><strong>Section 2</strong></p><p>This is where we create the output table. You&apos;ll notice that we are building a table from poolyTransactions, the auxiliary table we created in section 1, but we are also referencing a column called &quot;price&quot; that we didn&apos;t define yet. Price is in fact only defined later in line 19! This is made possible, because we are joining the poolyTransactions with certain outputs from the prices.usd table in section 3. So in essence, we are creating a table using our auxiliary table <em>poolyTransactions</em> as well as the table we built from prices.usd in the next section.</p><p><strong>Section 3</strong></p><p>This is where we define a table that we want to join with another table. The &quot;left join&quot; keyword allows us to do this:</p><ul><li><p>Line 18: <em>left join</em> – keyword used to indicate that we want to join our first table (left table) with another table (right table). That means, our first table defined in section 1 acts as the base table.</p></li><li><p>Line 19-20: here we define the table we want to create from prices.usd. In line 20 we limit the duration to &apos;2022-05-01&apos;, because the Pooly smart contracts were only deployed in the month of May, so we can significantly speed up the table query if we limit it to a smaller timeframe instead of parsing data all the way to Ethereum&apos;s genesis block.</p></li><li><p>Line 21: <em>as prices</em> – this names our table in lines 19-20 &quot;prices&quot; for easier future reference</p></li><li><p>Line 22: <em>on data_trunc(&apos;minute&apos;, block_time) = minute</em> – this is the line that combines our auxiliary table (section 1) with the prices table (section 3 lines 19-20). What it says here is to take column &quot;block_time&quot; from our auxiliary table, and truncate it to minutes only, i.e., remove all other data that is not minutes (e.g. seconds, milliseconds, etc.). The prices.usd table is already truncated to minutes, so there is no further conversion needed here. Then the minute column in prices.usd is matched to the minute column in our auxiliary table, and the correct price is thus allocated from the prices.usd to the corresponding minute timestamp in poolyTransactions.</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b41b1a63e05a9c7d09a249acae479de5026f29b7a195aa65b15a357009f9745f.png" alt="Viewing the minute column of the prices.usd table in the dataset explorer" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Viewing the minute column of the prices.usd table in the dataset explorer</figcaption></figure><p>To better visualize the third section, I have reorganized the parts to make it easier to understand:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/942df04de8d8eda32c56383642f6905388678d4f054ff53c165bf979c420733e.png" alt="Visualization of every step of the left join command" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Visualization of every step of the left join command</figcaption></figure><p>(1) We create the poolyTransactions table, then (2) we tell SQL to join it with another table, which (3) we define as minute and price columns from the prices.usd table. This prices.usd table we created is then (4) joined onto the left table poolyTransactions using the time in minutes as a mapping variable. To join tables, both tables must have entries which are exactly the same and if we truncate the block_time variable to minutes, we create matching minutes between both tables. By doing this, the (5) poolyTransactions table is updated to include the price column, with price values being matched to the respective dates.</p><p>From here, we simply query the joined poolyTransactions table and sum the result of multiplying the value_eth and price of ETH for each row.</p><p>Now add a counter, save and add to dashboard!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7b1b0945321f2b348f1b9fc272de5755a4004a3ef79404626f79f5bd044aca4c.png" alt="Adding a counter visualization to the query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adding a counter visualization to the query</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d098d546fdb185bca7d0e29e19fcdb2c9f17ad81ea8d2ee7723fd2da19a50de5.png" alt="Counter visualization settings and add to dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Counter visualization settings and add to dashboard</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/78fdec0389dfa08740d8d1b6c9ed0dd6fb6d20a9a1fc26955a0306213f56378f.png" alt="Counter visualization added to dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Counter visualization added to dashboard</figcaption></figure><h3 id="h-query-3-total-number-of-supporters" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 3: Total Number of Supporters</h3><p>For our next query, we want to count the unique addresses that purchased a Pooly NFT (i.e., total number of supports). That means that even if an address purchased multiple Poolys across all three Pooly types, they should only be counted once.</p><p>For this, let&apos;s first open our very first query, fork it, and remember to save it too.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1ce7c01311ade34fae55f1fabaa585118e8f68a40469262ab9736e270f41e3a2.png" alt="Forking the very first query. @0xPhillan via https://dune.com/queries/882266" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Forking the very first query. @0xPhillan via https://dune.com/queries/882266</figcaption></figure><p>Here we simply change the first line:</p><pre data-type="codeBlock" text="select COUNT(DISTINCT &quot;from&quot;) from ethereum.transactions
where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
"><code>select COUNT(DISTINCT <span class="hljs-string">"from"</span>) <span class="hljs-keyword">from</span> ethereum.transactions
where <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ebfaa2dfd8503df708503447839f840744658a7c5cbaf4d475ceeae6a449b770.png" alt="Unique Pooly supporters query. @0xPhillan via https://dune.com/queries/887079" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Unique Pooly supporters query. @0xPhillan via https://dune.com/queries/887079</figcaption></figure><p>The COUNT variable counts all transactions, and the DISTINCT keyword makes sure that every unique entry is only counted once. The result we get is 4660 unique supporters. If we compare that to the unique supporters on the Pooly website, we see they are very close:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/18502946b8488fa140225609df22179b97a38e97d6fb2865c0faf2798e9dc010.png" alt="Pooly real-time supporter figures. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly real-time supporter figures. Source: https://mint.pooltogether.com/</figcaption></figure><p>This shows that our query is correct, as there is a little lag between Dune&apos;s database refreshes and the latest blockchain state.</p><p>Finally, change the counter visualization and add to dashboard again.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a4b1499319edd951b1fa10c03c95fb02ff8c785bac44333fe8cf9778bb469622.png" alt="Adjust counter visualization settings and add to dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adjust counter visualization settings and add to dashboard</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/dcffc7cebcd8b87f4bcb6cd49b621bb63f625912daac0e9fa11355027d87ce00.png" alt="Counter added to dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Counter added to dashboard</figcaption></figure><h3 id="h-query-4a-leaderboard-using-the-erc721-abstraction" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 4a: Leaderboard using the erc721. Abstraction</h3><p>Next, let&apos;s build the leaderboard including addresses, number of NFTs purchased per address and total ETH spent in descending order.</p><p>Again, let&apos;s fork our previous query so that we avoid having to retype the filtered addresses. Remember to save this new query before proceeding.</p><p>Looking at the leaderboard, there are three pieces of information we need. First, the address of the purchaser, then the number of NFTs purchased, and finally, the amount of ETH spent on all NFTs purchased.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/696338bf49198461ae5fc03495ce5650c29d037fb6325c8f983fa5d7aa9199a7.png" alt="Pooly leaderboard columns. Source: https://mint.pooltogether.com/" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly leaderboard columns. Source: https://mint.pooltogether.com/</figcaption></figure><p>Here we are looking at the NFTs <em>purchased</em> not at the NFTs <em>held</em>. It is entirely possible that somebody purchased (minted) an NFT then moved it to a safe wallet or resold it at a later point. We are only interested in first-time purchases (mints).</p><p>We achieve this using below query:</p><pre data-type="codeBlock" text="with poolyTransactions as
(
select
    &quot;from&quot;,
    hash,
    value/1e18 as value_eth

from ethereum.transactions

where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
)

select 
&quot;from&quot;, nfts_purchased, value_eth
from poolyTransactions


left join 
    (Select evt_tx_hash, COUNT(&quot;tokenId&quot;) as nfts_purchased
        From erc721.&quot;ERC721_evt_Transfer&quot;
        Where (contract_address = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
        or contract_address = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
        or contract_address = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;)
        and &quot;from&quot; = &apos;\x0000000000000000000000000000000000000000&apos;
        group by 1)
        as nfts
        on evt_tx_hash = hash
ORDER BY 3 desc
"><code><span class="hljs-keyword">with</span> poolyTransactions <span class="hljs-keyword">as</span>
(
<span class="hljs-keyword">select</span>
    <span class="hljs-string">"from"</span>,
    hash,
    value/<span class="hljs-number">1e18</span> <span class="hljs-keyword">as</span> value_eth

<span class="hljs-keyword">from</span> ethereum.transactions

<span class="hljs-keyword">where</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
<span class="hljs-built_in">or</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
<span class="hljs-built_in">or</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
)

<span class="hljs-keyword">select</span> 
<span class="hljs-string">"from"</span>, nfts_purchased, value_eth
<span class="hljs-keyword">from</span> poolyTransactions


left <span class="hljs-keyword">join</span> 
    (<span class="hljs-keyword">Select</span> evt_tx_hash, COUNT(<span class="hljs-string">"tokenId"</span>) <span class="hljs-keyword">as</span> nfts_purchased
        <span class="hljs-keyword">From</span> erc721.<span class="hljs-string">"ERC721_evt_Transfer"</span>
        <span class="hljs-keyword">Where</span> (contract_address = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
        <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
        <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523')</span>
        <span class="hljs-built_in">and</span> <span class="hljs-string">"from"</span> = <span class="hljs-comment">'\x0000000000000000000000000000000000000000'</span>
        <span class="hljs-keyword">group</span> <span class="hljs-keyword">by</span> <span class="hljs-number">1</span>)
        <span class="hljs-keyword">as</span> nfts
        <span class="hljs-keyword">on</span> evt_tx_hash = hash
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-number">3</span> desc
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/13281b770d8706be010f36aaabe00a8f80e4ba5aa2b7b5856bc8912ef9551886.png" alt="Pooly Leaderboard table. @0xPhillan via https://dune.com/queries/887141" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly Leaderboard table. @0xPhillan via https://dune.com/queries/887141</figcaption></figure><p>You will notice that this heavily resembles the query in &quot;Funds raised in USD at ETH value at time of purchase&quot;, and that&apos;s because we are using the same methodology: we first gather the transaction data in our poolyTransactions table, then we left a second table on it with a common mapping value.</p><p>Here, for the second table we use the erc721.&quot;ERC721_evt_Transfer&quot; table, which is an abstraction that Dune maintains that tracks all NFT transfers on Ethereum. If we use the dataset explorer, type &quot;erc721.&quot; And scroll to &quot;ERC721_evt_Transfer&quot; we can see everything that is included in that specific table. We can also highlight only the commands for the second table and see what the output would be:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1f598b06e45cdaa054dcb5a35055946fb38b10c94d6bfcec6af4cb852dbeb683.png" alt="Running code selection of Leadership table query. @0xPhillan via https://dune.com/queries/887141" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Running code selection of Leadership table query. @0xPhillan via https://dune.com/queries/887141</figcaption></figure><p>Since we only want NFTs that were newly minted by the smart contract, we must specify the &quot;from&quot; address to be the null address. On Ethereum, all NFTs are minted from the null address. By counting the amount of &quot;tokenId&quot; for each transaction, we can count the total number of NFTs minted for each transaction.</p><p>You will also notice something peculiar about how the filters are defined. The first three filters are now enclosed in brackets, while the last filter is outside of the brackets.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/5802d7b2853dae0f32ae8694c82036cc740b7d08e61d994ebbe930a353a45684.png" alt="Evaluation if first three filter statements are enclosed by parentheses" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Evaluation if first three filter statements are enclosed by parentheses</figcaption></figure><p>The brackets determine the order in which the and/or filter commands are evaluated, just like when executing arithmetic commands in SQL. If we did not enclose the first three statements, the <em>and</em> condition would only apply to the last filter setting.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4bea36f18b4cc6058e662c54a0f98be2ac74184374a9004c8efc28e518f71287.png" alt="Evaluation if no parentheses are used" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Evaluation if no parentheses are used</figcaption></figure><p>Since we want the <em>from null address</em> filter to be applied to all results of the previous filters, we need to add the parentheses.</p><p>Finally, since we are using the &quot;COUNT&quot; command, we need to specify what column to count these on (i.e., what variable to roll-up the counts to). For this we use the &quot;group by&quot; command to say that we want to group the count of &quot;tokenId&quot; to the first column in our table, which is &quot;evt_tx_hash&quot;.</p><p>Earlier I mentioned that we need a common mapping value to map this second table to the transactions table. Here we use the transaction hash to map the number of NFTs purchased per transactions, to our poolyTransactions table where this time we also requested the transaction hash. So ultimately, we are mapping the transaction hash of our erc721.&quot;ERC721_evt_Transfer&quot; table (which we named &quot;nfts&quot;) to the transaction hashes of our poolyTransactions table, which only include transactions that were used to purchase poolys.</p><p>The output is a table that includes the purchasers address, the number of NFTs that purchased purchased in total, as well as the total value of ETH spent.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/690146ee6c964328d93f78716debada2ef4786127ad6f23fab1816e8f2c50a4e.png" alt="Running code selection of Leadership table query. @0xPhillan via https://dune.com/queries/887141" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Running code selection of Leadership table query. @0xPhillan via https://dune.com/queries/887141</figcaption></figure><p>Finally, we tell Dune to &quot;ORDER BY 3 desc&quot;, which means that the third column of our output table should be ordered in descending order:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/055123d8f223bf9fa9a713ba7c5ef4b002df55c0b65f1955d3b00336edbf6388.png" alt="Illustrating &quot;ORDER BY 3 desc&quot; command. @0xPhillan via https://dune.com/queries/887141" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Illustrating &quot;ORDER BY 3 desc&quot; command. @0xPhillan via https://dune.com/queries/887141</figcaption></figure><p>Awesome! Our leaderboard is complete. Let&apos;s compare it against the leaderboard on the Pooly NFT website:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f1dea9d369115d9c9f1561406386d2867f77dc2e96691c2d45f0131d333af099.png" alt="Comparing Dune query leaderboard to Pooly website leaderboard." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Comparing Dune query leaderboard to Pooly website leaderboard.</figcaption></figure><p>Not all figures tie, but from this list we can see that a few addresses, NFTs purchased and total ETH spent figures do tie. This is once again a sync timing issue between Dune and real-time blockchain data and nothing to worry about.</p><p>Remember to save your query and add it to the dashboard.</p><h3 id="h-query-4b-leaderboard-using-the-poolysupporter-decoded-table" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 4b: Leaderboard using the poolysupporter. Decoded Table</h3><p>Instead of using the erc721.&quot;ERC721_evt_Transfer&quot; table, we can also use the poolysupporter.&quot;PoolyNFT_call_mintNFT&quot; decoded table that the Dune team put together.</p><pre data-type="codeBlock" text="with poolyTransactions as
(
select
    &quot;from&quot;,
    hash,
    value/1e18 as value_eth

from ethereum.transactions

where &quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
)

select 
&quot;from&quot;, nfts_purchased, value_eth
from poolyTransactions


left join 
    (Select call_tx_hash, &quot;_numberOfTokens&quot; as nfts_purchased
        From poolysupporters.&quot;PoolyNFT_call_mintNFT&quot;
        where contract_address = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
        or contract_address = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
        or contract_address = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;
        )
        as nfts
        on call_tx_hash = hash

ORDER BY 3 desc
"><code><span class="hljs-keyword">with</span> poolyTransactions <span class="hljs-keyword">as</span>
(
<span class="hljs-keyword">select</span>
    <span class="hljs-string">"from"</span>,
    hash,
    value/<span class="hljs-number">1e18</span> <span class="hljs-keyword">as</span> value_eth

<span class="hljs-keyword">from</span> ethereum.transactions

<span class="hljs-keyword">where</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
<span class="hljs-built_in">or</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
<span class="hljs-built_in">or</span> <span class="hljs-string">"to"</span> = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
)

<span class="hljs-keyword">select</span> 
<span class="hljs-string">"from"</span>, nfts_purchased, value_eth
<span class="hljs-keyword">from</span> poolyTransactions


left <span class="hljs-keyword">join</span> 
    (<span class="hljs-keyword">Select</span> call_tx_hash, <span class="hljs-string">"_numberOfTokens"</span> <span class="hljs-keyword">as</span> nfts_purchased
        <span class="hljs-keyword">From</span> poolysupporters.<span class="hljs-string">"PoolyNFT_call_mintNFT"</span>
        <span class="hljs-keyword">where</span> contract_address = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
        <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
        <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>
        )
        <span class="hljs-keyword">as</span> nfts
        <span class="hljs-keyword">on</span> call_tx_hash = hash

<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-number">3</span> desc
</code></pre><p>The methodology is the same as above, except that with this table we can directly return all transaction hashes that called the mintNFT function, instead of using the null address to determine which transactions from the erc721. &quot;ERC721_evt_Transfer&quot; table are mint transactions.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/39ecfa1f6fd4cff6198439bee554567fb15cfca0373258c592e1d3a31c9adcf0.png" alt="Using poolysupporters. instead of erc721. @0xPhillan via https://dune.com/queries/887280" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Using poolysupporters. instead of erc721. @0xPhillan via https://dune.com/queries/887280</figcaption></figure><p>The poolysupporter dataset allows us to do more specific and detailed queries, as we can refer to specific contract calls.</p><p>Let&apos;s compare the results of our two tables to ensure nothing is amiss:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/829c5ca68a47de3b3c0e29bc0ed27dcc4c580e548725f0ebf4146915b949f0e0.png" alt="Comparison of query results using erc721. and poolysupporter. datasets" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Comparison of query results using erc721. and poolysupporter. datasets</figcaption></figure><p>Won&apos;t you look at that, the outputs are identical. Great!</p><p>Remember to save your query and add it to the dashboard.</p><h3 id="h-query-5-max-supply-and-remaining-supply-of-each-of-the-nft-sets" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 5: Max Supply and Remaining Supply of Each of the NFT sets</h3><p>In the alternative version of query 4 we used the poolysupporter function. You may have seen that when you search for pooly in the dataset explorer, you also see a function called &quot;PoolyNFT_call_maxNFT&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/66b3efb2a45f8886dd8b019113248597d1bbbb126b46b64bc0447e7a0eae389d.png" alt="The poolysupporters.PoolyNFT_call_maxNFT function" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">The poolysupporters.PoolyNFT_call_maxNFT function</figcaption></figure><p>You may conclude that you can use this function call to directly retrieve the maximum minted NFTs.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/389a926e615ec18cb4c2801d24e33e098960441a5b5a484a6439fb402b9a7129.png" alt="No query results using poolysupporters.PoolyNFT_call_maxNFT" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">No query results using poolysupporters.PoolyNFT_call_maxNFT</figcaption></figure><p>Unfortunately, that is not possible: this function is a &quot;read&quot; function and as a result, there is no on-chain record when this function is called. See Etherscan below:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/92d25e7d4c3cbe54fd7beab95b025ecfa4d97395f782420a10ea82ec6feb05fd.png" alt="maxNFT is a read function, it leaves no records on the blockchain" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">maxNFT is a read function, it leaves no records on the blockchain</figcaption></figure><p>The maxNFT variable is set when the deployer contract deploys the Pooly Supporter smart contracts, but unfortunately at time of writing, the deployer smart contract has not been decoded, so we can&apos;t get the max mint numbers from on-chain data – at least not without significant effort.</p><p>Instead, we&apos;ll have to manually slot in the maxNFT figures for each smart contract:</p><pre data-type="codeBlock" text="with poolyContracts as
(
Select  contract_address,
        COUNT(&quot;tokenId&quot;) as nfts_purchased
            From erc721.&quot;ERC721_evt_Transfer&quot;
            Where (contract_address = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
            or contract_address = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
            or contract_address = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;)
            and &quot;from&quot; = &apos;\x0000000000000000000000000000000000000000&apos;
            group by 1
)

select 
    CASE contract_address
        WHEN &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos; then &apos;Pooly_Supporter&apos;
        WHEN &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos; then &apos;Pooly_Lawyer&apos;
        WHEN &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos; then &apos;Pooly_Judge&apos;
        END as NFT_name, 
    nfts_purchased, 
    CASE maxNFT_Supply
        WHEN &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos; then 10000
        WHEN &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos; then 100
        WHEN &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos; then 10
        END as NFT_Supply,
    CASE maxNFT_Supply
        WHEN &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos; then 100-(nfts_purchased/10000.0*100)
        WHEN &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos; then 100-(nfts_purchased/1000.0*100)
        WHEN &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos; then 100-(nfts_purchased/10.0*100)
        END as percent_supply_remaining
from poolyContracts

left join
    (
    Select  contract_address as maxNFT_Supply
            From erc721.&quot;ERC721_evt_Transfer&quot;
            Where (contract_address = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
            or contract_address = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
            or contract_address = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;)
            and &quot;from&quot; = &apos;\x0000000000000000000000000000000000000000&apos;
            group by 1
    )
    as maxNFT
    on maxNFT_Supply = contract_address
    
ORDER BY 3 desc
"><code><span class="hljs-keyword">with</span> poolyContracts <span class="hljs-keyword">as</span>
(
<span class="hljs-keyword">Select</span>  contract_address,
        COUNT(<span class="hljs-string">"tokenId"</span>) <span class="hljs-keyword">as</span> nfts_purchased
            <span class="hljs-keyword">From</span> erc721.<span class="hljs-string">"ERC721_evt_Transfer"</span>
            <span class="hljs-keyword">Where</span> (contract_address = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
            <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
            <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523')</span>
            <span class="hljs-built_in">and</span> <span class="hljs-string">"from"</span> = <span class="hljs-comment">'\x0000000000000000000000000000000000000000'</span>
            <span class="hljs-keyword">group</span> <span class="hljs-keyword">by</span> <span class="hljs-number">1</span>
)

<span class="hljs-keyword">select</span> 
    <span class="hljs-keyword">CASE</span> contract_address
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed' then 'Pooly_Supporter'</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9' then 'Pooly_Lawyer'</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523' then 'Pooly_Judge'</span>
        <span class="hljs-keyword">END</span> <span class="hljs-keyword">as</span> NFT_name, 
    nfts_purchased, 
    <span class="hljs-keyword">CASE</span> maxNFT_Supply
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed' then 10000</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9' then 100</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523' then 10</span>
        <span class="hljs-keyword">END</span> <span class="hljs-keyword">as</span> NFT_Supply,
    <span class="hljs-keyword">CASE</span> maxNFT_Supply
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed' then 100-(nfts_purchased/10000.0*100)</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9' then 100-(nfts_purchased/1000.0*100)</span>
        <span class="hljs-keyword">WHEN</span> <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523' then 100-(nfts_purchased/10.0*100)</span>
        <span class="hljs-keyword">END</span> <span class="hljs-keyword">as</span> percent_supply_remaining
<span class="hljs-keyword">from</span> poolyContracts

left <span class="hljs-keyword">join</span>
    (
    <span class="hljs-keyword">Select</span>  contract_address <span class="hljs-keyword">as</span> maxNFT_Supply
            <span class="hljs-keyword">From</span> erc721.<span class="hljs-string">"ERC721_evt_Transfer"</span>
            <span class="hljs-keyword">Where</span> (contract_address = <span class="hljs-comment">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
            <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
            <span class="hljs-built_in">or</span> contract_address = <span class="hljs-comment">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523')</span>
            <span class="hljs-built_in">and</span> <span class="hljs-string">"from"</span> = <span class="hljs-comment">'\x0000000000000000000000000000000000000000'</span>
            <span class="hljs-keyword">group</span> <span class="hljs-keyword">by</span> <span class="hljs-number">1</span>
    )
    <span class="hljs-keyword">as</span> maxNFT
    <span class="hljs-keyword">on</span> maxNFT_Supply = contract_address
    
<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-number">3</span> desc
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/92dafe9f4f9f49b3d82c78308f1282bd5a0ca6fffa0e9dd52537c62a94913ca4.png" alt="Pooly NFT supply query. 0xPhillan via https://dune.com/queries/887355" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Pooly NFT supply query. 0xPhillan via https://dune.com/queries/887355</figcaption></figure><p>Here is where I had to be a little creative. Manually adding numbers to specific table entries in SQL is a difficult undertaking, and I had to apply some tricks to get this to leave a table that is easily readable.</p><p>Here again, we will use left join to combine two tables, but we will also used CASE WHEN statements on three of four columns to output specific information that we want to show. What we will do is first create our base table, then create a second table, and <em>left join</em> the second table with the first table and transform the table inputs to make them human-readable as well as do some simple arithmetic for us.</p><p>The reason for the second table is that within a single query SQL does not let you call a column twice. We, in fact, need to call one column multiple times and transform each column call separately. A joined table however, allows us to call columns from the second table multiple times, thus enabling us to create the outputs we need for the specific rows in the column that we need.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4f7cbccf0b0eba916f50f50f705aea5f91048ef31a6957541213d5d70ef9f725.png" alt="Breakdown of above query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Breakdown of above query</figcaption></figure><p>Let&apos;s break this query down into four sections for easier digestion.</p><p><em>TAKE NOTE OF THE SECTION ORDER! 1, 3, 2, 4!</em></p><p><strong>Section 1</strong></p><p>In this section we define a table called &quot;poolyContracts&quot; in which we count all individual tokenIds that originated from the null address from the three Pooly contract addresses, thus including only minted NFTs by using the erc721.&quot;ERC721_evt_Transfer&quot; table. We then group these by the first column, thus returning minted NFTs per pooly smart contract.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/56214dd15d0e661e508c3c7e2ac245d63b0c176992c6b49b4782a692fd3fad24.png" alt="The poolyContracts table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">The poolyContracts table</figcaption></figure><p><strong>Section 2</strong></p><p>In this code block we force the query to only show one of each of the three contract addresses. We do this by using the &quot;group by 1&quot; command, i.e., group the results by unique entries of the first column.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/10469179dafeb0b9f8b2fbd0bd3e03254b6ff339315916de61351ca17fae78ef.png" alt="Second table returning 1 of each contract address with the &quot;group by 1&quot; command" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Second table returning 1 of each contract address with the &quot;group by 1&quot; command</figcaption></figure><p>Without the group by command the query would return all transfer events in relation to these contract addresses, but we only need each to appear once. You&apos;ll see why in the next section.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0ba950545d9e70842f89e4757e80674c9db933d1cae9c368e2f6bf96654ea7ef.png" alt="Second table returning a long list of contract address without the &quot;group by 1&quot; command" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Second table returning a long list of contract address without the &quot;group by 1&quot; command</figcaption></figure><p>Furthermore, we rename the <em>contract_address</em> column to <em>maxNFT_Supply</em> so that we can define which column to join this table onto the poolyContracts table with.</p><p><strong>Section 3</strong></p><p>This is where the magic happens.</p><p>In this section we can now call columns from our joined table. We call:</p><ol><li><p><em>contract_address</em></p></li><li><p><em>nfts_purchased</em></p></li><li><p><em>maxNFT_Supply</em></p></li><li><p><em>maxNFT_Supply</em></p></li></ol><p>You&apos;ll notice that we are essentially retrieving the same data three times with columns 1, 3 and 4, and that columns 3 and 4 are even the same identical column! This is possible because we joined two tables. If you were to call contract_address twice before the tables were joined, the query editor would return an error message.</p><p>Next you will also notice that columns 1, 3 and 4 each have a <em>CASE WHEN</em> clause embedded. Because each of the two previous tables that we created only have one unique line for each smart contract, we cannot use a <em>CASE WHEN</em> statement to specify if a specific smart contract address appears (one of three options), return something else in its place.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f15ccf0deb93fdc295bc1ce29429ef9be9df0cc991c51966c988ec5fd46971f2.png" alt="Full table without ordering the results by nft_supply" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Full table without ordering the results by nft_supply</figcaption></figure><p>You&apos;ll see here for the first column we tell the query editor to replace each smart contract address with the name of the respective NFT!</p><p>In the third column we replace it with the known max NFT quantities listed on the Pooly website.</p><p>And in the fourth column we use a formula to calculate percent of remaining NFT supply. In these statements at least one of the numbers used in the arithmetic operation needs to include one decimal. If this is not included, the SQL query will be interpreted as wanting to return integers, meaning that we will not get any decimals for these calculations. By including “<em>.0”</em> we signify to the server that we want this calculation to return a decimal number.</p><p><strong>Section 4</strong></p><p>And finally, we indicate that we want the output to be ordered in descending order (largest to smallest) by the third column.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c6ee274b1d2cc6ecb4893cc844861dc416682b0f572aad8de2b242ac25ed951b.png" alt="Full table after ordering by nft_supply in descending order" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Full table after ordering by nft_supply in descending order</figcaption></figure><p>This table is done as well. Save your query, make any changes you need to make to the table and add it to your dashboard.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/9fea756f104126411a7e415be7cca6727371586c8f7a0b9dfd801080bc529fbb.png" alt="Adding the table to the dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Adding the table to the dashboard</figcaption></figure><h3 id="h-query-6-timeseries-chart-of-eth-raised-over-time" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Query 6: Timeseries Chart of ETH Raised Over Time</h3><p>In our final query, we will create a timeseries chart of the amount of ETH raised through NFT sales over time.</p><pre data-type="codeBlock" text="select 
    block_time as time,
    sum(value/1e18) over (order by date_trunc(&apos;minute&apos;, block_time) asc) as cumu_value_eth
from ethereum.transactions

where (&quot;to&quot; = &apos;\x90B3832e2F2aDe2FE382a911805B6933C056D6ed&apos;
or &quot;to&quot; = &apos;\x3545192b340F50d77403DC0A64cf2b32F03d00A9&apos;
or &quot;to&quot; = &apos;\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523&apos;)
and date_trunc(&apos;day&apos;, block_time) &lt; &apos;2022-06-25’
"><code>select 
    block_time <span class="hljs-keyword">as</span> time,
    sum(value<span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) over (order by date_trunc(<span class="hljs-string">'minute'</span>, block_time) asc) <span class="hljs-keyword">as</span> cumu_value_eth
<span class="hljs-keyword">from</span> ethereum.transactions

where (<span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x90B3832e2F2aDe2FE382a911805B6933C056D6ed'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x3545192b340F50d77403DC0A64cf2b32F03d00A9'</span>
or <span class="hljs-string">"to"</span> <span class="hljs-operator">=</span> <span class="hljs-string">'\x5663e3E096f1743e77B8F71b5DE0CF9Dfd058523'</span>)
and date_trunc(<span class="hljs-string">'day'</span>, block_time) <span class="hljs-operator">&#x3C;</span> <span class="hljs-string">'2022-06-25’
</span></code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/59ad5d3a59b2dc7d5768287543e19c5f12471daed5991032de75890f60989718.png" alt="Cumulative NFT sales in ETH over time. 0xPhillan via https://dune.com/queries/887727" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Cumulative NFT sales in ETH over time. 0xPhillan via https://dune.com/queries/887727</figcaption></figure><p>This is a shorter piece of code, however it includes the <em>over</em> command, which is an important command for aggregating cumulative values.</p><p>In this query we first select block_time, then we sum the ETH value (which is <em>value/1e18</em>) over the block_time in minute intervals, which we directly sort in ascending order, and name the column <em>cumu_value_eth</em>.</p><pre data-type="codeBlock" text="sum(value/1e18) over (order by date_trunc(&apos;minute&apos;, block_time) asc) as cumu_value_eth
"><code><span class="hljs-built_in">sum</span>(<span class="hljs-keyword">value</span><span class="hljs-operator">/</span><span class="hljs-number">1e18</span>) <span class="hljs-keyword">over</span> (<span class="hljs-keyword">order</span> <span class="hljs-keyword">by</span> date_trunc(<span class="hljs-string">'minute'</span>, block_time) <span class="hljs-keyword">asc</span>) <span class="hljs-keyword">as</span> cumu_value_eth
</code></pre><p>Furthermore, we&apos;ve added another filter to the end, which states that for this query blocktime should not exceed 2022-06-25, which is roughly when the fundraising campaign ends according to the Pooly website. This way our area chart will only display data of the campaign, instead of adding a flat line that will drag into eternity as time goes by.</p><p>To create the area chart, (1) click on &quot;New visualization&quot;, then in the (2) dropdown menu select &quot;Area chart&quot; and finally (3) click &quot;Add visualization&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/66488681c0a69af8549c258135aa0985c265b178b0ef7279fd51c93ef1e7207b.png" alt="Creating an Area chart visualization" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Creating an Area chart visualization</figcaption></figure><p>Your area chart should appear automatically with relevant settings pre-selected by Dune.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0486b9ee659ddfc36c4d5a5447eac5c8c90044b990cc6ee6804112f5dda19475.png" alt="Area chart visualization settings and add to dashboard" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Area chart visualization settings and add to dashboard</figcaption></figure><p>If they aren&apos;t pre-selected, you can play with the settings below the chart until it looks right.</p><p>Finally, save your query and press &quot;Add to dashboard&quot; once more.</p><p><strong>Part 3: Cleaning up the Dashboard</strong></p><p>We built a lot of queries, and directly added these to our dashboard. Well, let&apos;s take a look at how it looks like. Just click on the dashboard name after adding the last chart to your dashboard.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c760d1c62801207080dffa3362fa1ba6a07e0cc7ead7e5a1a4aca725fa431e40.png" alt="After the visualization is added, click the name of the dashboard to open it" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">After the visualization is added, click the name of the dashboard to open it</figcaption></figure><p>And, let&apos;s see…</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7705175ebbf297438a7dd7ae78da833f086a750538a76334d3d49f5f070bf14d.png" alt="Dashboard before clean up" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Dashboard before clean up</figcaption></figure><p>Yikes! That definitely needs to be cleaned up before it&apos;s presentable.</p><p>In the top right of your dashboard screen, click &quot;Edit&quot; to start editing.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/9a2823f3b8c54eade0058b564b794d4c5d8cbaa9b81f109b92d4ebfd366be804.png" alt="Click the edit button in the top right to edit the dashboard format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click the edit button in the top right to edit the dashboard format</figcaption></figure><p>From here, you can drag and drop the individual elements on a grid that is displayed by a red box in the background while you move elements around, and you can resize each element by dragging the icon in the bottom left corner. Simple!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/562b16ab0f7ffdbb7207b944a2a124ab82f5b20552dba9b560e57e80111c462b.png" alt="Visualizations and other elements support drag &amp; drop and drap to resize" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Visualizations and other elements support drag &amp; drop and drap to resize</figcaption></figure><p>To add text and images to your dashboard, press &quot;Add text widget&quot; in the top right of the dashboard edit screen.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/002469645da9067e79d12944895b0569fcfb1fbbce6e66993254e83c0d82259d.png" alt="Click &quot;Add text widget&quot; to add a text widget" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click &quot;Add text widget&quot; to add a text widget</figcaption></figure><p>While cleaning up you might notice that these two queries look the same and having both doesn’t really provide any valuable info…:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0d8cd097bfd706daba7eb3ccf960d58febd92c2af10db2060b01655777c1352a.png" alt="Two counters showing different approaches to calculating USD value of ETH" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Two counters showing different approaches to calculating USD value of ETH</figcaption></figure><p>Because we don&apos;t know when or how PoolTogether is withdrawing the ETH in the smart contract, we can just stick to how the Pooly website does it. We&apos;ll remove the right one and replace it with another query.</p><p>Here we go, the final dashboard:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/002b1b3fb43f5cdb97f33abf2d217a62ce8500a1b21cbe2415aa89043bc9849b.png" alt="The final dashboard. @0xPhillan via https://dune.com/phillan/pooly-nft-by-0xphillan" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">The final dashboard. @0xPhillan via https://dune.com/phillan/pooly-nft-by-0xphillan</figcaption></figure><p>That looks much nicer than before, and it also follows the same format of the Pooly website!</p><h2 id="h-closing" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Closing</h2><p>Dune Analytics is a strong platform that can provide deep blockchain data capabilities in the right hands. I hope with this piece I was able to teach you the basics. From here, it’s up to you to take on bigger challenges and make even better dashboards. Please share your dashboards with me - I’m excited to see what you build!</p><p><strong>If you enjoyed this piece, please consider following me on Twitter </strong><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xPhillan"><strong>@0xPhillan</strong></a><strong>!</strong></p><p>Don’t hesitate to reach out if you have any questions about Dune Analytics or ideas for future guides.</p><p><em>Special thanks to </em><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/superamscom"><em>@superamscom</em></a><em> for reviewing my code and informing me of a bug that has now been fixed!</em></p>]]></content:encoded>
            <author>phillan@newsletter.paragraph.com (0xPhillan)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/9f824ba368fa09f256736471dbe2deda1cbc25e2bed2ece36cd1279cb899228d.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Use Excel to Fetch Crypto Market Data with API Queries]]></title>
            <link>https://paragraph.com/@phillan/use-excel-to-fetch-crypto-market-data-with-api-queries</link>
            <guid>JU6nBNbIu1l84opZIBBb</guid>
            <pubDate>Sun, 29 May 2022 13:09:50 GMT</pubDate>
            <description><![CDATA[Follow me on Twitter: @0xPhillan In this piece I will teach you how to use Microsoft Excel to connect to APIs of blockchain data aggregation services to pull aggregate price, market cap, trade volume and TVL data. The skills learned here are transferable to any public API – be creative and show me what you make with it! We will cover three APIs that will teach you the basics of using Excel Power Query for API calls:CoinGecko API*: basic Power Query API call*CoinMarketCap API*: basic Power Que...]]></description>
            <content:encoded><![CDATA[<p>Follow me on Twitter: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xPhillan">@0xPhillan</a></p><p><em>In this piece I will teach you how to use Microsoft Excel to connect to APIs of blockchain data aggregation services to pull aggregate price, market cap, trade volume and TVL data. The skills learned here are transferable to any public API – be creative and show me what you make with it!</em></p><p><em>We will cover three APIs that will teach you the basics of using Excel Power Query for API calls:</em></p><ul><li><p><strong><em>CoinGecko API</em></strong>*: basic Power Query API call*</p></li><li><p><strong><em>CoinMarketCap API</em></strong>*: basic Power Query API call with a personal API key*</p></li><li><p><strong><em>DeFi Llama API</em></strong>*: advanced Power Query API call with parameters and data transformation in Power Query*</p></li></ul><h1 id="h-contents" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Contents</h1><ul><li><p>Part 1 Introduction</p></li><li><p>Part 2: Getting API Access</p></li><li><p>Part 3 CoinGecko – API &amp; Querying in Excel</p><ul><li><p>Part 3.1 CoinGecko – Finding the API Link</p></li><li><p>Part 3.2 Using Excel to Query the CoinGecko API</p></li><li><p>Part 3.3 Transforming the retrieved CoinGecko data</p></li></ul></li><li><p>Part 4: CoinMarketCap – API &amp; Querying in Excel</p><ul><li><p>Part 4.1 CoinMarketCap – Finding the API Link</p></li><li><p>Part 4.2 Using Excel to Query the CoinMarketCap API</p></li><li><p>Part 4.3 Transforming the retrieved CoinMarketCap data</p></li></ul></li><li><p>Part 5 DeFi Llama – API &amp; Querying in Excel</p><ul><li><p>Part 5.1 DeFi Llama – Finding the API Link</p></li><li><p>Part 5.2 Using Excel to Query the DeFi Llama API – /protocols</p></li><li><p>Part 5.3 Transforming the retrieved DeFi Llama data – /protocols</p></li><li><p>Part 5.4 Using Excel to Query the DeFi Llama API - /protocol/{protocol}</p></li><li><p>Part 5.5 Transforming the retrieved DeFi Llama data – /protocol/{protocol}</p></li></ul></li><li><p>Part 6 Other Notes</p><ul><li><p>Part 6.1 Refreshing Data</p></li><li><p>Part 6.2 Important note on API call URLs</p></li></ul></li><li><p>Closing thoughts</p></li></ul><h1 id="h-part-1-introduction" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 1 Introduction</h1><p>When we look at the blockchain data that is available today, we can see massive amount of data in various forms from various sources at various levels of granularity. We can find data on prices, market caps, TVL, NFT sales and even aggregations of specific smart contract interactions – all the data is public, and the volume of data available is incomprehensible.</p><p>While having more granular data means you can do deeper analyses, you also face the challenge of having to transform the data into a human-readable format. This is an extremely challenging task, but thankfully we have data aggregation services that do the heavy lifting for us.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/300d408698b74f0b98ffdbcd51350718c3725af1d041f6a86f11060519ad63ac.png" alt="Various levels of blockchain data publicly available" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Various levels of blockchain data publicly available</figcaption></figure><p>From above illustration you may feel that with aggregate data at token or smart contract level you will miss the big picture, but the truth is quite the opposite: with aggregate data you get to see the big picture and visualize trends without being distracted by every detail. If you start your data analysis journey with on-chain data, you&apos;ll miss the forest for the trees!</p><p><strong>So for today, let&apos;s see how we can use the CoinGecko API, CoinMarketCap API and DeFi Llama API to fetch aggregate token and TVL data.</strong></p><h1 id="h-part-2-getting-api-access" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 2 Getting API Access</h1><p>Before we get started, we need to make sure we have API access. Some APIs are accessible publicly, while others require sign-up and a personal API key. Today we will use below three public APIs:</p><ul><li><p>CoinGecko (free, no sign-up required | optional paid plans)</p></li><li><p>CoinMarketCap (free, <strong>sign-up required</strong> | optional paid plans)</p></li><li><p>DeFi Llama (free, no sign-up required)</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ecdba868305f155270267142b50e9792dd2c00e1965bdda93ffba4fcc0ef85f4.png" alt="Table of popular aggregated blockchain data APIs as of May 28th, 2022" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Table of popular aggregated blockchain data APIs as of May 28th, 2022</figcaption></figure><p>CoinGecko and CoinMarketCap have mostly the same data available, however we will be using both APIs to demonstrate how to use Excel to pass your API key details when querying an API which requires you to register for an account.</p><p>Whenever working with any API, the API documentation is an extremely valuable document that explains <strong>what data</strong> can be accessed through <strong>which API calls</strong>. Below are the latest links to the API docs for our three data sources:</p><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.coingecko.com/en/api/documentation">https://www.coingecko.com/en/api/documentation</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://coinmarketcap.com/api/documentation/v1/">https://coinmarketcap.com/api/documentation/v1/</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://defillama.com/docs/api">https://defillama.com/docs/api</a></p></li></ul><p>Since CoinGecko and DeFi Llama APIs are free, we only need to sign up for CoinMarketCap. In below link click the &quot;Get Your API Key Now&quot; button, follow the steps on-screen to get access to your API key:</p><div data-type="embedly" src="https://coinmarketcap.com/api/" data="{&quot;provider_url&quot;:&quot;https://coinmarketcap.com&quot;,&quot;description&quot;:&quot;Use CoinMarketCap&apos;s crypto API to get the best, most accurate real-time, historical cryptocurrency, DEX and exchange trade data for Bitcoin, Ethereum and more.&quot;,&quot;title&quot;:&quot;The World&apos;s Number 1 Cryptocurrency Market Data API&quot;,&quot;mean_alpha&quot;:34.8388888889,&quot;author_name&quot;:&quot;CoinMarketCap&quot;,&quot;url&quot;:&quot;https://coinmarketcap.com/api/&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/93a5ac9445d714bb8522feb0537bfb60c54b2e1f8fcbc5d53ed9f57b5d908b12.png&quot;,&quot;thumbnail_width&quot;:90,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;coinmarketcap.com&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:90,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:90,&quot;height&quot;:90,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/93a5ac9445d714bb8522feb0537bfb60c54b2e1f8fcbc5d53ed9f57b5d908b12.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/93a5ac9445d714bb8522feb0537bfb60c54b2e1f8fcbc5d53ed9f57b5d908b12.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://coinmarketcap.com/api/" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>The World&#x27;s Number 1 Cryptocurrency Market Data API</h2><p>Use CoinMarketCap&#x27;s crypto API to get the best, most accurate real-time, historical cryptocurrency, DEX and exchange trade data for Bitcoin, Ethereum and more.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://coinmarketcap.com</span></div><img src="https://storage.googleapis.com/papyrus_images/93a5ac9445d714bb8522feb0537bfb60c54b2e1f8fcbc5d53ed9f57b5d908b12.png"/></div></a></div></div><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f953f4e39eb1477389bbaf808bc426d73f029c189c1e0509fc69463fce218e8a.png" alt="CoinMarketCap API sign-up process" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinMarketCap API sign-up process</figcaption></figure><p>Once you have completed the process, you can view and copy your API key by hovering over the &quot;API Key&quot; box in the CoinMarketCap developer backend. Your CoinMarketCap API key should look something like this:</p><pre data-type="codeBlock" text="8d441bdd-dccf-5a50-ac45-8a880cc52c1a
"><code>8d441bdd<span class="hljs-operator">-</span>dccf<span class="hljs-operator">-</span>5a50<span class="hljs-operator">-</span>ac45<span class="hljs-operator">-</span>8a880cc52c1a
</code></pre><p><em>Note: This API key will</em> <em>not work</em> <em>and is for illustration purposes only. You</em> <em>must</em> <em>apply for a personal API key if you want to use the CoinMarketCap API.</em></p><h1 id="h-part-3-coingecko-api-and-querying-in-excel" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 3 CoinGecko – API &amp; Querying in Excel</h1><p>We will start off with CoinGecko since it is the easiest API to use.</p><p>Every API will have a special link you need to use initiate an API query. In below section we will first look at how to read API documentations to find the right links, before moving on to Excel and Power Query to fetch and transform the data. Some APIs provide you with the API link directly, while others require you to look around a little bit.</p><h2 id="h-part-31-coingecko-finding-the-api-link" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 3.1 CoinGecko – Finding the API Link</h2><p>First let&apos;s open the API documentation again:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.coingecko.com/en/api/documentation">https://www.coingecko.com/en/api/documentation</a></p><p>If you scroll down should see something like this:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2d6d68e7512be9f9ac910d9c167f08fea29ebe53bd3e68e3f0a792cad767faa5.png" alt="CoinGecko&apos;s API documentation" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinGecko&apos;s API documentation</figcaption></figure><p>CoinGecko does not directly share the API link with you, however we can easily find it by searching through their API commands. If you expand the GET ribbon under &quot;ping&quot;, you will see an option to try out the ping command.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/dcc6e0e7cc839c127920ee18951b42362112f88cb8d6e9b160f691539993a1e2.png" alt="CoinGecko /ping API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinGecko /ping API endpoint</figcaption></figure><p>If you click &quot;Try it out&quot; and then &quot;execute&quot; you should see the following:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/36ef24df37b875cdac81a58b064d82525d8aa1cbc3bc5368ef7ebed18785922e.png" alt="Results of CoinGecko /ping API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Results of CoinGecko /ping API call</figcaption></figure><p>Here we can see the following important information:</p><ul><li><p><strong>Request URL</strong>: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.coingecko.com/api/v3/ping">https://api.coingecko.com/api/v3/ping</a> – the link used to initiate the API call</p></li><li><p><strong>Server Response</strong>:</p><ul><li><p><strong>Response code</strong>: 200 – a code which signifies the server response was successful</p></li><li><p><strong>Response body</strong>: &quot;gecko_says&quot;: &quot;(V3) To the Moon!&quot; – the API query response</p></li></ul></li></ul><p>When you execute an API query call, all of the call parameters are included in the request URL. Or phrased differently: based on what is included in the link, the API knows which data or information to return. You can test this by pasting the request URL in your browser and you will receive the same response:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/84a2c2f5eb0578f0eea9da69bbc918624095ff09d3b024fc6854f9e082f01e53.png" alt="Executing an API call in your browser" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Executing an API call in your browser</figcaption></figure><p>Let&apos;s do another API call, but this time using the /coins/markets call under the <strong>coins</strong> section. This will &quot;List all supported coins price, market cap, volume, and market related data&quot;. Once you click &quot;Try it out&quot;, you will see a long list of parameter names and input fields in which we can specify our query parameters.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/6c93cc9966ff4dfb763c0fd130c47f343fae9637460b2cd91bc494f710cb4a1c.png" alt="CoinGecko /coins/markets API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinGecko /coins/markets API call</figcaption></figure><p>Apart from the field marked &quot;required&quot; which we must fill out (I put &quot;usd&quot;), we can leave the other fields as per default. Click the &quot;Execute&quot; button and wait for the API call. Once completed, you will see the below:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e850a91281e4acd9f0d15cc336bb47db18e24432e4444ce5951d4f460b639667.png" alt="CoinGecko /coins/markets API call server response" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinGecko /coins/markets API call server response</figcaption></figure><p>In the response body we can now see a huge JSON response with a lot of data about the cryptocurrencies CoinGecko tracks. Awesome!</p><p>Next let&apos;s see how we can run this API call in Excel and pull the data into Excel.</p><h2 id="h-part-32-using-excel-to-query-the-coingecko-api" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 3.2 Using Excel to Query the CoinGecko API</h2><p>From the server response from the previous step copy the request URL:</p><pre data-type="codeBlock" text="https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&amp;order=market_cap_desc&amp;per_page=100&amp;page=1&amp;sparkline=false
"><code>https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&#x26;order=market_cap_desc&#x26;per_page=100&#x26;page=1&#x26;sparkline=<span class="hljs-literal">false</span>
</code></pre><p>Then open a fresh instance of Excel and navigate to the data tab (1). Within the Data tab under “Get &amp; Transform Data”, click on “From Web” (2):</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/61e44aa8938444950566caf68af798261304000d12293fb14636afd94d736388.png" alt="Click &quot;Data &gt; From Web&quot; in a fresh instance of Excel" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click &quot;Data &gt; From Web&quot; in a fresh instance of Excel</figcaption></figure><p>Once you do this, the following pop-up window will appear. Paste the request URL into the box (1) and press &quot;OK&quot; (2):</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/740ee2c169d84de4e54c10526b8d5bc74bf0ed497e77f854aab0948aacc75508.png" alt="Excel&apos;s basic API query &quot;From Web&quot; settings screen" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s basic API query &quot;From Web&quot; settings screen</figcaption></figure><p>If this is your first time connecting to the CoinGecko API, you will see a window like the below. Simply press connect.</p><p><em>Note: In below window I first connected to the ping API call, your link will be to /coins/markets.</em></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/eff3d46ff8ffc1fa324117a77ccd9b9e0553d4cc38f33c931bc5173c5b05fab5.png" alt="Excel&apos;s anonymous access settings" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s anonymous access settings</figcaption></figure><p>You should see below screen as it connects.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1de201a3b29390558df3e1b6e27b4ee3c7753cc67c61e94c756206c8912829cc.png" alt="Excel attempting the API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel attempting the API call</figcaption></figure><h2 id="h-part-33-transforming-the-retrieved-coingecko-data" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 3.3 Transforming the retrieved CoinGecko data</h2><p>Followed by the Excel Power Query editor automatically popping up, as seen below. The Power Query editor lets you further apply data transformations to your query.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8740cd59bc652fac1b9f7b3bc6548e3f0545f28f3f3beebf4635049932ca8d36.png" alt="Data is pulled into Excel Power Query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Data is pulled into Excel Power Query</figcaption></figure><p>The Power Query editor follows Excel&apos;s general design language with a top ribbon with commands, and settings to the side.</p><p>First, let us rename our Query to something more readable and then let us convert the JSON response we received from CoinGecko into a Table:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b899e5272ebe7f4122d48e5ab5d24da444b10f543e1742dfb0e3c1e58c71ed62.png" alt="Change Name of Query and convert data to table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Change Name of Query and convert data to table</figcaption></figure><p>You will see below pop-up; press OK to proceed.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d7e7a3a1465f86c3399db9cd8a8c9c2bda8743a72124ac25544ea017389f1265.png" alt="&quot;To Table&quot; pop-up window delimiter options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">&quot;To Table&quot; pop-up window delimiter options</figcaption></figure><p>Once you press OK, the Power Query editor will refresh and you will see a few changes applied to it. First, the header ribbon becomes activated and the &quot;List Tools &amp; Transform&quot; ribbon disappears (1). Then, your raw JSON data has now been transformed into a Power Query table. This is added to the &quot;Applied Steps&quot; list on the right side (2) and can be reviewed in the formula bar above the list entries (3). Finally, although the data has been turned into a table, it still doesn&apos;t give us any valuable information. Currently Excel is showing you the highest level of data from the JSON response, which is just a list of records (4). We need to go one level deeper to see the data, and to do this we need to expand the records of Column1.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3309ddedf4369ab7d28a7f952425de6a3bf729349deacce7bc013ffac5ea99f4.png" alt="More Power Query options unlock once data is converted to table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">More Power Query options unlock once data is converted to table</figcaption></figure><p>To expand Column1, click on the two outward facing arrows (1) which will open a sub-menu with all the column headers of data available at the next level of depth. Simply press OK (2) to expand the column and refresh the table.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/22c2100172aae369f3a0a04422e1d3e2937d0a1aef3984135daac3a4a3cbf793.png" alt="Preview of what data is included in all the &quot;Records&quot;. Press OK to expand." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Preview of what data is included in all the &quot;Records&quot;. Press OK to expand.</figcaption></figure><p>You will see another step has been added to your applied steps (1) and that the formula bar has also been updated with code reflecting the expand step (2). But most importantly, all the detailed data from our API call is now visible (3)!</p><p>From here you can decide to make more transformations to your data such as changing data types, removing columns you don&apos;t need or adding certain calculations. If you are happy with the data, as a next step press &quot;Close &amp; Load&quot; (4). Since this is a new query, this will automatically load your Power Query table into a new Excel sheet as an Excel table.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cfa50cfd716655750bab9ccdb273f2dc9ee86fc89b38d661fb542e97e92f456e.png" alt="Queried data is now in a human-readable format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Queried data is now in a human-readable format</figcaption></figure><p>The Power Query editor will close and you will be brought back to your Excel sheet. In the Queries and Connections panel and within the sheet itself you will see Excel attempting to fetch the data again. Simply wait up to a minute for the API call to fetch the data, and Power Query to apply the transformations.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a7c63a7eb7c46a31841e4b2c7a5883de9c1929fdff744f66997aa83cdb3725f0.png" alt="Excel running the query and fetching the requested data " blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel running the query and fetching the requested data</figcaption></figure><p>Once complete, your data will appear in Excel and the Queries and Connections tab will let you know how many rows of data have been loaded.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c375e3f74c6dce85b90058531da282ea14a95006c7794c04f7fd9223bbd24e8d.png" alt="Latest data from our query appears in Excel in table format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Latest data from our query appears in Excel in table format</figcaption></figure><p>That&apos;s it! From here on out you can use Excel to play with the data, transform the data, make charts, tables graphs or just browse the full extent of data you pulled from CoinGecko in table format. <strong><em>Congratulations!</em></strong></p><p>Below is a simple charting example that only took a few seconds to produce with the data. Using a pivot table on the query result, we can easily create pivot charts that summarize the data in a visual manner.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e11864e32e589c89f6ea303faff157669db9e1d13a97bdb90a348cfd4a2f41a5.png" alt="Simple bar chart and pie chart using market cap data of CoinGecko&apos;s top 10 coins" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Simple bar chart and pie chart using market cap data of CoinGecko&apos;s top 10 coins</figcaption></figure><p>You can follow these steps for other API links within CoinGecko&apos;s documentation to fetch other data.</p><h1 id="h-part-4-coinmarketcap-api-and-querying-in-excel" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 4: CoinMarketCap – API &amp; Querying in Excel</h1><p>While the process for CoinMarketCap will mostly follow that of CoinGecko, there is one key difference: CoinMarketCap requires an API key to access their API. If you followed the steps in Part 2, you should already have an API key at your disposal. <strong>KEEP YOUR API KEY PRIVATE AND SAFE</strong>. Your API key should not be shared with others, as in the future you may start paying for other API access, and anybody with your API key will be able to use your access.</p><h2 id="h-part-41-coinmarketcap-finding-the-api-link" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 4.1 CoinMarketCap – Finding the API Link</h2><p>Just like in part 3, let us open the API documentation for CoinMarketCap:</p><div data-type="embedly" src="https://coinmarketcap.com/api/documentation/v1/" data="{&quot;provider_url&quot;:&quot;https://coinmarketcap.com&quot;,&quot;title&quot;:&quot;Account&quot;,&quot;url&quot;:&quot;https://coinmarketcap.com/api/documentation/v1/&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Coinmarketcap&quot;,&quot;type&quot;:&quot;link&quot;}" format="small"></div><p>Here you can view all API calls. Let us, however, use an API call that requests similar data to the one we used earlier for CoinGecko, namely the &quot;Listings Latest&quot; call:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyListingsLatest">https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyListingsLatest</a></p><p>If you click the top right GET command box, you can see the API call request URL. Copy it:</p><pre data-type="codeBlock" text="https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
"><code>https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ff8360ede47a6a63520109534d456f433c44b0f09944b8868384ce10a75495bc.png" alt="CoinMarketCap API Documentation for /v1/cryptocurrency/listings/latest API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinMarketCap API Documentation for /v1/cryptocurrency/listings/latest API endpoint</figcaption></figure><p>The CoinMarketCap free API membership is the “Basic” API plan. Hence we can use all endpoints that support that plan.</p><h2 id="h-part-42-using-excel-to-query-the-coinmarketcap-api" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 4.2 Using Excel to Query the CoinMarketCap API</h2><p>This step will be slightly different to the previous step with CoinGecko, because we need to use an API key to access the data. If we look at the &quot;Authentication&quot; section of the CoinMarketCap API Documentation, we will find that CoinMarketCap explains that to connect to their services we must use a custom header and our API key. The custom header that CoinMarketCap recommends is:</p><pre data-type="codeBlock" text="X-CMC_PRO_API_KEY
"><code>X-<span class="hljs-built_in">CMC_PRO_API_KEY</span>
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1d9a12e853a504e17e77e2cfc39295cb67b5da7df3f9065300dcd3cdd6e5ce23.png" alt="CoinMarketCap API Documentation for API key authentication" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinMarketCap API Documentation for API key authentication</figcaption></figure><p>With the custom header and API key at hand (log in to the CoinMarketCap Developers portal to find it, <em>see Part 2 of this guide</em>), let us navigate to the data tab (1) and under &quot;Get &amp; Transform Data&quot;, click on &quot;From Web&quot; (2) just like we did with CoinGecko:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/61e44aa8938444950566caf68af798261304000d12293fb14636afd94d736388.png" alt="Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window</figcaption></figure><p>This time when the “From Web“ pop-up appears, click on &quot;Advanced&quot; (1) and input the request URL in &quot;URL parts&quot; (2), then add the HTTP request header (3) as well as your API key (4). Once all is input, press OK (5).</p><p>URL:</p><pre data-type="codeBlock" text="https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
"><code>https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
</code></pre><p>HTTP request header:</p><pre data-type="codeBlock" text="X-CMC_PRO_API_KEY
"><code>X-<span class="hljs-built_in">CMC_PRO_API_KEY</span>
</code></pre><p>API key:</p><pre data-type="codeBlock" text="Log in to your personal CoinMarketCap Developer account and fetch from the dashboard
"><code>Log in <span class="hljs-selector-tag">to</span> your personal CoinMarketCap Developer account and fetch <span class="hljs-selector-tag">from</span> the dashboard
</code></pre><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8c41b4d9b91616724e3ee5c0f835a2a170414a5c6fc469375dfe5f61a56c619b.png" alt="Excel&apos;s advanced API query &quot;From Web&quot; settings screen with header options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s advanced API query &quot;From Web&quot; settings screen with header options</figcaption></figure><p>If this is your first time connecting to the CoinMarketCap API, you will see a window like the below we saw before for CoinGecko. Simply press OK.</p><p><em>Note: The link at the top will show your request URL for CoinMarketCap instead of CoinGecko as below.</em></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/eff3d46ff8ffc1fa324117a77ccd9b9e0553d4cc38f33c931bc5173c5b05fab5.png" alt="Excel&apos;s anonymous access settings" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s anonymous access settings</figcaption></figure><p>You should see below screen as it connects.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/13f5074dfac59f3f0409f545ae7faefc322261d2628f6e33059749a12bb6c9cd.png" alt="Excel attempting the API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel attempting the API call</figcaption></figure><h2 id="h-part-43-transforming-the-retrieved-coinmarketcap-data" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 4.3 Transforming the retrieved CoinMarketCap data</h2><p>The PowerQuery editor will automatically pop-up.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/48db1605344c70134e81b1ea23113d2346715bdb8e2dc33ec6d901f9f375ba3f.png" alt="Data is pulled into Excel Power Query, and split into &quot;status&quot; and &quot;data&quot;" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Data is pulled into Excel Power Query, and split into &quot;status&quot; and &quot;data&quot;</figcaption></figure><p>You will notice that it looks different to the CoinGecko screen – instead of “List Tools”, we are given a “Record Tools” ribbon at the top. This is because the CoinMarketCap API returns both the data we requested, as well as a record of our API call request (“status”), which it uses to track how much data we have pulled. In the CoinMarketCap API, there is a daily limit of how much data can be requested and is measured in credits. If you look at the CoinMarketCap developer dashboard, you will see with every API call your credits used will increase.</p><p>The above API call used 5 credits:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/de7ddfcf70449145fd51da8aabc9c1d5704ed90b97770ff16af7acb5c2b259a6.png" alt="CoinMarketCap Developer Dashboard credits used" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">CoinMarketCap Developer Dashboard credits used</figcaption></figure><p>To find the data we want from the Power Query editor, click on &quot;List&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1fd9001e447440356300442c50ea98c7dfa86413ba1c538b9a9ac0a5d4be2d7c.png" alt="Click on &quot;List&quot; to expand underlying data entries in Power Query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click on &quot;List&quot; to expand underlying data entries in Power Query</figcaption></figure><p>The result will be a table that looks similar to our previous table from CoinGecko. From here on out all steps are the same as with CoinGecko:</p><p>Press &quot;To Table&quot;</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/16e4a922e3815235fe01f53f5f7a3295f941ca94bf6dcdd567d0a10b7895ea92.png" alt="A list of records appears in Power Query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">A list of records appears in Power Query</figcaption></figure><p>Then click OK on the pop-up:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c144f6c8dce653fd08758f52df96d2922cee038d1d8382dbb929c5208d9a3dc4.png" alt="&quot;To Table&quot; pop-up window delimiter options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">&quot;To Table&quot; pop-up window delimiter options</figcaption></figure><p>In the resulting column, click the two outward facing arrows at the top of the column (1), then press OK (2).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d19d4c974c6a0c3280046adb6298e192fb27a387afd58da9aed92e8911ced6af.png" alt="Preview of what data is included in all the &quot;Records&quot;. Press OK to expand." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Preview of what data is included in all the &quot;Records&quot;. Press OK to expand.</figcaption></figure><p>As with CoinGecko, all CoinMarketCap data will be expanded. Again, click &quot;Close &amp; Load&quot; to load this data as a table into Microsoft Excel.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/29c5f778511b8b2c0b34bc412b885e16699b1eeb3751fb333b727d9cde93c91f.png" alt="Queried data is now in a human-readable format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Queried data is now in a human-readable format</figcaption></figure><p>You will see the Query running while Excel attempts to fetch the data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/9c5172d8310d544994b842ff683d64d088aa4f8b41515b96e929b0eb4464a78f.png" alt="Excel running the query and fetching the requested data" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel running the query and fetching the requested data</figcaption></figure><p>Once the API query call is complete, you will see all data in table format in your Excel.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7f8fc3aa1f43682eedcd173bbda735e1e6fe68e0753f3c992382debac2d9162e.png" alt="Latest data from our query appears in Excel in table format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Latest data from our query appears in Excel in table format</figcaption></figure><p>If you have been paying attention, you may have noticed that we did not rename our query this time. If you need to make any edits to your query, including any transformation steps within the query or the query name, simply double-click on the query on the right side to re-open the Power Query editor.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b0b9a98da0c3fcf944e2779f373c1ffe37f69c12226f2351f30326facc333047.png" alt="Double-clicking the Query in the &quot;Queries &amp; Connections&quot; panel re-opens Power Query" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Double-clicking the Query in the &quot;Queries &amp; Connections&quot; panel re-opens Power Query</figcaption></figure><p>From here we can now change the name (1) and hit &quot;Close &amp; Load&quot; (2) to save the changes to our query and reload it into our Excel.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4e13ee0f7a53f5ef67d5ba92be18deeefe70391e21f066ca813bf75a62b547e4.png" alt="Change the query name in Power Query and hit &quot;Save &amp; Close&quot;" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Change the query name in Power Query and hit &quot;Save &amp; Close&quot;</figcaption></figure><p>The updated name will be reflected accordingly. If you make any other changes to your query, they will also be updated.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/81d64537ec4cb087bcedeca9a646e08972eff7471aa52eef3d4ede5037969706.png" alt="Refreshed Excel table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Refreshed Excel table</figcaption></figure><h1 id="h-part-5-defi-llama-api-and-querying-in-excel" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5 DeFi Llama – API &amp; Querying in Excel</h1><p>Unlike the CoinMarketCap API, the DeFi Llama API is free. Hence, this process will much more closely resemble that of CoinGecko. However this time, we will run two Power Query API calls. We want to:</p><ol><li><p>Get a full list of all protocols tracked by DeFi Llama</p></li><li><p>Get detailed timeseries data for a specific protocol tracked by DeFi Llama</p></li></ol><h2 id="h-part-51-defi-llama-finding-the-api-link" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5.1 DeFi Llama – Finding the API Link</h2><p>Again, let&apos;s open the API documentation. This time for DeFi Llama:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://defillama.com/docs/api">https://defillama.com/docs/api</a></p><p>In your browser you should see the below screenshot. Here we can see a list of various Total Value Locked (TVL) data retrieval API calls. If we use the first call command /protocols, we will get a table similar to that of CoinGecko and CoinMarketCap which lists all the protocols and related information. From there we can find which protocol we want more detailed information for, and then use the /protocol/{protocols} API call to retrieve that information.</p><p>In summary, the steps we must undertake are:</p><ol><li><p>Get the protocol list using the /protocols API command</p></li><li><p>Within the data retrieved from the /protocols API command identify the &quot;slug&quot; (unique identifier) of the protocol that we want to retrieve our timeseries data for (this is a requirement listed in the /protocol/{protocols} API call)</p></li><li><p>Use the /protocol/{protocols} command to get the timeseries data for our selected protocol</p></li></ol><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/416bc7b9cad9493bd23edd7a9d016704920ca8adc6664655251ffc5218a1a710.png" alt="DeFi Llama API documentation" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">DeFi Llama API documentation</figcaption></figure><p>Same as with CoinGecko, we can expand the /protocols API call command and try it out on the website directly. This will show us the request URL we need to use in Excel, as well as show us the format of the data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d426515398fe2bc939754c297dd75a44ccd871f4901b5aa6ecc2faaab2f97d92.png" alt="DeFi Llama API server response for calling /protocols API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">DeFi Llama API server response for calling /protocols API endpoint</figcaption></figure><p>The request URL we need is:</p><pre data-type="codeBlock" text="https://api.llama.fi/protocols
"><code>https:<span class="hljs-comment">//api.llama.fi/protocols</span>
</code></pre><p>Just like with CoinGecko, we can observe the data returned. This can be helpful if you want to understand what data an API request will return. From the above screenshot, we can already see the slug for MakerDao: &quot;makerdao&quot;. We could skip doing the first API call from Excel and go straight to the second API query. However, we want to have a full list of all query-able slugs so that we can change our query in the future if we want to. For this we must still do the first API call requesting the full protocol list.</p><h2 id="h-part-52-using-excel-to-query-the-defi-llama-api-protocols" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5.2 Using Excel to Query the DeFi Llama API – /protocols</h2><p>Open Excel, and once again navigate to the data tab (1). Within the Data tab under &quot;Get &amp; Transform Data&quot;, click on &quot;From Web&quot; (2):</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/61e44aa8938444950566caf68af798261304000d12293fb14636afd94d736388.png" alt="Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window</figcaption></figure><p>In the pop-up window, paste the retrieval URL <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.llama.fi/protocols">https://api.llama.fi/protocols</a> then press OK.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/fb5382eb2a08bf036641f155f69f24705512a80c4c6187e8152a9abb6d1db2a4.png" alt="Excel&apos;s basic API query &quot;From Web&quot; settings screen" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s basic API query &quot;From Web&quot; settings screen</figcaption></figure><p>If you are asked to apply Access Web content settings, leave it with the default setting and press connect.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e9526b4ff6a2727df7c35412a3f506117842b531d598ebf415422596aaec8a6a.png" alt="Excel&apos;s anonymous access settings" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s anonymous access settings</figcaption></figure><p>A connecting pop-up will appear indicating that Excel is attempting the API call.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/98712eb753476bee3687522931bf5f81ab26181e01f79f08954a473696f741a3.png" alt="Excel attempting the API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel attempting the API call</figcaption></figure><h2 id="h-part-53-transforming-the-retrieved-defi-llama-data-protocols" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5.3 Transforming the retrieved DeFi Llama data – /protocols</h2><p>Once the API call was successful, the Power Query editor will open automatically once again, resembling our first CoinGecko API call. Once again, let us click &quot;To Table&quot; to convert the retrieved data to a table format.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cc3539ff290f0293d8b80417267e9a64ababc516fc189abed09b2d6d6c4caa70.png" alt="Data is pulled into Excel Power Query as a list of records" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Data is pulled into Excel Power Query as a list of records</figcaption></figure><p>When the &quot;To Table&quot; pop-up appears, keep all settings at default and click OK.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/6a1858bec8c9aef5c360c828f984cd28f6200eef68cf7eec10135cf464a073dd.png" alt="&quot;To Table&quot; pop-up window delimiter options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">&quot;To Table&quot; pop-up window delimiter options</figcaption></figure><p>Once complete, click the two outward facing arrows (1) then click OK (2) to expand the underlying columns.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/40626d18213fa750bc730227324046f62e92b7f2c6c0db409dc6540555a32ed9.png" alt="Preview of what data is included in all the &quot;Records&quot;. Press OK to expand." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Preview of what data is included in all the &quot;Records&quot;. Press OK to expand.</figcaption></figure><p>The result will be the full expanded table of all protocols listed on Defi Llama. Click &quot;Close &amp; Load&quot; to load the data as a table into a new sheet.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1995799ae35a3c26f38c21b295d6e8bb0c55ec54647cd2659da6597f95c28db1.png" alt="Queried data is now in a human-readable format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Queried data is now in a human-readable format</figcaption></figure><p>Excel will now work to retrieve the data from DeFi Llama.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2226c6e54fba1e9b2a0aac42dd756162f8ea8a28ab38ddfc848bb9137b34f1d1.png" alt="Excel running the query and fetching the requested data" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel running the query and fetching the requested data</figcaption></figure><p>Once retrieved, you will have a data table including information of protocols with key data that is listed on DeFi Llama.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2642a04a521f0df2fbeec5649ed4edfba2ace6b454509304ad905165405f88d3.png" alt="Latest data from our query appears in Excel in table format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Latest data from our query appears in Excel in table format</figcaption></figure><p>From here we can navigate to the &quot;slug&quot; column to see all the slugs that DeFi Llama uses (press CTRL+F on Windows to search for the keyword &quot;slug&quot; to find it quickly).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/bb9403eafc7556c3359f5623ae453d0081214588b5baa4b46abb6543fefe8101.png" alt="&quot;Slug&quot; column with all the unique identifiers for each protocol listed on DeFi Llama" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">&quot;Slug&quot; column with all the unique identifiers for each protocol listed on DeFi Llama</figcaption></figure><h2 id="h-part-54-using-excel-to-query-the-defi-llama-api-protocolprotocol" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5.4 Using Excel to Query the DeFi Llama API - /protocol/{protocol}</h2><p>Now that we have a full list of available slugs that we can refresh whenever we want, let us pick a slug. For this example I have picked &quot;makerdao&quot;.</p><p>Let us navigate back to the API documentation <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://defillama.com/docs/api">https://defillama.com/docs/api</a> and take a closer look at the /protocol/{protocol} command.</p><p>Again, we can try the API call directly on the DeFi Llama website first to get a feeling for the kind of data we will receive. Let us input &quot;makerdao&quot; into the protocol slug field and press execute.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3a0347c857f671a1ebed9386d39e4d51d2d1853cad0d38fb2e44523ab9c87549.png" alt="DeFi Llama API Documentation for /protocol/{protocol} API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">DeFi Llama API Documentation for /protocol/{protocol} API endpoint</figcaption></figure><p>In the resulting server response we can see a complex JSON data structure.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f60aa13c95948637d07cf9c7d901b3a8db6e9014c102bd55bd40af963505200d.png" alt="DeFi Llama API server response for calling /protocols/{makerdao} API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">DeFi Llama API server response for calling /protocols/{makerdao} API endpoint</figcaption></figure><p>At the highest level we receive more details about the protocol, and if we scroll further down the server response, we can also see what other data is included in the API response.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3c33dfe1fb50f238607e9f51b14089888fbe367541cf9e8b5a2810e2c3c53f08.png" alt="DeFi Llama API server response for calling /protocols/{makerdao} API endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">DeFi Llama API server response for calling /protocols/{makerdao} API endpoint</figcaption></figure><p>From our previous API call <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.llama.fi/protocols">https://api.llama.fi/protocols</a> that used the /protocols command, we can guess that the API address for this call should now be</p><ul><li><p>API base URL: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.llama.fi">https://api.llama.fi</a></p></li><li><p>API query: /protocol/</p></li><li><p>Parameter: makerdao</p></li></ul><p>Adding everything together the address we need to use is: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.llama.fi/protocol/makerdao">https://api.llama.fi/protocol/makerdao</a></p><p>Again in Excel we click the &quot;Data&quot; (1) tab and select &quot;From Web&quot; (2).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/61e44aa8938444950566caf68af798261304000d12293fb14636afd94d736388.png" alt="Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Click &quot;Data &gt; From Web&quot; to open the &quot;From Web&quot; query window</figcaption></figure><p>In the pop-up, paste the URL we just created:</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4c72c52aac1433effc317deabd4226c3dec912c558fee2dcea15011db1355124.png" alt="Excel&apos;s basic API query &quot;From Web&quot; settings screen" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel&apos;s basic API query &quot;From Web&quot; settings screen</figcaption></figure><p>A connecting pop-up will appear indicating that Excel is attempting the API call.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d90c207a73086a096b50f58e00e02a72e8db2d9a1426c3de12ea0c0f5fd1baa2.png" alt="Excel attempting the API call" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Excel attempting the API call</figcaption></figure><h2 id="h-part-55-transforming-the-retrieved-defi-llama-data-protocolprotocol" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 5.5 Transforming the retrieved DeFi Llama data – /protocol/{protocol}</h2><p>Since I&apos;ve worked with API before, I know to access &quot;tvl&quot; to get the total MakerDAO TVL over time. However, when you work with APIs you have not yet worked with before and the API documentation isn&apos;t very descriptive, you may need to click around the API responses to find what you are looking for.</p><p>In the result we can see all details of the MakerDAO protocol that DeFi Llama provides through their API as of this moment in time. From here we click on &quot;record&quot; next to &quot;tvl&quot; to expand that entry.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/136213dc44ebedf308b32f9c3341bbbee1476a7bcbd8050effd3b42f39b4e07e.png" alt="API call response from /protocol/{protocols} endpoint" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">API call response from /protocol/{protocols} endpoint</figcaption></figure><p>From here we transform these entries into a table by clicking on &quot;To Table&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cb43aa17e5fc566be2735a2cc13f6afc1ef9af94b9164a5810c7f312d815a41c.png" alt="List of records ready to be converted into a Power Query table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">List of records ready to be converted into a Power Query table</figcaption></figure><p>When the below pop-up appears, click OK.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c1718928747e20e287f8144b44a21742782954043157110315027591aa12dcb0.png" alt="&quot;To Table&quot; pop-up window delimiter options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">&quot;To Table&quot; pop-up window delimiter options</figcaption></figure><p>We must once again click the outwards facing arrows (1) on our column of data to open the sub-menu, then click OK (2) to expand the data.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/60d0c0d1ca4bc6274bdd05b2446e9eb810951c829f9d227656060d76f42e7979.png" alt="Preview of what data is included in all the &quot;Records&quot;. Press OK to expand." blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Preview of what data is included in all the &quot;Records&quot;. Press OK to expand.</figcaption></figure><p>We can now see data and TVL data or phrased differently, a timeseries of Total Value Locked in MakerDAO. But you may have noticed that the dates currently do not resemble dates. That is because the dates have been returned as UNIX timestamps, which count seconds from January 1st, 1997 onwards. Excel does not recognize this time format. If we click the cell format dropdown (1) and convert this data to date format (2), then…</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/674c911bd31130903ae7790a9d3814f75d92541e5b0ec890a4a9566b5389a6e8.png" alt="Column format sub-menu" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Column format sub-menu</figcaption></figure><p>We receive an error. Excel is not capable of directly transforming from a UNIX timestamp to an Excel time format. To do this, we need to manually calculate what the Excel time equivalent would be.</p><p>First, undo the last action by clicking on the &quot;X&quot; next to &quot;Changed Type&quot; in the &quot;Applied Steps&quot; window on the right.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/1fd49f5282c3098b3f5936df2771ffa566aeeb73970de4f13a9688c4b0d1b37c.png" alt="Converting UNIX time using the Power Query &quot;Date&quot; format leads to errors" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Converting UNIX time using the Power Query &quot;Date&quot; format leads to errors</figcaption></figure><p>Now that we have returned to our previous view, select the &quot;Add Column&quot; tab and click &quot;Custom Column&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/65f2e01abe610a8b6a1cd99290a9dd59c50cc92168661b2a0ab890c1c809fe4c.png" alt="Add a custom column for custom calculations and formulas" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Add a custom column for custom calculations and formulas</figcaption></figure><p>This will open the Custom Column editor where we can input a custom formula. Power Query formulas are different to Excel formulas, so if you want to do complex calculations, please refer to the Power Query formula documentation by Microsoft: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.microsoft.com/en-us/powerquery-m/power-query-m-function-reference">https://docs.microsoft.com/en-us/powerquery-m/power-query-m-function-reference</a></p><p>What we must do now is write a custom formula that converts the timestamp from UNIX to Excel format. UNIX time counts time in seconds from January 1st, 1970, while Excel counts time as days from January 1st, 1990. So to convert the time, we must take UNIX time and multiply by the amount of seconds within a day (86,400), then add the number of days from January 1st 1900 to January 1st 1970 (25,569).</p><p>Let&apos;s add the formula below and click OK.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3a87dc2ea5fae8b4b2c54b1d0b894e5afae7899500c8272781342a984760e03e.png" alt="Custom column formula editor" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Custom column formula editor</figcaption></figure><p>A new column has been added with numbers, but these numbers still don&apos;t look like dates. The values are correct, but the format is not.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b0a414a51d0715b09aac80755b658bea3c21fd27065e97c1d21938ac2d8c2ce8.png" alt="Custom column is added to the Power Query table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Custom column is added to the Power Query table</figcaption></figure><p>Hence as a next step, we need to change the format to &quot;Date&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/144594a4c4cebdddddfe44332e46eacff6d5618dcea0e077808f573a6ca12a20.png" alt="Column format sub-menu" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Column format sub-menu</figcaption></figure><p>And there we go, now our data looks alright.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/80a197d96db2edaf58546eb0e6e7e28bdda18874168a4ac7ed1fbc80cb167e97.png" alt="Converting the custom column using the &quot;Date&quot; format does not lead to errors anymore" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Converting the custom column using the &quot;Date&quot; format does not lead to errors anymore</figcaption></figure><p>Now let&apos;s clean up our table by removing the first column which is now obsolete. To do this right click on the column header (1) and then click &quot;Remove&quot; (2).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/518bfcbe30feda7ed37eefd65d5c540c16b60485e580e89f5f0e001ba1fc58a9.png" alt="Right click the column header to unveil further column options" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Right click the column header to unveil further column options</figcaption></figure><p>And then let&apos;s move the new date column to the left (simply drag it to the left).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cad900d6be839e35d6e27ef174f66c091a10546a00002de68e15c8fe2ec6c9fe.png" alt="Column re-organization is a simple drag-and-drop action" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Column re-organization is a simple drag-and-drop action</figcaption></figure><p>Now our data is ready to be loaded into an Excel sheet. Click &quot;Close &amp; Load&quot;.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d62a747e8cd7eb1190df5ddfd3a01816716b916ba6a88aee185faff20657f580.png" alt="Queried data is now cleaned up and ready for import to our Excel sheet" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Queried data is now cleaned up and ready for import to our Excel sheet</figcaption></figure><p>Now the timeseries TVL data for MakerDAO has been loaded into Excel as a data table. Congratulations!</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ee39fdb794d376684948f1f5b836761d0b629d8c15e8e13eeed2cb9019b2c757.png" alt="Latest data from our query appears in Excel in table format" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Latest data from our query appears in Excel in table format</figcaption></figure><p>From here we could, for example, use the data to add a line chart to visualize MakerDAO&apos;s TVL over time.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0526233124df2b516bd2e84567684b25d9234a855f0fb11c81b95c966eb11a41.png" alt="Simple timeseries line chart using DeFi Llama&apos;s TVL data on MakerDAO" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Simple timeseries line chart using DeFi Llama&apos;s TVL data on MakerDAO</figcaption></figure><h1 id="h-part-6-other-notes" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 6 Other Notes</h1><p>Here we will briefly cover how to refresh data after you have built a query, and share some other important notes on API call URLs.</p><h2 id="h-part-61-refreshing-data" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 6.1 Refreshing Data</h2><p>To refresh this data when you open your Excel file in the future, simply navigate to the Data tab and click &quot;Refresh All&quot; (1).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/87bc9ff6cba6afc6681d7984dbeb937653638e1ce020680c4829ded901768acd.png" alt="Refresh all runs all data queries" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Refresh all runs all data queries</figcaption></figure><p>Another quick way is to just right click anywhere within your table (1) and click &quot;Refresh&quot; (2).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3af3ed19f99eca4204fc1d5790805f08696446b2fd56301d03f6cd3a35549503.png" alt="Refreshing a single table runs only the data query of that table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Refreshing a single table runs only the data query of that table</figcaption></figure><p>Alternatively, if you only want to refresh a specific query, you can click anywhere in the data table (1) then navigate to the data tab (2) and click the down arrow under the &quot;Refresh All&quot; button (3) and click &quot;Refresh&quot; (4).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f58e45c2a6932612ad2fe53dcc68971bc5c36add98365e577ff86fe6166ade02.png" alt="Refreshing a single table runs only the data query of that table" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Refreshing a single table runs only the data query of that table</figcaption></figure><p>Or within the data tab (1) you can open the Queries &amp; Connections panel (2), right click on your specific query (3) and click &quot;Refresh&quot; (4).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/aaa2bf867f28b7117905b24c30a9c60b02f122d83e7bcd08685c4c62fd92f38c.png" alt="Refreshing a single query runs only that data query and updates and related tables" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Refreshing a single query runs only that data query and updates and related tables</figcaption></figure><h2 id="h-part-62-important-note-on-api-call-url" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Part 6.2 Important note on API call URL</h2><p>In our first CoinGecko example we used the below API call link provided by the CoinGecko API documentation:</p><pre data-type="codeBlock" text="https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&amp;order=market_cap_desc&amp;per_page=100&amp;page=1&amp;sparkline=false
"><code>https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&#x26;order=market_cap_desc&#x26;per_page=100&#x26;page=1&#x26;sparkline=<span class="hljs-literal">false</span>
</code></pre><p>This link is actually comprised of two parts, namely the base URL and the API call parameters:</p><ul><li><p>Base URL: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://api.coingecko.com/api/v3/coins/markets">https://api.coingecko.com/api/v3/coins/markets</a></p></li><li><p>Parameters:</p><ul><li><p>?vs_currency=usd</p></li><li><p>&amp;order=market_cap_desc</p></li><li><p>&amp;per_page=100</p></li><li><p>&amp;page=1</p></li><li><p>&amp;sparkline=false</p></li></ul></li></ul><p>The first parameter is prepended by a question mark (?), while every other parameter is prepended with an ampersand (&amp;). Each parameter consists of the parameter name (left of the =) and the parameter setting (right of the =). You can change these parameters as needed for your specific API call. When manually building API call URLs, make sure that you include the required parameters as stated in the API documentation, otherwise your API call will return an error.</p><p>Error codes and their meanings are usually listed in API documentations as well to help you with troubleshooting.</p><h1 id="h-7-closing-thoughts" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">7. Closing thoughts</h1><p>From here on out you can use multiple API queries to fetch and update information at regular intervals and create entire dashboards of only the data that is important to you. Gone are the days where you have to click through multiple websites and multiple pages to see the data that you care about – instead you can build it all in Excel!</p><p>If you have previous experience with Excel, you can combine these data fetching techniques with other Excel data transformation techniques to combine queries from multiple APIs to get a strong view on the crypto market. For example, you could combine CoinGecko&apos;s or CoinMarketCap&apos;s AAVE token pricing, market cap and volume details with DeFi Llama&apos;s TVL data to get an immediate overview of how the AAVE token is performing.</p><p><strong>If you found this helpful, please consider sharing this and following me on Twitter</strong> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/0xPhillan"><strong>@0xPhillan</strong></a><strong>. And if you have any questions, feel free to DM me on Twitter!</strong></p><p>Thanks, and have a great day!</p>]]></content:encoded>
            <author>phillan@newsletter.paragraph.com (0xPhillan)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/c9068bea00f925bbfc69a61e1b621be77a9c40bba1c7e3012b6dd3e8f31a1bd8.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>