Solidity version is 0.5.1 the buyTokens function works fine when i call it directly from myetherwallet or remix, but it does not work when i send some ether to address. I think it doesn't even call the fallback function.

the buyTokens function is an public payable function

function () external payable {
  • Fallback functions cannot do that, the gas spent in a function is limited to a very small gas amount
    – Majd TL
    Apr 20, 2021 at 20:19
  • You can use function buytoken() external payable without the fallback function
    – Majd TL
    Apr 20, 2021 at 20:20

1 Answer 1


A fallback function is invoked when the contract receives some Ether(or a non existent function is called) but the gas provided is only enough so as to emit a event if called using transfer or send . You can use call and specify the amount of gas if you want to execute any function inside the fallback. You can refer to this link https://solidity-by-example.org/sending-ether/

Your Answer

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

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