Web3js

合約尚未部署到檢測到的網路(網路/工件不匹配)

  • November 1, 2021

為什麼找不到已部署的合約?

我的節點:

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

網路 3 來自truffle networks

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

在編譯的契約 json 文件中:

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

此錯誤來自的程式碼:

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

上面的程式碼輸出:

provider HttpProvider {host: " http://localhost:8545 “, timeout: 0, connected: false}contracts.js:38whaleRewardsV2 錯誤:WhaleRewardsV2 尚未部署到 modules.js 處檢測到的網路(網路/工件不匹配)?雜湊=d495843d4bdb24e9ee23d52d143d36f9c62487b7:14057 at meteor.js?hash=cbcc712d51de4298c275e8dcf25c66c29914f19a:1167 at

發生在伺服器和客戶端上。

我在我的 truffle.js 中失去了from密鑰,即使看起來它們已正確部署,也會導致收到此消息。

我發現我的問題是元遮罩在錯誤的網路上

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