getBalanceAt() Javascript API

kharvtrankharvtran Member Posts: 12
edited August 2014 in Geth - Go Implementation
Hi,

Sorry for a noob question of if this is addressed somewhere else already,

Following this https://github.com/ethereum/go-ethereum/wiki/PoC-5-JavaScript-API, if I want to get the balance of my ethereum address, for example in this case: a9fc34ef99a927f77779899dd05e878ca4a684e3. Is it correct to have this piece of code?


eth.getBalanceAt("a9fc34ef99a927f77779899dd05e878ca4a684e3",function(balance){
document.querySelector("#balance").innerHTML = balance;
})

I tried but it showed nothing. Where did I go wrong?

Thanks
Post edited by kharvtran on

Comments

  • heliumcraftheliumcraft Member Posts: 28
    @kharv‌ see https://forum.ethereum.org/discussion/comment/5835#Comment_5835
    However please note though, that even now it doesn't work 80% of the time.
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    It's likely that if you are loading it in ethereal, a javascript typo is preventing it from executing (there's no .js debugger yet in the webview). Easiest way to debug this is to set manual 'checkpoints' using the debug() method in js and see where it stops working. Also, use a linter within your IDE to catch the most obvious errors.
  • kharvtrankharvtran Member Posts: 12
    edited August 2014
    @heliumcraft: thank you for the link! But it seems the getStorageAt doesn't work for me as well. Referring to your last post's comment in this thread (https://forum.ethereum.org/discussion/1330/syntax-error-trying-to-create-a-contract-in-the-go-client#latest), I think we have the same error. Mine shows
    webapp.qml:195: getStorage: TypeError: Property 'getStorageAt' of object JSObject(0x5c4ce90) is not a function
    . Have you found any clear solution about that? I'd be interested to know.

    @Stephan_Tual‌: Thanks for the suggestion. Yes, I loaded it in Ethereal. I checked the whole thing again. The code is simple like this, and I guess it should contain no typo. However, it does not print out the ether balance (suppose that the eth.getBalanceAt() is correct) .






    function init() {
    eth.getBalanceAt("a9fc34ef99a927f77779899dd05e878ca4a684e3",function(balance){
    document.querySelector("#balance").innerHTML = balance;
    })
    };






    Also, can you please specify more about the debug() method? I've been googling around but found nothing really relevant. A relevant URL would be really good for me. Kinda not-expert in javascript here :)
Sign In or Register to comment.