0

Expected

Use the Etherscan API to make a GET request for an ETH address' balance in order to receive a response providing the Ether token quantity representing all decimal places.

Observed

The response provides the Ether token quantity without representing any decimal places.

Request: Etherscan Get Ether Balance for a single Address

http://api.etherscan.io/api?module=account&action=balance&address=0x8a27D05e97A156E93D42a6d3afB5c2154ebb9cB5&tag=latest&apikey={YOUR_API_KEY_HERE}

Note: I chose a random ETH address above. This is not my ETH address.

Response

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

Balance From Etherscan UX

The balance from the Etherscan UX indicates that decimal places are included in the Ether balance. However, the API response does not provide any information regarding decimal formatting.

0.086354095 Ether

1

The result from the Etherscan GET request's response must be divided by 1018.

As answered in this post regarding ERC20 tokens decimal places, "Most ERC20 tokens should follow the pattern of using 18 decimal places for their token."

This applies to Ether itself. Therefore, the result response of 86354095000000000 is equal to 0.086354095 Ether.

(86354095000000000/(1018)) = 0.086354095

0

Well obviously in this example you need to do the formatting by your self. The presented return value is in wei, you can convert it into eth by using web3 library:

web3.utils.fromWei('86354095000000000', 'ether');

This will return a 0.086354095 value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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