1

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;
    Rice.deployed().

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

Click event:

    $("#viewrice").click(function(){
        var id = $("#viewid").val();
        App.viewrice(id);
    })

HTML front end:

<div class="row">
    <h1 style="text-align: center">View Rice</h1>
    <div style="width: 30%; margin: 25px auto;">
        <form>
            <div class="form-group">
                <input class="form-control" type="text" name="farmer" id="viewid" placeholder="id">
            </div>
            <div class="form-group">
                <button class="btn btn-lg btn-primary btn-block" id="viewrice">Submit</button>
            </div>
        </form>
        <ul>
            <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>
        </ul>
    </div>
</div>

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 '18 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 '18 at 7:46
  • Answer the question asked in above comment and also paste the error if you getting any. @Deb – Aniket Nov 23 '18 at 8:12
  • The information is accurate, is there a way I can share a screencast of the occurring – Deb Nov 23 '18 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 '18 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.