Learn about Ethereum transactions and write your first Web3 SQL to extract data from the blockchain.
What is a Transaction?
Ethereum is a global computer that executes smart contract and stores its data (generally referred as contract state).
In addition to smart contract’s state, it also stores account balances i.e ETH owned by accounts.
Ethereum’s global state is updated on the following three scenarios.
Transaction Type I : Create Smart Contract
To create a smart contract on the Ethereum network, the user signs and sends a transaction along with the code. Once the transaction is processed, the Ethereum Virtual Machine (also known as the EVM) updates the global state to store the new contract’s code and data.
Transaction Type II : Call Smart Contract
In order to perform action on an existing contract, the user signs and sends a transaction to invoke the required method along with the input data. Upon processing, the EVM updates the contract’s data to reflect the current state.
For instance, when a user sells their NFT registered in a particular contract, the contract’s state will be updated to reflect the new owner.
Transaction Type III : Transfer ETH
When a user transfers ETH to another user, the account state is updated to reflect the new balances.
As we’ve seen, any changes to the Ethereum network are made through transactions. Transactions are the means by which external users interact with the system. So, by measuring the transaction volume, we can observe how active the network is.
Since we have observed that every transaction is recorded in the blocks (referred to as the blockchain), we can figure out the total number of transactions by querying the blocks.
Dune Analytics extracts the transaction data from the blocks and loads them into the ethereum.transactions
table.
To identify the total number of transactions since inception, we can just count the total number of rows in the ethereum.transactions
table.
/* Query to retrieve total number of transactions in Ethereum */SELECT
--Divided by 1e9 to report results in billions
COUNT(*)/1e9 AS transactions_count
FROM
ethereum.transactions;
Fork the above query and create your own chart.
We explored transactions and created our first query with just three lines of code to extract data from the public blockchain.
Follow for more articles on web3/blockchain data analytics.
Originally published at https://www.twigblock.com.
New to trading? Try crypto trading bots or copy trading