2

I can't get my interface to work on Mist using truffle contract abstraction. After building and testing successfully with Metamask I thought I'd test it on Mist as well and, surprise, it doesn't work. I did some digging and "cut down some trees" to see where the problem is and concluded there is a conflict when using web3.eth.filter and MyContract.deployed() together.

I would be grateful if someone could test the following code to see I'm not the only one with the problem. My setup is truffle v3.4.7 + geth v1.6.6 with rpc.

if (typeof web3 !== 'undefined') {

    web3 = new Web3(web3.currentProvider);
    var filter = web3.eth.filter("latest");
    filter.watch(function(error, result) {
        if (error != null) {
            console.log(error);
            return;
        }
        console.log('new block');
    });

    MyContract.setProvider(web3.currentProvider);
    MyContract.deployed().then(function (value) {
        console.log('contract found!');
    }).catch(function (e) {
        console.log(e);
    });

}

The above gives this error:

Error: MyContract has not been deployed to detected network (network/artifact mismatch)

Did some digging on this and it appears that network_id gets corrupted for a while with some random value like "0x6197b6fe01d72d08b3ddfce26f9fe409" before it takes the right value, like "4" (Rinkeby).

I ended up finding that invoking web3.version.getNetwork before all the code above takes care of this problem but many other errors take its place. I think went a little to far trying to find workarounds for days and I need your help in solving this the right way. Can you think of anything? Thanks.

  • I'm seeing exactly the same problem. The workaround to call web3.version.getNetWork before trying to access deployed contracts seems to work fine here, but obviously thats just ugly. If you found a real solution in the meantime, please update the question. Thanks! – TripleSpeeder Aug 21 '17 at 12:24
  • Well, I stopped using truffle and all the problems went away. I tried getting help on their gitter channel as well but nobody responded. And now that I know how to work without truffle I don't even find it as useful as I did. – Rideron85 Aug 22 '17 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.