eth_getBalance

Returns the balance of the account of a given address.

Parameters

  1. DATA, 20 Bytes - address to check for balance.

  2. QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
   '0xc94770007dda54cF92009BFF0dE90c06F603a09f',
   'latest'
]

Returns

QUANTITY - hex value of the current ETH balance for the given address, measured in wei.

Request

const Web3 = require("web3");

async function main() {

	const Web3 = require('web3')
        const rpcURL = '1DLT-IP-ADDRESS' // Your RPC URL goes here
        const web3 = new Web3(rpcURL)
	
	// Query the blockchain (replace example parameters)
    	const balance = await web3.eth.getBalance('0xc94770007dda54cF92009BFF0dE90c06F603a09f'); 
    
	// Print the output to console
	console.log(balance);
   }

main();

Result

{
  "jsonrpc": "2.0",
  "id": 0,
  "result": "0x7c2562030800"
}

Converting eth_getBalance response into ETH

To convert the hex string response, measured in Wei to a decimal value measured in ETH we need to complete two steps:

  1. Convert the hex response into decimal (Wei)

  2. Convert the Wei decimal into ETH decimal (10^18 wei = 1 eth)

Depending on what library or language you are using, there are several options here.

// conversion from hex string to decimal
dec = parseInt("hex strong response", 16)

// conversion from Wei to to ETH
ethBalance = dec*(10**18)

Last updated