Skip to main content
added 47 characters in body
Source Link
Aniket
  • 3.5k
  • 2
  • 21
  • 43

If you are looking for an alternative of throw, you can use revert in the similar way. The revert function can be used to flag an error and revert the current call. As stated in solidity docs :

Note

There used to be a keyword called throw with the same semantics as revert() which was deprecated in version 0.4.13 and removed in version 0.5.0.

From code point of view, you can use the require as below:

 function createTokens() payable {
        require(isMinting == true && msg.value > 0);
        uint256  tokens = msg.value.div(100000000000000).mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);
  }

So if isMinting is not equal to true, it will throw straight from there without making any changes in the state.

For more : https://solidity.readthedocs.io/en/v0.5.0/control-structures.html#error-handling-assert-require-revert-and-exceptions

If you are looking for an alternative of throw, you can use revert in the similar way. The revert function can be used to flag an error and revert the current call. As stated in solidity docs :

Note

There used to be a keyword called throw with the same semantics as revert() which was deprecated in version 0.4.13 and removed in version 0.5.0.

From code point of view, you can use the require as below:

        require(isMinting == true && msg.value > 0);
        uint256  tokens = msg.value.div(100000000000000).mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);

So if isMinting is not equal to true, it will throw straight from there without making any changes in the state.

For more : https://solidity.readthedocs.io/en/v0.5.0/control-structures.html#error-handling-assert-require-revert-and-exceptions

If you are looking for an alternative of throw, you can use revert in the similar way. The revert function can be used to flag an error and revert the current call. As stated in solidity docs :

Note

There used to be a keyword called throw with the same semantics as revert() which was deprecated in version 0.4.13 and removed in version 0.5.0.

From code point of view, you can use the require as below:

 function createTokens() payable {
        require(isMinting == true && msg.value > 0);
        uint256  tokens = msg.value.div(100000000000000).mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);
  }

So if isMinting is not equal to true, it will throw straight from there without making any changes in the state.

For more : https://solidity.readthedocs.io/en/v0.5.0/control-structures.html#error-handling-assert-require-revert-and-exceptions

added 757 characters in body
Source Link
Aniket
  • 3.5k
  • 2
  • 21
  • 43

UseIf you are looking for an alternative of throw, you can use revert in the similar way. The revert function can be used to flag an error and revert the current call. As stated in solidity docs :

Note

There used to be a keyword called throw with the same semantics as revert() which was deprecated in version 0.4.13 and removed in version 0.5.0.

From code point of view, you can use the require( as below:

        require(isMinting == true && msg.value > 0);
        uint256  tokens = msg.value.div(100000000000000).mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);

So if isMinting == is not equal to true), if it will be failed, execution will be automatically thrown (stopped)throw straight from there without making any changes in the state.

For more : https://solidity.readthedocs.io/en/v0.5.0/control-structures.html#error-handling-assert-require-revert-and-exceptions

Use require(isMinting == true), if it will be failed, execution will be automatically thrown (stopped).

If you are looking for an alternative of throw, you can use revert in the similar way. The revert function can be used to flag an error and revert the current call. As stated in solidity docs :

Note

There used to be a keyword called throw with the same semantics as revert() which was deprecated in version 0.4.13 and removed in version 0.5.0.

From code point of view, you can use the require as below:

        require(isMinting == true && msg.value > 0);
        uint256  tokens = msg.value.div(100000000000000).mul(RATE);
        balances[msg.sender] = balances[msg.sender].add(tokens);
        _totalSupply = _totalSupply.add(tokens);
        owner.transfer(msg.value);

So if isMinting is not equal to true, it will throw straight from there without making any changes in the state.

For more : https://solidity.readthedocs.io/en/v0.5.0/control-structures.html#error-handling-assert-require-revert-and-exceptions

Source Link
Aniket
  • 3.5k
  • 2
  • 21
  • 43

Use require(isMinting == true), if it will be failed, execution will be automatically thrown (stopped).