Linked Questions
18 questions linked to/from Difference between require and assert and the difference between revert and throw
-1
votes
1answer
1k views
revert,assert,require,throw what is the difference? [duplicate]
Who can tell me what is the difference between revert,assert,require,throw!
130
votes
2answers
26k 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 ...
19
votes
6answers
16k 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 ...
25
votes
4answers
4k 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?
38
votes
2answers
12k 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 ...
3
votes
3answers
4k 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 ...
7
votes
1answer
2k 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 ...
7
votes
3answers
849 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 ...
2
votes
3answers
465 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
2answers
723 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
2answers
449 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? Use require to refund gas seems always a better choice than consuming them?
I saw ...
3
votes
1answer
543 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 ...
4
votes
1answer
404 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
0answers
801 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()".
...
0
votes
1answer
259 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 ...