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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael