Linked Questions

-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!
user17314's user avatar
  • 303
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 ...
Rob Hitchens's user avatar
  • 55.6k
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 ...
Aydin's user avatar
  • 2,117
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?
Peter Hall's user avatar
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 ...
BokkyPooBah's user avatar
  • 40.4k
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 ...
TripleSpeeder's user avatar
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 ...
user2284570's user avatar
  • 1,029
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 ...
terence tsao's user avatar
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 ...
Ilake Chang's user avatar
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 ...
Bobo's user avatar
  • 244
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 ...
Curt's user avatar
  • 307
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 ...
jordanpg's user avatar
  • 195
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, ...
Fabiano's user avatar
  • 303
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 ...
maurelian's user avatar
  • 3,251
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()". ...
NineCattoRules's user avatar

15 30 50 per page