Require Function
The require function is a fundamental conditional check used to validate inputs or conditions within a smart contract function. If the provided condition evaluates to false, the require statement reverts the transaction and can optionally return an error message.
It is the most common tool for input validation, ensuring that only authorized users perform actions or that inputs fall within expected ranges. For example, a require statement might check if a user has sufficient balance before allowing a withdrawal or if a price feed is fresh before executing a trade.
It enforces the rules of the protocol and prevents unauthorized or nonsensical operations. Because it consumes gas up to the point of failure, it also discourages spamming invalid transactions.