header-langage
简体中文
English
Scan to Download the APP
Partnered With:

How to understand Ethereum transaction information through on-chain data

Read this article in 22 Minutes
Interpretation starts from the transaction data, from the shallower to the deeper, in the order from the whole to the details, and understands the transaction data in the browser based on the working principle of Ethereum.
Original title: "The Road to Becoming an On-Chain Data Analyst - Understanding Ethereum Transactions"
Original Source: OKLink
Original Author: Mabrary
< p>

The process of on-chain data analysis can start from data to interpret behavior, then to intention and even trading psychology. Among them, the behavior can be the behavior of the trader, the behavior of the contract, or the behavior of the market. Judgment and long-term observation of traders' intentions can lead to their trading psychology. From the contract behavior, the intention of the contract creator (project party) can be more accurately understood, and the code does not lie. Finally, the analysis of certain specific behaviors and intentions can lead to the overall psychological state and psychological expectations of the market.


The core of the data on the chain is the transaction data, so in this article we will start to interpret the transaction data, from the shallower to the deeper, in the order from the whole to the details, Understand transaction data in the browser using how Ethereum works as a baseline.


We divide the concepts that need to be understood in transaction data into three levels in order from shallow to deep, and you can choose according to your own foundation Read carefully:


Level 1 Keyword: Ordinary Transaction|Contract Transaction


Second Level Key Words: External account|Internal account|Internal transaction


Third-level keywords: Transfer|Transaction|Event|Log


< /p>

1. Types of Ethereum transactions


First of all, transactions in Ethereum can be roughly divided into two types: external address transactions (Figure 1) & contract transactions (Figure 2).



  Figure 1: External account address transaction overview page  


Ordinary address transaction It refers to the transfer that only involves Ethereum’s original Token (native token) Ether, and does not involve the call of the contract or other tokens in Ethereum. Token transaction. The data in ordinary transactions can be roughly divided into four blocks: transaction hash, time, etc. belong to the transaction index (index), which provides information for locating transactions. The transaction amount specifically refers to the amount of Ether transferred, and the sender (sender) and receiver (receiver) of the transaction are each other's counterparties in this transaction. Gas fee consumption is the transaction cost that the sender of this transaction needs to bear.



  Figure 2: 0x513d and Metamask Router contract transaction overview page  


We See, there will be three more pieces of content on the browser transaction overview page involving smart contracts:


(1) The internal process of Ethereum executing transactions (internal transactions) ;


(2) Token The result of the transfer ( Token Transfer);


(3) Input parameters (input data) of contract execution


Compared with ordinary transactions, there are two more tabs (blue) at the top of the contract transaction page: internal transaction and event log.


So, what is insider trading? Why are transactions between ordinary addresses not labeled as internal transactions? How is the information presented in the Internal Transactions tab interpreted? What is the difference between an internal transaction and a normal transaction?


To answer the first three questions above, we need to understand two concepts: external account & internal account


Second, external account & internal account


Ethereum addresses (accounts) are divided into external accounts (i.e. entity accounts) and internal accounts (i.e. contract account) two types.


Users access external addresses through their private keys, while internal addresses cannot be directly accessed as wallets, but can only be used by calling their functions.


The external account is the entity (person) in the world outside of Ethereum who wants to access the agent of the Ethereum world, and it is also the initial change in the state of the world computer of Ethereum source. We know that the change of the state of Ethereum is initiated by a transaction (ordinary transaction). If the counterparty is a smart contract, the input data (input) in the transaction will be used as an input parameter to trigger the contract method when the virtual machine executes the contract. After the contract method is called and executed, it may also trigger the methods in other contracts, thus forming a chain reaction, and the intermediate process of these chain reactions is the internal transaction. Figure 3:


< br>

  Figure 3  


Now, let's take a look at the browsing If you look at the normal address transaction in the device (Figure 1), you can understand why there is no label item for internal transactions - because this is a transfer from an external account to an external account, the sender does not attach a code to the input data, and the receiver There are also no executable contract methods. The contract transaction in Figure 2 is initiated from the external account address of 0x514d to the contract account of 0x881d, and the initiator 0x514d tells the contract method (function) to be called by the contract 0x881d through input data (input data) and the parameters required by the method. After the method in the contract is called, it will continue to call the method in other contracts. For example, in the first internal transaction, Metamask's Router contract will continue to call (call) the receiver 0x74de(Matic Token The method in the contract address)... finally forms a call chain, which is what we call an internal transaction.   



  Figure 4: 0x513d and Metamask Router contract transaction internal transaction tab
Note: The transactions recorded on the internal transaction details page only involve native Token Transfer of Ether.   


It should be noted that since the Ethereum blockchain only stores the state of the Ethereum Virtual Machine (EVM) after processing the transaction, it does not Store calculations. Therefore, the internal transaction information shown above is not stored in the blockchain, and the result of the Ethereum transfer (red box) will eventually be updated in the world state of t+1. Some of the execution results will be reflected in the " Token Transfer" (Token Transfer).   



Figure 5: Token Transfer part  


back Turning around, let's review the concept of external accounts. Although the behavior of external accounts sometimes does not directly lead to changes in the state of the Ethereum world (changes in the balance of external accounts or changes in the state of contract accounts), the source of tracking these changes must come from external accounts, and the direct cause of the changes at this time is Execution of contract methods.


After reading this, you may have accumulated some questions in your mind:


< /p>

We often see two words in some descriptions: Transfer and Transaction. Both words can be translated as transfer, so what is the difference between them?


How does the 0x881d contract mentioned above know which contract method is called?


·What is the third tab event log (Log)? Where does it work? Will they all be recorded on the blockchain?


