Linked Questions
20 questions linked to/from Difference between require and assert and the difference between revert and throw
-1
votes
1
answer
1k
views
revert,assert,require,throw what is the difference? [duplicate]
Who can tell me what is the difference between revert,assert,require,throw!
174
votes
4
answers
47k
views
Are there well-solved and simple storage patterns for Solidity?
Simple and appropriate data organization can challenge Solidity newcomers. It wants us to organize everything in ways many of us aren’t accustomed to.
Are there well-solved general patterns for ...
30
votes
6
answers
32k
views
Solidity: How can we write a error message in "require"?
Im learning Solidity. As far as I'm aware, it's recommended using "require" to handle errors. But, I'd like to inform the users about the kind of errors they make, e.g. an argument is invalid or out ...
27
votes
4
answers
6k
views
Why does a Solidity throw consume all gas?
When you throw an exception, all gas is consumed. What is the rationale for this design decision?
40
votes
2
answers
19k
views
How do I detect a failed transaction after the Byzantium fork as the REVERT opcode does not consume all gas?
Pre Byzantium fork, I could use gas == gasUsed to detect when a transaction has failed (further details in How can the transaction status from a thrown error be detected when gas can be exactly the ...
10
votes
1
answer
6k
views
Will revert() refund all gas of the transaction or just the remaining gas?
According to the docs revert() will not consume any gas:
Note that assert-style exceptions consume all gas available to the call, while revert-style exceptions will not consume any gas starting ...
11
votes
3
answers
3k
views
What’s the point of checking msg.sender≠0 ? Are there cases where msg.sender can be null?
In the Tron contract (a large ICO listed on many exchanges) lies this modifier which is used for all token transfers :
modifier validAddress {
assert(0x0 != msg.sender);
_;
}
I understand ...
3
votes
3
answers
5k
views
how do I loop through a mapping of address to struct
I have a mapping where the key is the artist name, the value is msg.sender address. In a function, I want to check if the parameter username has already existed in the mapping keys, if yes, i will ...
6
votes
4
answers
1k
views
Why using assert, since it would consume all gas
Since assert would consume all gas and require would return all gas, is there any reason to use assert not require? Using require to refund gas seems always a better choice than consuming them?
I saw ...
2
votes
3
answers
513
views
Formal verification example
I am currently taking a look at the slides from this presentation
I suppose the question is less with formal verification and more with solidity. Can some one help me understand what can possibly go ...
2
votes
2
answers
879
views
Function to Retrieve Tokens from Contract fails
In case people send ERC20 tokens to my contract, I want to be able to retrieve them. Hence the following function:
/**
* @dev Allows owner to transfer ERC20 tokens to vault
* @param _token the ...
3
votes
1
answer
991
views
What is the advantage of using require instead of return or revert for error handling?
As is well documented, require is preferred over assert for error conditions, eg. Difference between require and assert and the difference between revert and throw
Solidity might someday include the ...
3
votes
2
answers
438
views
The "revert CustomError()" behavior shouldn't be the same as "require(falseCondition)"?
Based on this article at Solidity blog about Custom Errors, I've understood that this recent Solidity feature Custom Errors would behavior in the same way as a failed condition in require statement, ...
4
votes
1
answer
444
views
Will existing contracts behave differently when REVERT is implemented by Metropolis?
Solidity v0.4.10 introduced the revert() and require() functions, along with support for the REVERT opcode. As far as I can tell, this means that any contract compiled using ^0.4.10 will express ...
1
vote
0
answers
896
views
How do I fix this compile error: "throw" is deprecated in favour of "revert()", "require()" and "assert()"?
I've just downloaded Mist 0.9.0 and I tried to compile a new contract but it does not let me do it with this error:
"throw" is deprecated in favour of "revert()", "require()" and "assert()".
...
1
vote
1
answer
477
views
Can I add a modifier in a function inheriting from the interface?
Let's consider this situation:
interface ITest
{
function check()
external;
}
contract Test is ITest
{
address private admin;
constructor()
public
{
admin = ...
0
votes
1
answer
274
views
Adding address to Struct's array of addresses does not persist
I'm having trouble getting the array of "watchers" to persist after I:
Deploy the contract
Create Magic with name "test1"
Execute watchMagic (with test1's magic id)
Execute watchMagic (with test1's ...
1
vote
1
answer
162
views
Is there anyway a smart contract creator can put a limit on the gasPrice(gwei) for a transaction?
I am looking at the possibility of creating a custom token on the Ethereum network & wanted to know if there is a way if i can put an limit on the gasPrice in order to prevent the so called "gas ...
2
votes
2
answers
46
views
Change value if function parameter is not zero
I have this function.
How do I change only the parameters that aren't zero when calling the function? This is what I did
function changeParameters(uint newAnte, uint8 newNumberOfPlayers, uint ...
1
vote
0
answers
17
views
What's the point of 'assert'? Can't i just use 'require' all the time? [duplicate]
I read this stackexchange post and understood the difference between 'assert' and 'require'.
But it got me thinking, what even is the point of 'assert'? I mean it has same the behaviour as 'require' ...