Skip to content

getBalance

Returns the balance of an address in wei.

Usage

import { publicClient } from './client'
 
const balance = await publicClient.getBalance({ 
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
})
// 10000000000000000000000n (wei)

Returns

bigint

The balance of the address in wei.

Parameters

address

The address of the account.

const balance = await publicClient.getBalance({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', 
})

blockNumber (optional)

  • Type: bigint

The balance of the account at a block number.

const balance = await publicClient.getBalance({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockNumber: 69420n
})

blockTag (optional)

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'

The balance of the account at a block tag.

const balance = await publicClient.getBalance({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockTag: 'safe'
})

Tips

  • You can convert the balance to ether units with formatEther.
const balance = await publicClient.getBalance({
  address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
  blockTag: 'safe'
})
const balanceAsEther = formatEther(balance) 
// "6.942"

JSON-RPC Method

eth_getBalance