Solidity

:契約尚未部署到檢測到的網路(網路/工件不匹配)嘗試了所有連結但沒有幫助

  • September 13, 2018

我的APP.js程式碼

App = {
 web3Provider: null,
 contracts: {},
 account: 0x0,

 init: function() {
   return App.initWeb3();
 },

 initWeb3: function() {
   web3.eth.defaultAccount=web3.eth.accounts[0]
   // Initialize web3 and set the provider to the testRPC.
   if (typeof web3 !== 'undefined') {
     App.web3Provider = web3.currentProvider;
     web3 = new Web3(web3.currentProvider);
   } else {
     // set the provider you want from Web3.providers
     App.web3Provider = new Web3.providers.HttpProvider('http://localhost:8545');
     web3 = new Web3(App.web3Provider);
   }
   App.displayAccountInfo();
   return App.initContract();
 },

 displayAccountInfo: function() {
   web3.eth.getCoinbase(function(err, account) {
     if (err === null) {
       App.account = account;
       $("#account").text(account);
       web3.eth.getBalance(account, function(err, balance) {
         if (err === null) {
           $("#accountBalance").text(web3.fromWei(balance, "ether") + " ETH");
         }
       });
     }
   });
 },

 initContract: function() {
   $.getJSON('ChainList.json', function(chainListArtifact) {
     // Get the necessary contract artifact file and use it to instantiate a truffle contract abstraction.
     App.contracts.ChainList = TruffleContract(chainListArtifact);

     // Set the provider for our contract.
     App.contracts.ChainList.setProvider(App.web3Provider);

     // Retrieve the article from the smart contract
     return App.reloadArticles();
   });
 },

 reloadArticles: function() {
   // refresh account information because the balance may have changed
   App.displayAccountInfo();

   App.contracts.ChainList.deployed().then(function(instance) {
     return instance.getArticle.call();
   }).then(function(article) {
     if (article[0] == 0x0) {
       // no article
       return;
     }

     // Retrieve and clear the article placeholder
     var articlesRow = $('#articlesRow');
     articlesRow.empty();

     // Retrieve and fill the article template
     var articleTemplate = $('#articleTemplate');
     articleTemplate.find('.panel-title').text(article[1]);
     articleTemplate.find('.article-description').text(article[2]);
     articleTemplate.find('.article-price').text(web3.fromWei(article[3], "ether"));

     var seller = article[0];
     if (seller == App.account) {
       seller = "You";
     }

     articleTemplate.find('.article-seller').text(seller);

     // add this new article
     articlesRow.append(articleTemplate.html());
   }).catch(function(err) {
     console.log(err.message);
   });
 },

 sellArticle: function() {
   // retrieve details of the article
   var _article_name = $("#article_name").val();
   var _description = $("#article_description").val();
   var _price = web3.toWei(parseInt($("#article_price").val() || 0), "ether");

   if ((_article_name.trim() == '') || (_price == 0)) {
     // nothing to sell
     return false;
   }

   App.contracts.ChainList.deployed().then(function(instance) {
     return instance.sellArticle(_article_name, _description, _price, {
       from: App.account,
       gas: 500000
     });
   }).then(function(result) {
     App.reloadArticles();
   }).catch(function(err) {
     console.error(err);
   });
 },
};

$(function() {
 $(window).load(function() {
   App.init();
 });
});

我的 Truffle.js 程式碼

module.exports = {
 networks: {
   development: {
     host: "localhost",
     port: 8545,
     network_id: "*" // Match any network id
   }
 }
};

我試過以下這些沒用

1)我們完全刪除了建構文件夾

並重新執行

> > 松露遷移——重置 > > >

(未成功)

2)我已經用這兩個命令檢查重新編譯和部署沒有用

> > 松露編譯松露遷移 > > >

(沒用)

3)誰能解釋這個錯誤在說什麼?什麼是乙太坊中的文物 沒有幫助我請幫助我

Truffle 的預設開發埠9545

✗ truffle develop
Truffle Develop started at http://127.0.0.1:9545/

Accounts:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
...

為了在本地部署到 Truffle 的開發環境,試試這個:

  • 將 9545 作為development網路埠
  • truffle develop在一個終端中執行
  • 跑進truffle migrate --reset --network development另一個

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