Hello I made a restfull API on my own (python file jsonify + localtunnel) on a localhost using a specific number (in this case 141) represented by the variable z. This variable should go into DevCoin function balances[msg.sender] and should be displayed on localhost:8080 as: You have 141 DVC. For this purpose I use ganache-cli (Listening on , ethereum-bridge(node bridge -a 9 -H -p 8545 --dev) as well as truffle.js (8545). Using: truffle compile, truffle migrate --development --reset and npm run dev leading to no error. The problem is now, when I connect the index.html(where my variable should be displayed) with a private network on metamask on localhost:8545, I got: You have 0 DVC. I don't know why. If I pass instead of z a number, the chosen number is displayed. Have anyone any idea to help me out?enter image description hereenter image description hereenter image description hereethereum-bridge "result":"141"RestAPI Truffle console: enter image description here

App.js enter image description here enter image description here

truffle.js enter image description here

2_deploy_contracts.js enter image description here

index.html enter image description here

  • As you can see via the bridge output, the Oraclize setup is working correctly and returning the z of 141 to your smart contract. So to figure out your issue, first I would use the Truffle console to access your contract on this test-net and query it directly to confirm that z is infact updated to 141. Then, when you've confirmed that, you'll know that the problem is with the front-end side of your DApp. At that point we can't help further until you post the javascript code that you're using to access the smart-contract.
    – gskapka
    Commented Jan 3, 2019 at 20:11

1 Answer 1



  • You should edit your original question to include the screenshots that you have mistakenly posted as a reply.

  • You should refrain from posting images of code, and post the actual code instead. Code cannot be copy & pasted from images making it much more work for an answerer to type out a reply.


Your issue is that in the javascript, when the balance is refreshed it is querying account[0]'s balance, whereas you are hoping to retrieve the z value from your smart contract.

So to fix this you have two options:

Option 1:

  • Change the javascript to query the smart-contract for the z variable

Option 2:

  • Change the smart-contact to apportion the result of the Oraclize query as a balance for account[0].


An issue with Option 2 is that you'll need to know the address of account[0] before hand, and hard code it into your contract. This isn't ideal, so we'll go for Option 1 instead.


Find the refreshBalance function in App.js and change the line:

return dev.getBalance.call(account, {from: account});

To read:

return dev.z.call();

Now it'll be querying the z variable, and returning the result to the balance span in the html.


The Oraclize query is asynchronous, so please make sure the refreshBalance javascript function is called after the Oraclize query has returned, or else your the value will remain 0.

Edit - Answering follow-up question:

The sendCoin functionality should already work, looking at the code. However, looking at the smart-contract, no account ends up owning any of the coin in order to send any. The constructor function gives the deployer ([msg.sender]) an amount of coins equal to z. However the contract begins life with z = 0, and so ∴ msg.sender also has none.

To rectify this, change the line:

balances[msg.sender] = z;


balances[msg.sender] = 1000000;

Congratulations! [msg.sender], who in this case is Truffle account[0], has a million DVC! Now when you use the send functionality in your DApp, you'll have some coins to send!

  • wow thank you very much. It works for the refreshBalance function. How would you change the the sendCoin function, to send some DVC? Greets
    – Jolosin
    Commented Jan 4, 2019 at 16:34
  • Please accept the answer so other used can know that it provides an accurate solution. As for your other question, I'll edit the answer now...
    – gskapka
    Commented Jan 4, 2019 at 16:38
  • Ok I have done it!
    – Jolosin
    Commented Jan 4, 2019 at 16:42
  • Also, could you add the images you posted in your answer, into your question, so that other users can see the full code of your question in one single post? That'd make things much clearer for anyone else experiencing similar issues to yourself! Many thanks!
    – gskapka
    Commented Jan 4, 2019 at 16:44
  • No problem & thanks for reorganising your question so now other people can understand the question & answer together!
    – gskapka
    Commented Jan 4, 2019 at 18:01

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.