I developed a Dapp in which I am adding attributes to an entity, and finally I have a function to query some of the information about that entity, when I am clicking on the button to execute the function, the information appears for 2-3 seconds and then disappears after that, not sure why this is happening, if anyone can look at the below code and help me troubleshoot this.

Below is the code:

viewrice: function(id){
    var simp;

    then(function(instance) { simp = instance; simp.viewRice.call(id,{from: accounts[0],gas:3000000}).
        $("#riceweight").html(result[3].toNumber()); });    

Click event:

        var id = $("#viewid").val();

HTML front end:

<div class="row">
    <h1 style="text-align: center">View Rice</h1>
    <div style="width: 30%; margin: 25px auto;">
            <div class="form-group">
                <input class="form-control" type="text" name="farmer" id="viewid" placeholder="id">
            <div class="form-group">
                <button class="btn btn-lg btn-primary btn-block" id="viewrice">Submit</button>
            <li>Owner - <span id="riceowner"></span></li>
            <li>Farmer - <span id="ricefarmer"></span></li>
            <li>Status - <span id="ricestatus"></span></li>
            <li>Weight - <span id="riceweight"></span></li>

Smart Contract function:

function viewRice(uint32 _id) public view returns(address owner, address farmer, State status, uint256 weight){
        return (rices[_id].owner, rices[_id].farmer, rices[_id].status, rices[_id].weight);
  • Is the information appearing the same you expect? Also, calling a view function doesn't require gas so you should change .call(id,{from: accounts[0],gas:3000000}) to .call(id)
    – Aniket
    Nov 23, 2018 at 6:18
  • I made the above modifications, but it did not resolve the error. But definitely cleared one of my doubts.
    – Deb
    Nov 23, 2018 at 7:46
  • Answer the question asked in above comment and also paste the error if you getting any. @Deb
    – Aniket
    Nov 23, 2018 at 8:12
  • The information is accurate, is there a way I can share a screencast of the occurring
    – Deb
    Nov 23, 2018 at 9:41
  • @Deb Is the call executed? My guess is the click triggers another event that will override the original call deleting the results. It doesn't seem a blockchain issue but some trouble with javascript rendering.
    – Ismael
    Nov 24, 2018 at 6:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.