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.

2 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.

It is preferable to use If because it is gas efficient.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.