Who can tell me what is the difference between revert,assert,require,throw!

  • It's always better to mention your findings when you ask a question which might lead to get an answer on where you need the exact clarification. This question shows no effort at all. Aug 29, 2017 at 14:03

1 Answer 1


Throw is the old mechanism for reverting the state of the current call (and all its sub-calls)

From version 0.4.13 the throw keyword is deprecated and will be phased out in the future.

Revert is the new, preferred mechanism for reverting a call

The revert function can be used to flag an error and revert the current call.

As for assert and require:

The convenience functions assert and require can be used to check for conditions

The difference between them being


The assert function should only be used to test for internal errors and to check invariants


The require function should be used to ensure valid conditions, such as inputs, or contract state variables are met, or to validate return values from calls to external contracts


contract Sharer {
    function sendHalf(address addr) payable returns (uint balance) {
        require(msg.value % 2 == 0); // Only allow even numbers
        uint balanceBeforeTransfer = this.balance;
        addr.transfer(msg.value / 2);
        // Since transfer throws an exception on failure and
        // cannot call back here, there should be no way for us to
        // still have half of the money.
        assert(this.balance == balanceBeforeTransfer - msg.value / 2);
        return this.balance;

Source: Solidity documentation

Not the answer you're looking for? Browse other questions tagged or ask your own question.