Skip to content

Contract Analysis

@jxsxph@jxsxph12 charts

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 Analysis Quickstart

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.

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.

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 Functions Dive

We use "traces" to get the function signatures (first 8 characters of "traces.input") and generate decoded tables using the ABI.

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 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.

Some functions may not be tied in if they were only ever called in traces. Functions called by governance contracts are a good example of this. I can't make that link yet because we don't support trace <> log indexing connections.

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.

Top 100 Users

Its helpful to see who has been interacting with a contract (even if they don't call this contract directly, but instead through traces). We can see their ENS, as well as NFT/DEX activity

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 Using This One

Here we check for contracts that call this one by function in "traces". Flow goes caller -> caller function -> callee -> callee function, where callee is the address you put in the param at the top.

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.

modify parameter affects this table.

See which contracts are calling this one the most.

Note that sometimes arb bots will write custom contracts or use some multicall contract to interact more efficiently.

modify parameter affects this table.

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.

modify parameter affects this table.

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.

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.

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.

modify parameter affects this table.