[Ethereum] why do we use revert() in payable function

remixrevert-opcodesolidity

I have seen this snippet in many online examples could you please explain what this is doing and why are we using it in a payable function?

function () public payable {
   revert () ; 
}   

Best Answer

The function without a name: function () is called the fallback function. It is executed when the contract receives some ETH without a function being explicitly called.

Putting revert(); in it means that you cannot send ETH to the contract without explicitly calling a payable function.

Related Topic