Let’s answer one by one~


3. Transaction And event 1. What is the difference between Transfer and Transaction?


Transfer usually refers to Token The transfer of ownership can be divided into original Token transfers and other criteria Token transfer (such as ERC20, ERC721, etc.); and Transaction refers to the initiator of the transaction, that is, the from address (external account), the transaction request submitted to the miners. If the miners are successfully included in the block and complete the consensus, then The transaction takes effect, otherwise it will be informed that the transaction failed.


What information does the transaction submitted by the initiator contain? This requires us to understand how a transaction occurs on the chain.



  Figure 6: Transaction data composition


We focus on explaining the third part. From the perspective of program execution logic, this part is the initial information that the transaction sender enters into the Ethereum virtual machine to execute this transaction: the virtual machine operation object (receiver To), the asset transferred from the transaction sender to the operation object (Value), and the virtual machine Enter the parameters (input) at runtime. When  To is empty, it means that the virtual machine has no operable object, and the virtual machine will use the input content to deploy a new contract.   


2. Let's take the above contract transaction (Figure 2) as an example to answer the second question: 0x881d contract How to know which contract method was called?


This requires us to parse the input parameters. The first eight digits of the input data after removing 0x represent the contract method identifier (5f575529), and the latter data are the parameters required by the method.


Input Data:
0x5f5755290000000000000000000000000000000000000000000000000000000000008000000000 000000000000000007d1afa7b718fb893db30a3abc0cfc608aacfebb0000000000000000000000000000000000000000000000007d59f7b054aa6bc0000000000 136 f6e65496e6368563446656544796e616d6963000000000000000000000000000000000000000000000000000000000000000000000000000000000000 002000000000000000000000000007d1afa7b718fb893db30a3abc0cfc608aacfebb0000000000000000000000000000000000000000000000000000000000 102 04aab87265e200000000000000000000000000000000000000000000000000000000000012000 00000000000000000000000000000000000000000000 000002591872913bde0000000000000000 00000000f326e4de8f66a0bdc0970b79e0924e33c79f19150000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000c82e95b6c80000000000000000000000007d1 afa7b718fb893db30a3abc0 cfc608aacfebb000000000000000000000000000000000000000000000007d59f7b054aa6bc00000000000000000000000000000 00000000000000000000001044bbac12d5ad5000000000000000000000000000000000000000000000000000000000000080000000000000000000000000 0000 00000000000000000000000000000000000140000000000000003b6d03407f8f7dd53d1f3ac105 2565e3ff451d7fe666a311ab4991fe000000000000000 000000000000000000000000000000000e5


Among them, the contract method identifier is obtained by retaining the first eight characters after the contract method passes through the SHA-3 hash algorithm. Therefore, although we don't know the source code of the contract, we can match this method in the records of other known method source codes according to the first eight identifiers:


swap(string aggregatorId, address tokenFrom, uint256 amount, bytes data).


Because methods in smart contracts are often reused in other contracts, the same method (identifier) may correspond to multiple contracts.



  Figure 7: Input Data Parsing  


3. The third label What is the event log (Log)? Where does it work? Will they all be recorded on the blockchain?


In a contract source code, not only the contract method (function), but also the event event abc() and the submission event emit abc() are defined. The submitted event will be recorded in the log, and finally the log will be recorded in the receipt function of a transaction that calls the contract. Let's take the source code of SushiSwap's contract 0x7f8F7Dd53D1F3ac1052565e3ff451D7fE666a311 as an example. They define the async event, which will also be submitted and recorded in the log middle.



  Figure 8: SushiSwap contract partial source code  

  

However, in the log Storing events in the log is not intended to be accessed by smart contracts in the future, **smart contracts cannot listen to the data in the log. ** In fact, events are used to notify outside users of what is happening on the blockchain. For example, when you receive a sum of money on the Ethereum address Token , the interface of the wallet will push a reminder for you, which is actually an event that occurred on the chain that the front interface of the wallet has monitored. Since the code of the event submission event is in the contract source code, its execution is also carried out in a decentralized manner, and is finally saved on the blockchain. Therefore, the data in the log is credible. Another reason why developers use events is that logs are a cheaper way to store data, the cost of storing data in logs is about 8 gas/byte, and the cost of storing data in contract variables is 625 gas/byte.   


< br>

Figure 9: 0x513d and Metamask Router contract transaction event log tab


For To describe an event, a log usually contains several Indexed Topics and unindexed Data. Among them, Topic0 is the signature (keccak256 hash value) that usually contains the name of the occurrence event, including the type of its parameters (uint256, string, etc.). Still taking the above 0x513d and Metamask Router contract transaction as an example, the log in the red part records the events recorded in the log when the SushiSwap contract is executed.


[Topic0]: 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1


is to send the event Sync (uint112 reserve0, uint112 reserve1) obtained by running the Keccak256 algorithm. Also, ...1f0f and ...d552 are two parameters in the event.


We retrieved the event log of the OKLink full node for a whole year (2021.3.15-2022.3.16), and we saw that Transfer events are the most, The Sync event analyzed above ranks third~



  Figure 10: Ranking of event methods


Fourth, summary

< br>

In this article, we start with an overview of the two types of transactions, and analyze the transaction data between external account addresses and the execution process of contract methods triggered by external account addresses. Both types of transactions contain a transaction index, counterparty, transaction amount, and cost. In the contract transaction, the calling process of the contract method will be recorded by the blockchain except for one time between the initiator and the receiver, and the calling process inside the other contract will not be on the chain. Only the execution result and the submission event will be recorded in the blockchain. in the block chain.


Original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit