4.1 KiB

title, description
title description
useBlock Hook for fetching information about a block at a block number, hash or tag.

useBlock

Hook for fetching information about a block at a block number, hash or tag.

Import

import { useBlock } from 'wagmi'

Usage

::: code-group

import { useBlock } from 'wagmi'

function App() {
  const result = useBlock()
}

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

Parameters

import { type UseBlockParameters } from 'wagmi'

blockHash

`0x${string}`

Information at a given block hash.

::: code-group

import { useBlock } from 'wagmi'

function App() {
  const result = useBlock({
    blockHash: '0x89644bbd5c8d682a2e9611170e6c1f02573d866d286f006cbf517eec7254ec2d' // [!code focus]
  })
}

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

blockNumber

bigint

Information at a given block number.

::: code-group

import { useBlock } from 'wagmi'

function App() {
  const result = useBlock({
    blockNumber: 42069n // [!code focus]
  })
}

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

blockTag

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

Information at a given block tag. Defaults to 'latest'.

::: code-group

import { useBlock } from 'wagmi'

function App() {
  const result = useBlock({
    blockTag: 'pending' // [!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 { useBlock } from 'wagmi'
import { mainnet } from 'wagmi/chains' // [!code focus]

function App() {
  const result = useBlock({
    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 { useBlock } from 'wagmi'
import { config } from './config' // [!code focus]

function App() {
  const result = useBlock({
    config, // [!code focus]
  })
}

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

includeTransactions

boolean

Whether or not to include transactions as objects.

::: code-group

import { useBlock } from 'wagmi'
import { config } from './config'

function App() {
  const result = useBlock({
    includeTransactions: true // [!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 { useBlock } from 'wagmi'
import { config } from './config'

function App() {
  const result = useBlock({
    scopeKey: 'foo' // [!code focus]
  })
}

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

watch

boolean | UseWatchBlockParameters | undefined

::: code-group

import { useBlock } from 'wagmi'

function App() {
  const result = useBlock({
    watch: true, // [!code focus]
  })
}
import { useBlock } from 'wagmi'

function App() {
  const result = useBlock({
    watch: { // [!code focus]
      pollingInterval: 4_000, // [!code focus]
    }, // [!code focus]
  })
}

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

Return Type

import { type UseBlockReturnType } from 'wagmi'

Action