14

I try example from book Mastering Ethereum:

contract Faucet {
    function withdraw(uint withdraw_amount) public {
        require(withdraw_amount<=10000000000000000);
        msg.sender.transfer(withdraw_amount);
    }
    function () public payable {}
}

Is error:

Error: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead.
--> Faucet.sol:6:32:
|
6 |     function () public payable {}
|                                ^

Compiler solc is in version 0.7.4. How correct it?

Andrzej
  • 141
  • 1
  • 1
  • 3

1 Answers1

24

instead of using

function() public payable {}

Use

fallback() external payable {}

with latest solidity we dont use function keyword. https://solidity.readthedocs.io/en/v0.7.4/contracts.html#fallback-function

See release of 0.6.0 https://solidity.readthedocs.io/en/v0.7.4/060-breaking-changes.html#semantic-and-syntactic-changes

Ashutosh Singh
  • 351
  • 1
  • 8