1

Project Overview

3

Create Metrics Charts

4

Publish your dashboard

๐Ÿ…

How to Query Total Smart Contracts Deployed in Ethereum


Let's build a counter to display the total number of smart contracts created so far.

Smart contracts are created in two ways.

  • An external account sending a transaction to create a smart contract. We've seen this in the last section.

  • A Smart contract sending an instruction to create another smart contract. Yes. When a transaction is executed, it can create or interact with other smart contracts.

Smart Contracts Creation Scenarios

Smart Contracts Creation Scenarios

In the second workflow, the user triggered a call to an existing contract. In response to that, the smart contract #0xb000 created a new smart contract #0xb999.

Not only can a smart contract create another smart contract, but it can also call an existing smart contract, as well as send ETH to other accounts.

These are known as internal transactions, and they are NOT recorded as transactions in the blocks.

If they are not in blocks, where do we get that information?

EVM records the output of each step of the transaction execution in traces.

We will be able to list all smart contracts created thus far, including those created internally, by scanning the traces.

Dune Analytics ETL

Dune Data Load

We know where to look now.

Let's run a query against the traces table to list only contract creation data. We can add a condition to retrieve only the required rows because traces contain other run time data as well.

/* Query to retrieve total number of smart contracts created so far */
SELECT
  --Divide by 1,000,000 (or 1e6) to report in millions
  COUNT(*) / 1e6 AS contracts_count 
FROM
  ethereum.traces
WHERE
  `type` = 'create';

๐Ÿ‘จ๐Ÿฝโ€๐Ÿ’ป Can you create a counter chart for the above query, as you did in the previous section?

๐Ÿ‘‰๐Ÿฝ Please remember to add the chart to the current dashboard.

Feeling stuck?Check out this Smart Contracts Chart

๐Ÿ’พ Lets save your progress

Copy the Dune query URL and update it here.