2

For example, IDEX has 40,767.582633880607462483 Ether. But I use BalanceAt function and only get 15.884 Ether. Why? Should I traversal all the tokens and query balanceOf("0x2a0c0DBEcC7E4D658f48E01e3fA353F44050c208")?

1 Answer 1

0

Are you sure you are caught up to the latest block on your Geth node?

Try running:

eth.syncing

Using Web3.js, I get the correct result for the amount of ether, using Infura/Metamask as my Ethereum provider:

https://shawntabrizi.com/ethbalance/

    window.addEventListener('load', function () {
        if (typeof web3 !== 'undefined') {
            console.log('Web3 Detected! ' + web3.currentProvider.constructor.name)
            window.web3 = new Web3(web3.currentProvider);
        } else {
            console.log('No Web3 Detected... using HTTP Provider')
            window.web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/noapikey"));
        }
    })
    function getBalance() {
        var address, wei, balance
        address = document.getElementById("address").value
        try {
            web3.eth.getBalance(address, function (error, wei) {
                if (!error) {
                    var balance = web3.fromWei(wei, 'ether');
                    document.getElementById("output").innerHTML = balance + " ETH";
                }
            });
        } catch (err) {
            document.getElementById("output").innerHTML = err;
        }
    }

At the time of writing this post:

40857.081452818949926701 ETH

2
  • I didn't run a geth node, I use infura and go-ethereum/ethclient. So it should be no sync problem. I don't know why…
    – Yriuns
    Commented Jul 22, 2018 at 3:36
  • my fault……the balance overflow uint64
    – Yriuns
    Commented Jul 22, 2018 at 4:10

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.