I have a standard ERC20 token contract with minting functions:
pragma solidity ^0.4.11;
import "./Stake.sol";
import "./Mint.sol";
contract Token is Stake, Mint {
//omitted standard ERC20 text
}
The minting contract that this inherits from is the following:
pragma solidity ^0.4.11;
import "./BaseToken.sol";
contract Mint is BaseToken {
// Mint state
address public centralMinter;
uint256 public totalMinted;
// modifer
modifier onlyMinter {
if (msg.sender != centralMinter) revert();
_;
}
function Mint() {
// constructor
}
function mint(address _to, uint256 _amountToMint) onlyMinter() {
balances[_to] += _amountToMint;
totalSupply += _amountToMint;
Transfer(this, _to, _amountToMint);
}
}
Now, I have a Relay
contract that inherits Token
:
pragma solidity ^0.4.11;
import "./Token.sol";
contract Relay is Token {
uint256 public approvalCount;
function Relay() {
// constructor
}
modifier onlyOwner {
if (msg.sender != owner) revert();
_;
}
function approveTransaction() {
approvalCount += 1;
if (approvalCount == 3) {
mint(msg.sender, 1);
kill();
}
}
function kill() onlyOwner() {
selfdestruct(owner);
}
}
This Relay
contract gets created by a separate contract. I run through everything in the truffle console and on the 3rd approveTransaction
call I get the following:
truffle(development)> relay.approveTransaction()
Error: VM Exception while processing transaction: invalid opcode
at Object.InvalidResponse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:37312:16)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:220420:36
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:204149:9
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:205574:13)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:73069:18)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:73359:12)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:73514:12)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:73474:24)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
Not really sure why this is happening. At first I thought it was because of the onlyMinter
, but that wasn't it. The minted tokens are supposed to go to some arbitrary address. Any ideas? Thank you.