0

my APP.js code

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

My Truffle.js code

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

i Tried following thigs no use

1) we deleted the build folder completly and

and rerun the

truffle migrate --reset

(not succeded )

2) I have used the two commands to check for re compile and deploy no use

truffle compile truffle migrate

(no use)

3) Can anyone explain what this error is saying ? what are artifacts in etherium nothing helped me plese help me

  • 1
    Hi Venkatesh! To get a potentially more complete answer, please share your deployment code from migrations folder. – Utgarda Sep 13 '18 at 15:38
1

Truffle's default development port is 9545, like in

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

Accounts:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
...

In order to deploy locally to Truffle's development environment, try this:

  • put 9545 as your port for development network
  • run truffle develop in one terminal
  • run truffle migrate --reset --network development in another one
  • HI I am using testrpc for first testing it is mentioned it is listing to the port 8545 after running testrpc command Now if i change the port in the truffle it may cause some issue I think Plese help – Venkatesh Muthyala Sep 14 '18 at 9:33
  • No probs, we'll get to the bottom of it. But please first try the method described above. – Utgarda Sep 14 '18 at 9:39
  • I tried but it is saying rpc error now If you don't mind i will give the github link can you downlad and deploy once using testrpc github.com/chainskills/chainlist/releases/tag/… – Venkatesh Muthyala Sep 14 '18 at 10:16
  • Please try describing your trial and error here to let others understand what's happening on your side and come up with a solution collectively - a bit more than "rpc error" could be helpful. It's not like you can say "oh, it doesn't work, go check my code guys" and chill. Well, you can, but it's not the way of StackExchange. Your input is expected to be definitely no less than that from other praticipants, if you want the problem solved. Just tried deploying your code to truffle development network - it's fine, just change the port to 9545. – Utgarda Sep 15 '18 at 16:17
  • Thanks It worked while using metamask and only truffle – Venkatesh Muthyala Sep 17 '18 at 6:46

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.