Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "require" and "if" statement in a solidity smart contract

Require is an error handling global function in solidity which is basically operates in the manner that if the condition within require comes out to be true then the compiler will execute the piece of code written beneath it. However the general logical statement if also serves the same purpose within solidity, so wanted to know if there is a difference b/w both of these.

like image 904
muhammad hannan Avatar asked Nov 01 '25 06:11

muhammad hannan


1 Answers

The difference is that require() is an error handling statement like you had stated, but if this statement fails, the transaction is reverted. Whereas if you had an if else statement, you would have to make sure to revert the transaction yourself.

like image 61
Michael Avatar answered Nov 04 '25 12:11

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!