5

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?

0
10

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.