Understanding the Ethereum transaction Return and status: 0
Ethereum’s transaction system is designed in such a way that errors are treated when executing intelligent contracts. Two critical concepts in this context are ‘transaction revertand' status: 0
. In this article we will mean how these terms, how to differ and when you could meet one or both.
Return transaction
A transaction decline occurs when an error occurs during the execution of an intelligent contract. This can happen for various reasons, such as:
- Errors from the gas (oog)
- Gas creation (ge)
- Invalid gas prices
- Not fatal returns (NFR)
When a return occurs, the gasless system from Ethereum automatically drives the transaction and returns an error message to the contract. The status “Transaction Revert" is then displayed in the blockchain as "Status: 0".
Status: 0
Status: 0 refers to the block number in which the returned transaction occurred. It is essentially a timeline for this specific block.
Here is a simple example of how this works:
Solidity
Pragma solidity ^0.8.0;
Contract revertexample {
Function DosomeThing () Public {
// do something
}
Function Reversomething () Public {
// If we want to trigger a return manually, we can use the following code:
Return dosomeethette ();
}
}
`
In this example, Ethereum will automatically divid the transaction and returns an error message when an error occurs. The “Status: 0” field is then set in such a way that the block number is shown in which the returned transaction occurred.
key differences
* Fault type : Provisions are errors that occur during the contract execution, while ‘status: 0specifies a block number.
* Dealing with handling : If an error occurs, the gasless system from Ethereum releases the transaction and returns an error message. In contrast,status: 0does not indicate a mistake, but represents the time temple for the returned transaction.
Best Practices
When writing intelligent contracts on the Ethereum platform, it is important to treat the returns properly:
- UseAbi.Revert () instead of
Reversomething ()
.
- Treat returns within your contract functions or in separate storage storage stores.
- Note gas creation and invalid gas prices that can lead to Oog defects.
If you understand the difference between decline in transaction and status: 0, you are better equipped for the treatment of errors and the optimization of your intelligent contracts for efficient provision for Ethereum.