I'm learning solidity on remix. I was following some tutorial video on youtube and I've got stuck trying to build 2 contracts. contract ERC20Token has function which increases balances. And Mycontract instantiates and call the mint function. I did it the same way as the guy on youtube did, but I ran into error saying when I call buyToken function. The error is saying
transact to MyContract.buyToken errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
Please help me out.
Here is the code.
pragma solidity 0.5.1;
contract ERC20Token{
string public name;
mapping(address => uint256) public balances;
function mint() public {
balances[tx.origin] ++;
}
}
contract MyContract {
address payable wallet;
address public token;
constructor(address payable _wallet, address _token) public {
wallet = _wallet;
token = _token;
}
function buyToken() public payable {
ERC20Token _token = ERC20Token(address(token));
_token.mint();
wallet.transfer(msg.value);
}
}