Hi all,
I’am trying to receive Ether via a normal external payable function but it does not run at all. I have tried many permutations, “public payable”, call within receive() function or within the fallback() function. But I cannot execute my external payable buy() function.
The receive() and fallback() functions work well to receive Ether, but for some reason my external payable function does not get executed.
Any help is very much appreciated as the project is heavily delayed by this problem.
Here is the basic framework of my contract:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import “@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol”;
import “@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol”;
import “@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol”;
import “@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol”;
contract myContract is Initializable, ContextUpgradeable
{
uint256 public stage;
function initialize(param1, param2, …) public virtual initializer
{
__Context_init_unchained(); // Run the initializer of ContextUpgradeable.
}
function buy() external payable
{
stage = 1;
}
receive() external payable
{
}
}
I use the openzeppelin upgradeable contracts deploy procedure to deploy this contract. I can access the stage variable and the other getter functions well via the transparentProxy.
I used MetaMask to transfer Ether when the buy() is called via receive() or fallback().
I used web3.eth.accounts.signTransaction() and web3.eth.sendSignedTransaction(), to directly transfer Ether to buy().
However, the stage variable does not get set to 1 at all.
I’am using solidity compiler 0.8.6 on ubuntu Linux and truffle to migrate.
Best Regards
Configentia