2

I have a smart contract token deployed in a Ganache instance. My dapp written with React and web3.js shows the same 10 accounts for eth.accounts as running the same command in the geth console.

If I create my token object with the abi and contract address in geth, I get a different balance for accounts[0] than the balance I get with my dapp. Both create the token object with the same blockchain address. Both show that eth.accounts[0] is the same address!

I also have an Android app using web3j. It uses the same contract address and it displays the same values that the React dapp shows.

However, I also have an app in web3.py and it shows the same values that are shown in geth!

Can someone please explain to me how the same token object could display different outputs on .balanceOf("the_same_address") if it's in the same blockchain? The only difference is if I'm using geth, web3j, web3.js or web3.py

EDIT: added picture ob browser with console (dapp) and terminal console (geth) enter image description here

It gives me different balances for all accounts. It feels as if I was connecting to 2 different blockchains. However, they have the same 10 default accounts and my contracts deployed in the same addresses.

6
  • When you say the balances are "different", do you mean that one is 0?
    – carver
    Apr 19, 2018 at 22:23
  • No. Balances are completely different numbers. I also get different results when checking mappings in a contract. Web3.js will return a different mapping than geth console.
    – GabCas
    Apr 20, 2018 at 13:24
  • Can you show the balances as integers before shifting the decimals? The difference seems too large for this, but maybe it's some kind of rounding error. Also, if there's any chance you're connected to two different chains, the best way to confirm you're on the same one is by comparing the latest block hash with: web3.eth.getBlock('latest').hash.
    – carver
    Apr 20, 2018 at 21:13
  • Thanks @carver I was really hoping this would show two different hashes. Unfortunately, it showed the same hash in geth and dapp even though they show different balances. We created a new instance and it shows the same balances in all apps. I still haven't destroyed this instance with hopes of understanding what went wrong.
    – GabCas
    Apr 23, 2018 at 13:56
  • A broken token could give a different balance depending on who was calling. (and the different web3's might have different default senders) Can you add the solidity to verify no funny business in that function?
    – carver
    Apr 25, 2018 at 1:00

1 Answer 1

0

Are the results showing in 'eth' values and not in 'wei's? Can you show us the different results you see in geth/ web3j/ js/ py ?

3
  • It's in wei's. I can convert from wei and its not a rounding problem. I've added an image to the question.
    – GabCas
    Apr 20, 2018 at 13:25
  • In your console, you're typing coin.balanceOf(). Is 'coin' your contract? Are you calling the same 'coin' contract through web3js (UI where it displays 599999400) ? I guess the balance that you're getting in UI is the actual account balance from your blockchain network and coin.balanceOf is the balance the address in your contract. Can you post your coin.balanceOf function here? Apr 20, 2018 at 15:30
  • Yes, 'coin' is the contract with the same address. balanceOf.call(accounts[0]) in React coin.balanceOf(eth.accounts[0]) in geth You can see in the picture that accounts[0] is the same for both. It really is super weird. Feels like 2 different blockchains but both live in the same endpoint and port...
    – GabCas
    Apr 20, 2018 at 17:09

Your Answer

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

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