Verification of ERC20 transfer events on L1: Soliness example
In this article, we will study how to check the ERC20 transfer event to the Ethereum Layer 2 (L2) network using a solid smart contract. We will assume that Alice transferred 100 USDC to BOB to a transaction T by Block B.
The problem: L1-ETHICS transactions on L2
During the transfer of assets between different block channels, since from L1 to L2, the transaction is carried out on L1, after which it is distributed to L2 via a series of Etherscan transactions. However, this process can be ineffective due to the latency of the network and the gas costs.
The ERC20 standard, which controls the transfer of tokens between the accounts, has been updated to include the management of L1-ET transfers. However, checking these events is still a challenge due to the decentralized nature of blockchain networks.
Our decision: Solishness Agreement
We will create a simple smartness contract in Solidity, which shows how to check an ERC20 transfer event to L1 using L2 network (Arbitrum One or Optimism). The contract will follow all transactions including beans and will identify those who have specific conditions, such as the sender is Alice and the recipient who has transferred $ 100.
`Solidity
Pragma Solidity ^ 0.8,0;
Import "
L1tol2verify contract {
// Mapping Accounts in the history of their transactions
Mapping (address => transactionhistory) public transactions;
Structural Transaction History {
Uint256 blocking number;
Ladres address;
approach approach;
UINT256 amount;
}
TransactionCreated Event (Indexed Address of the Sender, Indexed Recipient Address, UINT256 amount);
Transfer the event (address indexed from the address, indexed, UINT256 amount);
Createtransctionhistory () Publy Returns (Transactionhistory) Function (Transactionhistory) {
Return Transactionhistory (Block.Timestamp, Msg.sender, 0, 100 10 * 18);
}
Submission Function (Address _Pipient, Uint256 _amount) Public Payable {
// Create a transaction history for the sender
Transactions [msg.sender] .blocknumber = block.number;
Transactions [msg.sender] .Fromaddress = _Rescapient;
// Update the recipient transaction history
Transactions [_repient].
}
VerifyTransactionevent (Address _Sender, Address _recaper) returns publicly (bool) {
// Get the sender and the recipient of the transfer of the history of the account L1
Transactionhistory Sender = transactions [msg.sender];
Transactionhistory the replicient = transaction [_reput];
// Check that the sender is Alice
Require (Sender.Fromaddress == "0x ...", "Sender Invalid");
// Check that the recipient has transferred 100 USDC
require (recipient. Sum> = 100 10 * 18, "the recipient has not transferred enough markers");
// Create a new event for the appearance of a transfer (not illustrated in this example)
Radiation transfer (Sender.Fromaddress, _reput, 100 10 * 18);
Real return;
}
}
'
Explanation
This solidity contract consists of three main functions:
- Createtransctionhistory ‘: Creates a new history of account transactions.
- “SENDTRANSAction”: Send a transaction from one address to another and update their transaction stories.
- `VerifyTransactionevent ‘: Checks if a specific L1 (Ethereum) network transfer event happened using the experienced and recipients provided.
The contract uses cartography to store all transactions including beans, including the history of transaction.
deploying
To unfold this contract, you will need:
- Configuring an account in Faucet Ethereum.
2