0

How can I execute methods in receive?

receive() external  payable{
   address _userAddress = msg.sender;
   uint256 _amount = msg.value;
   weth.deposit{value: msg.value}();
   if(_amount>5){
       myFoo1(_userAddress, _amount);
   }
   else{
       myFoo2(_userAddress, _amount);
   }
}

When I try like that code block, I'm getting this error: The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance." is error but I have enough balance and as you see function is payable

6
  • 2
    You're not including the exact error message and we cannot guess what is wrong with your code. You're also not including the full contract code, share it here if you want someone to help you. Jul 12 at 10:24
  • "The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance." is error but I have enough balance and as you see function is payable. @MiroslavNedelchev Jul 12 at 10:26
  • 2
    Does this answer your question? What is the receive keyword in solidity? Jul 12 at 10:27
  • No it does not. My question is - If someone send ether to my contract my contract should execute other functions. I mean trigger functions with receive- @PaulRazvanBerg Jul 12 at 10:39
  • Is the question then how to implement an if block? I don't see how that other thread doesn't answer everything there is know about the "receive" function, including how to get hold of the amount of the ETH transferred. Jul 12 at 10:41

Your Answer

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

Browse other questions tagged or ask your own question.