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

Majd TL
  • 3,217
  • 3
  • 17
  • 36
  • 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. – Miroslav Nedelchev Jul 12 '21 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 – Condensator Jul 12 '21 at 10:26
  • 2
  • 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 – Condensator Jul 12 '21 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. – Paul Razvan Berg Jul 12 '21 at 10:41
  • @furkankaya What are myFoo1, myFoo2? How are you sending ether to the contract? from an EOA or a contract. Sending from a contract using transfer or send it has a 2300 gas stipend limit. Sending from an EOA should work fine. – Ismael Jul 15 '21 at 05:11

0 Answers0