0

I want to display the eth balance "result" which for example, displays from the etherscan API

{
status: "1",
message: "OK",
result: "13386321000069000000000069"
}

Using the Ethereum wallet 0x00000000219ab540356cBB839Cbe05303d7705Fa

but my code returns the Ethereum balance result as 0, when I type into the chrome console from page inspect.

ether.fetchEther("0x00000000219ab540356cBB839Cbe05303d7705Fa")

I'm not sure why status and message are working ok. This is the code I use in a JavaScript file. The Html and CSS file just have skeleton code because I'm checking the JS works first.

let ether = {

    fetchEther: function(address)
    {
        fetch("https://api.etherscan.io/api?module=account&action=balance&address="+address +"tag=latest&apikey=RE98FGG6WVI25619AZKGI6B9IPJS6I64N8"
        ).then((response) =>response.json())
        .then((data)=>this.displayBalance(data));
    },
displayBalance: function(data){
const { result } =data;
console.log(result)
}
}
mintgg
  • 1
  • 1
  • The API responds with `{"status":"1","message":"OK","result":"0"}`, there is no problem with your code. Are you sure the the test wallet has funds? Are you sure your using the right API? – David Barishev Aug 27 '22 at 11:17
  • Yes that wallet is a top Ethereum holder, I was expecting to receive back ( result: "13386321000069000000000069" ) but got 0 instead. – mintgg Aug 27 '22 at 11:21

1 Answers1

1

It looks like you're missing an ampersand before tag. Should be &tag.

let ether = {

    fetchEther: function(address)
    {
        fetch("https://api.etherscan.io/api?module=account&action=balance&address="+address+"&tag=latest&apikey=RE98FGG6WVI25619AZKGI6B9IPJS6I64N8"
        ).then((response) =>response.json())
        .then((data)=>this.displayBalance(data));
    },
displayBalance: function(data){
const { result } =data;
console.log(result)
}
}