2

I’m guessing there is an obvious answer to this question but I’m just completely missing the point. I have a very simple contract with 2 functions: a setter that changes a bunch of fields, and a constant getter that returns those fields. And I have a javascript application that interacts with that contract using truffle-contract. Behind the scenes, my contract is deployed to testrpc. When I submit a form, I’m calling my setter and in the then block, I’m calling my getter to update the page. I’m assuming that, as said in the doc, the then block is only executed once the transaction has been mined. Now when I run my app in a browser with Metamask disabled, connecting directly to my node with web3, everything works smoothly, no need to refresh the page to see the result once the transaction has been sent. But with Metamask, once I click submit, the call to the getter retrieves nothing, and I have to reload the page and trigger the getter again to get data. Is that because of a problem in the behavior of testrpc? Does that ring a bell to anybody?

Here is the contract:

pragma solidity ^0.4.11;

contract ChainList {
    // State variables
    address seller;
    string name;
    string description;
    uint256 price;

    // sell an article
    function sellArticle(string _name, string _description, uint256 _price) public {
        seller = msg.sender;
        name = _name;
        description = _description;
        price = _price;
    }

    // get the article
    function getArticle() public constant returns (
        address _seller,
        string _name,
        string _description,
        uint256 _price) {
        return(seller, name, description, price);
    }
}

And here is the JS code that calls it:

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

if you try something like this in javascript? (per state variable)

contract.statevariable(function(err, result) {
    $("#htmlelement").html(result);
});
1

It could be that your MetaMask is not connected to your TestRPC instance. When you open MetaMask, you would have to click the top-left "provider menu" that says "Main Ethereum Network" and select "Localhost 8545", or if you configured TestRPC differently, "Custom RPC".

  • No no, I guarantee you MetaMask is connecting to my testrpc. Which is confirmed as I reload the page and see the right information. – Sebastien Aug 17 '17 at 18:27

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.