hooks
Usebalance

useBalance

Hook for accessing user balance.

import { useBalance } from "aptosjs"

Usage

import { useBalance } from "aptosjs"
 
function App(){
  const { data, loading, error } = useBalance()
 
  if (loading) return <div>Loading...</div>
  if (error) return <div>Error: {error}</div>
  return <div>Balance: {data?.formatted}</div>
}

Example Return

// The following is a use balance example of: 0xf4ae7b6d73bbacfbf094f2efe0d3ad476f2da8c188a5d45d12fa550f6576ed35
{
  value: 1637171n,
  formatted: "0.01637171 APT"
}

Input Values

{
  address: string,
  network: "mainnet" | "testnet" | "local"
}

Address (required)

The address you want to get the balance of.

address: string

Network (required)

The Aptos network you want to connect to.

network: "mainnet" | "testnet" | "local"

Return Value

{
  value: BigInt,
  formatted: string
}