Contract-Invocation

松露契約:契約尚未部署到檢測到的網路(網路/工件不匹配)

  • January 22, 2019

我正在執行一個專用網路,並希望用於truffle-contract與契約進行互動。不幸的是,它給了我這個錯誤:

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

我正在使用truffle-contract@3.0.7,這是我設置程式碼的方式:

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); });

我也嘗試過MyContract.setNetwork(10);,其中 10 個匹配net.version輸出(geth 控制台)或 genesis.json 中的 chainId。不幸的是沒有運氣。

傳遞整個工件文件以truffleContract使其工作,即類似

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

引用自:https://ethereum.stackexchange.com/questions/65865