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

function getContractAddress() constant returns (address){
    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
    Commented Jun 20, 2017 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
    Commented Aug 10, 2017 at 17:15

2 Answers 2



var guess;
.then(function(instance) {
  guess = instance;
  return guess.getContractAddress.call()
.then(function(response) {
  console.log("Response:", response);

Hope it helps.

  • 1
    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
    Commented Jun 20, 2017 at 13:03
  • Not working for me, make truffle crash with the same error "VM Exception while processing transaction: invalid opcode "
    – btc4cash
    Commented Jan 28, 2020 at 17:59
  • var MillionMoneyInstance; MillionMoney.deployed() .then(function(instance) { MillionMoneyInstance = instance; return MillionMoneyInstance.ownerWallet.call() }) .then(function(response) { console.log("Response:", response); });
    – btc4cash
    Commented Jan 28, 2020 at 18:00
  • You should post that as a new question with details about what you did before and during the test. The original poster was on a certain step but your situation is less clear. Commented Jan 28, 2020 at 20:02

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.