60262186
Lok Sze Decoration Engineering Limited
Flat C7, 5/F, Tung Lee Factory Building, 9 Lai Yip Street, Kwun Tong, Kowloon

  • 中文 (香港)
  • English
  • Ethereum: What is the difference between transaction revert and status:0?

    Understanding Ethereum Transaction Reverts and Status:0

    Ethereum’s transaction system is designed to handle errors that occur during the execution of smart contracts. Two critical concepts in this context are transaction revert and status: 0. In this article, we’ll delve into what these terms mean, how they differ, and when you might encounter one or both of them.

    Ethereum: What is the difference between transaction revert and status:0?

    Transaction Revert

    A transaction revert occurs when an error is encountered during the execution of a smart contract. This can happen due to various reasons such as:

    • Out-of-gas (OOG) errors

    • Gas exhaustion (GE)

    • Invalid gas prices

    • Non-fatal reverts (NFR)

    When a revert occurs, Ethereum’s gasless system automatically aborts the transaction and returns an error message to the contract. The transaction revert status is then reflected in the blockchain as status: 0.

    Status:0

    Status:0 refers to the block number where the reverted transaction occurred. It is essentially a timestamp for that specific block.

    Here’s a simple example of how this works:

    pragma solidity ^0.8.0;

    contract RevertExample {

    function doSomething() public {

    // Do something

    }

    function revertSomething() public {

    // If we want to manually trigger a revert, we can use the following code:

    revert doSomething();

    }

    }

    In this example, if an error is encountered during doSomething, Ethereum will automatically abort the transaction and return an error message. The status: 0 field will then be set to represent the block number where the reverted transaction occurred.

    Key Differences

    • Error Type: Reverts are errors that occur during contract execution, whereas status:0 indicates a block number.

    • Revert Handling: When an error occurs, Ethereum’s gasless system aborts the transaction and returns an error message. In contrast, status: 0 does not indicate any error but rather represents the timestamp for the reverted transaction.

    Best Practices

    When writing smart contracts on the Ethereum platform, it’s essential to handle reverts properly:

    • Use abi.revert() instead of revertSomething().

    • Handle reverts within your contract functions or in separate contract storage.

    • Be aware of gas exhaustion and invalid gas prices that can lead to OOG errors.

    By understanding the difference between transaction revert and status:0, you’ll be better equipped to handle errors and optimize your smart contracts for efficient deployment on Ethereum.