[Ethereum] Etherscan API Get Balance – Decimals Not Showing In Response

balancesetheretherscanexplorer-apiexternal-api

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

Best Answer

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

Related Topic