3.4 KiB
title, description
| title | description |
|---|---|
| useBalance | Hook for fetching native currency balance. |
useBalance
Hook for fetching native currency balance.
Import
import { useBalance } from 'wagmi'
Usage
::: code-group
import { useBalance } from 'wagmi'
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Parameters
import { type UseBalanceParameters } from 'wagmi'
address
Address | undefined
Address to get balance for. enabled set to false if address is undefined.
::: code-group
import { useBalance } from 'wagmi'
import { mainnet } from 'wagmi/chains'
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48', // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
blockNumber
bigint | undefined
Block number to get balance at.
::: code-group
import { useBalance } from 'wagmi'
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
blockNumber: 17829139n, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
blockTag
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined
Block tag to get balance at.
::: code-group
import { useBalance } from 'wagmi'
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
blockTag: 'latest', // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
chainId
config['chains'][number]['id'] | undefined
ID of chain to use when fetching data.
::: code-group
import { useBalance } from 'wagmi'
import { mainnet } from 'wagmi/chains' // [!code focus]
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
chainId: mainnet.id, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
::: code-group
import { useBalance } from 'wagmi'
import { config } from './config' // [!code focus]
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
config, // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
scopeKey
string | undefined
Scopes the cache to a given context. Hooks that have identical context will share the same cache.
::: code-group
import { useBalance } from 'wagmi'
function App() {
const result = useBalance({
address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
scopeKey: 'foo', // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Return Type
import { type UseBalanceReturnType } from 'wagmi'