# Getting “VM Exception while executing eth_call: invalid opcode”

I have a very basic contract to test out some functionality, but when I call the functions getContractAddress() and getThrowaway(), I get the invalid opcode error. I'm using truffle and testrpc, and I get the error after running some commands in truffle console (below).

Here is the full contract in question:

pragma solidity ^0.4.4;

import "./MetaCoin.sol";

contract Guess {

// Constructor, gives this contract 10k coins
function Guess(){
MetaCoin metaCoin = new MetaCoin(); //I think this should give the contract 10k coins
}

return this;
}

function getThrowaway() constant returns (string){
return "Hello";
}

}


And here are the commands I'm running in truffle console.

guess = Guess.deployed();
guess.then(function(instance){return instance.getThrowaway.call();})


Same problem when I run getContractAddress().

Here is the full repo for reference: https://github.com/willikers19/GuessTheEth

When I run commands in a similar fashion from this contract (https://github.com/willikers19/ethereum-demo-tools/blob/master/GeektSolidity/contracts/Geekt.sol), they succeed so it feels like I'm doing something wrong.

• After restarting my computer and picking this up again the next day, I found that the answer from Rob Hitchens worked! I then tried my inputs again to see what I was doing wrong and I found that my inputs worked too... I think the issue stems from not restarting testrpc between truffle migrations. – wtk219 Jun 20 '17 at 14:24
• I'm having the same problem as you (with a similar set up). Just testing throwaway calls I get invalid opcode. However if i shut down my testrpc and start it back up and migrate my contract fresh the calls all work. Why would this be happening? Does truffle migrate still need to be confirmed by the network? – okwme Aug 10 '17 at 17:15

Try:

var guess;
Guess.deployed()
.then(function(instance) {
guess = instance;
})
.then(function(response) {
console.log("Response:", response);
});


Hope it helps.

• After restarting my computer and picking this back up the next morning, I find that your solution works, but when I tried my console inputs again, so did mine... So I guess the real fix was to restart my computer. Thanks for your (somewhat indirect) help! – wtk219 Jun 20 '17 at 13:03

You not only need to run:

truffle migrate


But before you do it, you need to edit the migration script in which you specify which contracts migrate to the blockchain. Check here.

Cheers