I am facing an issue and I can't figure what's going wrong.
It is a very simple scenario:
A smart-contract, that implements ERC20 and ERC20Mintable from OpenZeppelin.
pragma solidity ^0.5.0;
import "./openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "./openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
contract MyToken is ERC20, ERC20Mintable {}
Another smart-contract that received some MyToken.
pragma solidity ^0.5.0;
import "./MyToken.sol";
contract TokenInteraction {
address public tokenAddress;
constructor(address _tokenAdd) public {
tokenAddress = _tokenAdd;
}
function transferToken(address to) public {
MyToken myToken = MyToken(tokenAddress);
myToken.transfer(to, 1);
}
}
I checked that TokenInteraction has more than one token, but when I call transferToken
the transaction revert
.
I don't understand what's happening.
Many thanks for you help!
EDIT :
Concerning the deployment and the testing methodology, I use Remix IDE on localhost and I deploy on Ganache running locally. To test it, I just mint a token to TokenInteraction and then try to call transferToken to another address
Best Answer
I successfully transferred token with your code. I guess the reason why you encountered problem was a mis-setup at deployment. Please try out the following procedure with Remix IDE to see if it works for you.
Deployment
MyToken
contractTokenInteraction
and pass the address copied at step 2 to the constructor.TokenInteraction
contract is deployed, check iftokenAddress
matches the address got from step 2Mint tokens to
TokenInteraction
contractTokenInteraction
contract.MyToken
contract) and call themint
function with the address from the previous step as well as the amount.balanceOf
function to verify everything is good.Transfer tokens to another address
Pass the recipient address when calling
transferToken
ofTokenInteraction
contract.Verify Results
Check the balance of the recipient and that of the
TokenInteraction
contract.