1
receive() external payable {
    fund();
}
fallback() external payable {
    fund();

I want to find out where exactly should these special functions be wrriten; should they come before the contract or at the tail end of the contract and why. I appreciate your comments.

1 Answer 1

2

You can technically place these special functions anywhere in your contract without any issues.

However, if you want to follow the Solidity style guide as referenced in the documentation, these functions should directly follow the constructor before any other functions:

Order of Functions: Ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier.

Functions should be grouped according to their visibility and ordered:

constructor

receive function (if exists)

fallback function (if exists)

external

public

internal

private

1
  • 1
    Thanks for the answer, it was really helpful. Sep 20 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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