Fund:0.012 ETH / $6.94
Question is solved

What is the difference between Solidity’s “require()” and “assert()”?

1 month ago

I don’t understand why Solidity has both require and assert. I come from a JavaScript background and they seem to be very similar if not the exact same. What is the difference if any?


The most clear difference is the gas efficiencies.

“require” if false will return to you the remaining gas. This is very advantageous incase you are deploying a large contract and a beginning require statement is false. The remaining gas that you paid would be returned to the wallet that initially paid it. Any gas already spent will be unrecoverable as it has already been paid to miners.

“assert” will not return the remaining gas if it encounters a falsy (ex. assert(false)). It will use up the full gas balance and revert all changes because it did not complete.

There is a second difference that has to do with how they are actually compiled but it is very minor and shouldn't effect your code.
1 month ago

Your question is successfully refund. You will be redirect in few seconds.