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

  init: function() {
    // Load pets.
    return App.initWeb3();

  initWeb3: function() {
    if (typeof web3 !== 'undefined') {
      // If a web3 instance is already provided by Meta Mask.
      App.web3Provider = web3.currentProvider;
      web3 = new Web3(web3.currentProvider);
    } else {
      // Specify default instance if no web3 instance provided
      App.web3Provider = new Web3.providers.HttpProvider('http://localhost:7545');
      web3 = new Web3(App.web3Provider);

    return App.initContract();

  initContract: function() {
    $.getJSON("adding.json", function(addingdappfrontend) {

      App.contracts.Add = TruffleContract(addingdappfrontend);

      // we have to set provideer


       return App.render();


  render : function(){
    var addingInstance;

      // loading data
      web3.eth.getCoinbase(function(err, account) {
        if (err === null) {
          App.account = account;
          $("#accountAddress").html("Your Account: " + account);

      // Load contract data
      App.contracts.Add .deployed().then(function(i){
        app = i
        return app.add($("#fvalue").val() , $("#svalue").val());

$(function() {
  $(window).load(function() {

The following code is my app.js code for the ui of my block chain

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Adding and Subracting  Twonumbers </title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <div class="container">
      <div class="row">
        <div class="col-xs-12 col-sm-8 col-sm-push-2">
          <h1 class="text-center">adding Two Numbers</h1>
          <input type="number" name="fvalue"  id = "fvalue" value=""></br>
          second Value</br>
          <input type = "number"  name = "svalue"  id = "svalue" value = ""></br>
          <input type = "number"  name= "total"  id = "total" value = ""> </br>
        </br><button name="add" id="add">Add</button>
      <p id="accountAddress" class="text-center"></p>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/web3.min.js"></script>
    <script src="js/truffle-contract.js"></script>
    <script src="js/app.js"></script>

I have written my index.html code i want to link to my backend solidity code and call my add function and deploy the total in total box provided in my index.html code

pragma solidity ^0.4.23;

contract adding{

  uint256 public total;
  function  add(uint256 val1,uint256 val2) public returns(uint256){
    total = val1+val2;
    return total;

The above code is giving me the following error Failed to load resource:

app.js:54 14

    browser-sync-client.js?v=2.26.3:9 GET http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=MPxk1Re net::ERR_CONNECTION_REFUSED
    i.create @ browser-sync-client.js?v=2.26.3:9
    i @ browser-sync-client.js?v=2.26.3:9
    o.request @ browser-sync-client.js?v=2.26.3:9
    o.doPoll @ browser-sync-client.js?v=2.26.3:9
    n.poll @ browser-sync-client.js?v=2.26.3:9
    n.doOpen @ browser-sync-client.js?v=2.26.3:9
    n.open @ browser-sync-client.js?v=2.26.3:9
    n.open @ browser-sync-client.js?v=2.26.3:9
    n @ browser-sync-client.js?v=2.26.3:9
    n @ browser-sync-client.js?v=2.26.3:9
    n.open.n.connect @ browser-sync-client.js?v=2.26.3:9
    (anonymous) @ browser-sync-client.js?v=2.26.3:9
    browser-sync-client.js?v=2.26.3:9 GET http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=MPxk2fv net::ERR_CONNECTION_REFUSE
  • You put too much code here, and not enough information about the error. Did you successfully get the pet-shop app running? Oct 16, 2018 at 6:47
  • Yes i have succeful ran pet shop aplication Oct 16, 2018 at 6:48
  • you should share a github repo with the exact state of your app, and steps to reproduce the error you are getting. Oct 16, 2018 at 6:50
  • yes give some time i will do it Oct 16, 2018 at 6:51
  • Thnks i got it after making it as pure value but how to handle receipt in the ui i am thinking any documentation for that Oct 16, 2018 at 6:58

2 Answers 2


There are lots of code above, but not enough info to help you

First suggestion, make sure that adding.json is accessible

After solving of current issue, you may face to:

$("#add").click(function() {
    App.contracts.Add.deployed().then(function(i) {
        return i.add($("#fvalue").val(), $("#svalue").val());
    }).then(function(j) {

I have changed my function to pure function it worked fine

pragma solidity ^0.4.23;

contract adding{

  function  add(uint256 val1,uint256 val2) public pure  returns(uint256){
    //uint256 public total;
    uint256 total = val1+val2;
    return total;

Unit test is going wrong

refer to the following link for explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.