I'm developing two contracts:
Tokens : ERC20Burnable Transparent Upgradeable Proxy - contract minting a token 1:1 for each ethers sent.
Machine : Transparent Upgradeable Proxy - contract accepting Tokens as payment. When Tokens are received, Machine instantly burn them and redeem the associated ethers.
So far, so good... Except that I keep getting reverted transaction when trying to burn and redeem.
Here is the buy
function from Machine contract :
function buy(uint _amount) public {
ITokens(tokensContract).burnAndRedeemFrom(
_msgSender(),
_amount
);
emit MachineBuy(_amount, _msgSender());
}
Here is the burnAndRedeemFrom
function from Tokens contract :
function burnAndRedeemFrom(address _from, uint _amount) public {
burnFrom(_from, _amount);
payable(_msgSender()).transfer(_amount);
emit TokensBurn(_amount);
}
I'm sure that Tokens contract has funds. I'm sure that allowance from the address to Machine contract is correct.
Still I keep getting execution reverted?
How are transactions working here? Should the buy
function be payable so the Tokens contract can send ethers?
What am I missing?
Thanks in advance!
buy
doesn't need to bepayable
. Who will receive the Redeemed ether ? the Machine contract or the user who callsbuy
function from Machine contract?