@pepperonesยท12 charts
Contract Functions Dive
We use "transactions" (users calling contracts) and "traces" (contracts calling other contracts) to get the function signatures (first 8 characters of "transactions.data" or "traces.input") and generate decoded tables using the ABI. I then use the transaction hash to tie together the "logs" table and see what functions emit what events.
Take a look at the most commonly called functions, and start your analysis there. Look to the connected events tables to help fill in any missing data points.
Contract Usage Over Time (Events)
This shows the number of times different events were emitted (it is not representative of the number of transactions). It helps us see when there was a spike or drop in certain events (such as liquidations).
You can take this a step further by figuring out how to add values like ETH or ERC20 amount to events but looking at what variables are in the parameters (ABI table).
Top 100 Contracts This One Uses
Now let's look at which other contracts are interacted with downstream. I've added a general filter to allow you to toggle if you want to show tokens and multisigs.
A good intuition to build is that higher-level contracts manage liquidity more granularly in lower-level contracts, so the farther you go down the stack the more you can see how concepts like prices, royalities/revenue splits, and liquidity mining rewards are managed.
Contract Usage Over Time (Calls)
This is here in case the contract has no events. Usually, looking at function call usage is convoluted because most contracts will have many functions tied to the same event, such as different token swap calculations/logic for a single Swap() event.
I've also added a modify_only filter which removes view functions from the chart - view functions are pretty much only useful to analyze for something like oracles.
Top 1000 Users
Its helpful to see who has been interacting with a contract (again, based off txs that emit an event on this contract). Here we use get_ens() to get a better idea of who is interacting with this contract.
Sometimes it won't be helpful at all, but it never hurts to skim this! I would click around at top users and see:
- are they a power user of any other protocols?
- what's the average wallet age and token holdings of top users?
New/Old Wallets Over Time
See how many new or old wallets call this contract directly or indirectly (cause an event to emit) over time.
The next level for this is doing actual retention metrics, so splitting into monthly/weekly new users and seeing how many weeks in a row they come back.
Contract ABI Events
Same as above, try and see what variables show up consistently. Pay attention to if variables show up in both event and input, or event and output - this will tell you that something (like swap price) was adjusted and calculated within this function.
Contract Metadata
This pulls from our contracts table which tracks the decoding pipeline, I've added some extra logic to let you know if it fits into any token standards.
What are the most popular function calls and events emitted, and how are the two linked together?
The two tables below serve to show you this data lineage in Dune, and easily show all the events a function emits (or all functions that emit a specific event) - as well as how often they're called. Usually, you'd use something like a call graph visualizer to get this, but those can still make it hard to figure out which functions are important and how they're tied to events.
Caveat, sometimes you'll need to modify these query to use "traces" instead of "transactions" in case of things like governance contract calling an updateParameter function. That function won't appear because it was never invoked by a EOA /user.
Contract Analysis Quickstart
๐ง Be sure to follow our list of educational wizards on Twitter for more Duniveristy content!
๐ข Do you have a contract address from a protocol or token, but aren't sure how to start analyzing it? This dashboard will give you an overview of how any contract address works - so you'll know what function/event tables (or other contracts/addresses) to query next!
You should gain a good understanding of:
- what functions and events make up the contract, and how to understand them.
- which functions and events are tied together
- the most popular functionalities and usage trends over time
- who and how other protocols interact with it, and what other protocols/contracts does this one call
- who the top users are (with ENS + other labels).
The first section, requires the contract to be decoded in Dune, the others will try and find a signature match for functions/events.
๐ All Function/Event Name columns have links to an example transaction!
๐ if you find a bug/edge-case, please screenshot it and dm me so I can fix it.
Top 100 Contracts Using This One
Here we check for contracts that call this one and cause an event to emit. In case this contract has no events, then you'll want to run this query that checks function calls in traces instead (though it'll likely time out).
This can be the start of a proxy for market share or user analysis, to help you figure out which aggregators or vertical protocols are driving the most volume and users. You could pick an event/function and then analyze market/user share over time.
Contract Overview
The contract must be decoded for this section of the dashboard to work. You can run your contract address to see if it's ready or not.
This section provides you with basic contract metadata and a high-level view of all external functions and events, as well as their input or output parameters from the ABI. You can read more about function state mutability here.
Dune takes raw blockchain data (i.e. function signatures and event topics from transactions, traces, and logs tables) and uses the ABI above to get you decoded tables that follow a specific schema. You'll find the signature <> ABI linkage in the next section.
Contract ABI Functions
The functions listed here are all external, meaning they can be called by other contracts or users. "view" or "pure" functions act as getters, and don't modify the state at all. "payable" allows ETH to be transferred, "nonpayable" does not.
I would skim the inputs and outputs of payable/nonpayable functions to get a sense of what variables show up the most - these are likely the ones you'll need to aggregate across decoded tables in your queries.
New/Old Protocol Integrations Over Time
See how many new or old contracts call this contract directly (in traces). Safes and contract wallets are filtered out.
Note that sometimes arb bots will write custom contracts or use some multicall contract to interact more efficiently.
Contract Events Dive
Here we go the other way around, starting from the "logs" table to decode topics into event names before joining on "transactions" to get all the functions that emit this event.
Sidenote, you might see the numbers here are much larger than in the table above - that's because we didn't include internal transactions there.
Who and how is this contract being used?
Composability is one of the most used words in web3 - this section takes a deeper look at how this contract is used. We look at events emitted by this contract when another contract is called, and also events emitted by contracts that this one calls. For example, an NFT marketplace contract will be called by some set of aggregator or bot contracts, and likely calls some set of allowlist or price oracle contracts. I've filtered out ERC20, ERC721, and ERC1155 contracts in the callee table.
Looking at wallets (EOAs which invoke the calls also tells us who some of the top users might be, we have a labels table in spellbook which we use to provide us more enhanced metadata around the user addresses.
Same caveat as the last section, you'd maybe want to take a traces approach to all of this to get function usage instead of event usage. You can find an example here that takes much longer to run.
Choose your chain and contract address, then hit "apply all parameters" or "command + enter" to start running the queries.
Some queries in the second two sections take up to 5-10 minutes, so go grab a coffee and come back!
โ Not sure what contract to analyze? Check out 0xKofi'strending contracts dashboard and pick one from there.
Or try one of these more complicated contracts/tokens:
- Aave v2 (lendingpool at 0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9)
- Uniswap V2 (Router02 0x7a250d5630b4cf539739df2c5dacb4c659f2488d, Factory 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f, WBTC/ETH pair 0xbb2b8038a1640196fbe3e38816f3e67cba72d940)
- Lido (stETH at 0xae7ab96520de3a18e5e111b5eaab095312d7fe84)
- Lens Protocol (LensHub on Polygon at 0xdb46d1dc155634fbc732f92e853b10b288ad5a1d)