3.5 KiB

title, description
title description
useBalance Composable for fetching native currency balance.

useBalance

Composable for fetching native currency balance.

Import

import { useBalance } from '@wagmi/vue'

Usage

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::

Parameters

import { type UseBalanceParameters } from '@wagmi/vue'

address

Address | undefined

Address to get balance for. enabled set to false if address is undefined.

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'
import { mainnet } from '@wagmi/vue/chains'

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48', // [!code focus]
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::


blockNumber

bigint | undefined

Block number to get balance at.

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
  blockNumber: 17829139n, // [!code focus]
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::

blockTag

'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined

Block tag to get balance at.

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
  blockTag: 'latest', // [!code focus]
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::


chainId

config['chains'][number]['id'] | undefined

ID of chain to use when fetching data.

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'
import { mainnet } from '@wagmi/vue/chains' // [!code focus]

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
  chainId: mainnet.id, // [!code focus]
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::

config

Config | undefined

Config to use instead of retrieving from the WagmiPlugin.

::: code-group

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'
import { config } from './config' // [!code focus]

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
  config, // [!code focus]
})
</script>

<<< @/snippets/vue/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

<script setup lang="ts">
import { useBalance } from '@wagmi/vue'

const result = useBalance({
  address: '0x4557B18E779944BFE9d78A672452331C186a9f48',
  scopeKey: 'foo', // [!code focus]
})
</script>

<<< @/snippets/vue/config.ts[config.ts] :::

Return Type

import { type UseBalanceReturnType } from '@wagmi/vue'

Action