Web3js Truffle – Contract Has Not Been Deployed to Detected Network

meteortruffleweb3js

Why can't deployed contract be found?

My node:

admin.nodeInfo
{
  ...,
  protocols: {
    eth: {
      difficulty: 36521801351,
      genesis: "...",
      head: "...",
      network: 3
    }
  }
}

network 3 from truffle networks:

Network: development (id: 3)
  Migrations: 0xfa79df82dce04e1a894df648f4f20af5a59f42f8
  WhaleNetworkV2: 0x93e21793323f9d3053b6a2bd2ab4234948aec210

in compiled contracts json file:

"networks": {
    "3": {
      "events": {},
      "links": {},
      "address": "0x93e21793323f9d3053b6a2bd2ab4234948aec210"
    }
  }

The code from which this error comes from:

if (typeof web3 !== 'undefined') {
    web3 = new Web3(web3.currentProvider);
} else {
    // set the provider you want from Web3.providers
    web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

console.log("provider", web3.currentProvider);

whaleNetworkV2 = contract(WhaleNetwork);
whaleNetworkV2.setProvider(web3.currentProvider);

whaleRewardsV2 = contract(WhaleRewards);
whaleRewardsV2.setProvider(web3.currentProvider);

let whaleNetworkContract;
let whaleRewardContract;

web3.eth.getAccounts((err, accounts) => {
    if (err != null) {
        console.log("There was an error fetching your accounts.");
        return;
    }

    if (accounts.length == 0) {
        console.log("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
        return;
    }

    whaleRewardsV2.deployed().then((result) => {
        console.log(result);
    }).catch((error) => {
        console.log("whaleRewardsV2", error);
    });
});

The above code outputs:

provider HttpProvider {host: "http://localhost:8545", timeout: 0,
connected: false} contracts.js:38 whaleRewardsV2 Error: WhaleRewardsV2
has not been deployed to detected network (network/artifact mismatch)
at modules.js?hash=d495843d4bdb24e9ee23d52d143d36f9c62487b7:14057
at meteor.js?hash=cbcc712d51de4298c275e8dcf25c66c29914f19a:1167
at

Happens on both server and client.

Best Answer

I found my problem was that the metamask was on the wrong network