my question is if "THROW" is deprecated then what i have to put instead throw in the following solidity code ?
// This function creates Tokens
function createTokens() payable {
if(isMinting == true){
require(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);
}
else{
throw;
}
}
so the code should look like this:
// This function creates Tokens
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);
}
else{
throw;
}
}
Or i have to delete the
else{
throw;
last update:
function createTokens() payable public {
if(isMinting == true){
require(isMinting, "Not allowed");
require(msg.value > 0, "No funds");
uint256 tokens = msg.value.div(100000000000000).mul(RATE);
balances[msg.sender] = balances[msg.sender].add(tokens);
_totalSupply = _totalSupply.add(tokens);
owner.transfer(msg.value);
}
else{
revert();
}
thanks AK
Best Answer
If you are looking for an alternative of
throw
, you can userevert
in the similar way. Therevert
function can be used to flag an error and revert the current call. As stated in solidity docs :From code point of view, you can use the
require
as below:So if
isMinting
is not equal totrue
, 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