0

I am running a private network and would like to use truffle-contract to interact with the contracts. Unfortunately it gives me this error:

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

I am using truffle-contract@3.0.7 and here is how I set up my code:

const Web3 = require('web3-quorum');
const truffleContract = require('truffle-contract');

const web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:22000'));

const ContractJSON = require('./build/contracts/Contract.json');

var MyContract = truffleContract({
    abi: ContractJSON.abi,
    unlinked_binary: ContractJSON.bin,
    address: ContractJSON.address
});
MyContract.setProvider(web3.currentProvider);

MyContract.deployed().then(function(instance) {  
    return instance.myMethod(
        web3.utils.toHex('31ad646cf39d485d8df7'), 
        Number(100), 
        Number(12345));
}).then(function(result) {
    console.log(result);
}).catch(err => { console.log(err); });

I also tried MyContract.setNetwork(10);, whereby 10 matches net.version output (geth console) or also chainId in the genesis.json. Unfortunately without luck.

  • 1
    Can you try passing the whole artifact file to truffleContract, ie something like var MyContract = truffleContract(ContractJSON). – Ismael Jan 21 at 4:35
1

Passing the whole artifact file to truffleContract make it work, ie something like

...
const ContractJSON = require('./build/contracts/Contract.json');
var MyContract = truffleContract(ContractJSON)
...

Your Answer

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

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