Hi everyone !
I am trying to create 2 smart contracts : one for an ERC20 and the other for an ERC721. What I want to do now is to buy a token of ERC721 by sending ERC20 amount to the seller balance.
The problem is really simple : When I call the transfer() fonction from the ERC721 contract with token.transfer(), I have the error “ERC20: transfer amount exceeds balance”.
When I looked on the forum, people had the same issue, and the solution was to use transferFrom() instead of transfer().
But the error I got was “ERC20: transfer amount exceeds allowance”.
I tried giving allowance to the contract address (because I think the caller is the contract) and I still got this error.
I am using ERC20 and ERC721 OpenZeppelin contracts on Remix, with version 0.8.0 of Solidity.
contract TokenTransfer is ERC721 {
function transfer() external {
Token token = Token(0xd9145CCE52D386f254917e481eB44e9943F39138);
token.transfer(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2, 150);
}
}
0xd9145CCE52D386f254917e481eB44e9943F39138 : address of the contract “Token”.
0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 : an address not owning RMN (not the caller).
contract Token is ERC20 {
constructor(uint256 initialSupply) ERC20("RAMEN TOKEN", "RMN") {
_mint(msg.sender, initialSupply);
}
}
I tried to only provide the relevant code for my issue.
Thanks for your help !