In case people send ERC20 tokens to my contract, I want to be able to retrieve them. Hence the following function:
/**
* @dev Allows owner to transfer ERC20 tokens to vault
* @param _token the contract address of the ERC20 contract
*/
function retrieveTokens(address _token) public onlyOwner {
ERC20 erctoken = ERC20(_token);
erctoken.transfer(Vault, erctoken.balanceOf(this));
}
On Ropsten testnet, I successfully sent some tokens to the contract. Then I run the above, but it fails. (It used very little gas and did not run out. I entered a gas limit of 6000000, which was much more than needed.)
In remix.ethereum.org (with Injected Web3), I get the following error:
transact to browser/Test.sol:TestSale.retrieveTokens errored: Gas required exceeds limit: 4000000. An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation).
In remix.ethereum.org (with Javascript VM), I'm getting the following error:
from:0xca3...a733c, to:broswer/Test.sol:TestSale.retrieveTokens(address) 0x643...62e55, value:0 wei, data:0xac4...95963, 0 logs, hash:0xe76...c0094
transact to browser/Test.sol:TestSale.retrieveTokens errored: VM error: invalid opcode. The constructor should be payable if you send value. The execution might have thrown. Debug the transaction to get more information.
How do I fix this? I'm not sending any value when I call this transaction.
I copied the code from TenX and modified it for my Solidity smart contracts. You can see all of my code at https://gist.github.com/anonymous/3497e6b4e09953a009a4fdbacd11946a