I've minted a token and given one of my dummy accounts all of the balance. It shows in Metamask as received.
I then created a contract that I want to work as a delegate contract to use TransferFrom - called Market Exchange for example.
I approve the Market Exchange address and that goes through.
When I try to call TransferFrom - from the Owner contract I get the error that I don't have enough tokens to transfer.
I've taken inspiration from this solution by abcoathup
and still can't get Remix to work. Where am I being Dumb here thank you.
Code to reproduce
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
address public admin;
constructor() ERC20('Cally Token', 'POP') {
admin = 0x492980696aBD3129a22770C1f14FFB3E2E7299bf;
_mint(admin, 10000 * 10 ** 18);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import './Token.sol';
contract MarketEx {
address public tokenAddress = 0x552b4b432BcEA755dE362031c1f2D781c057C75E;
function delegateTransfer(address recipient, uint256 amount) external {
Token token = Token(tokenAddress);
token.transferFrom(msg.sender, recipient, amount);
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import './Token.sol';
import './MarketEx.sol';
contract Owner {
function approveOtherContract(ERC20 token, address marketExchange, uint256 amount) external {
token.approve(marketExchange, amount);
}
function sendTokens(MarketEx marketExchange, address recipient, uint256 amount) external {
marketExchange.delegateTransfer(recipient, amount);
}
}
Environment
Remix.
Gas estimation errored with the following message (see below).
The transaction execution will likely fail. Do you want to force sending?
execution reverted: ERC20: transfer amount exceeds balance { "originalError": { "code": 3, "data": "0x08c3.....", "message": "execution reverted: ERC20: transfer amount exceeds balance" } }