Skip to content

useBlockNumber ​

Fetches the latest block number from the configured network and can optionally poll for updates at a specified interval.

Import ​

ts
import { useBlockNumber } from "@midl/react";

Example ​

tsx
function Page() {
  const { blockNumber } = useBlockNumber();

  return (
    <div>
      <h2>Block Number</h2>
      <p>{blockNumber}</p>
    </div>
  );
}

Parameters ​

NameTypeDescription
paramsUseBlockNumberParams

UseBlockNumberParams ​

NameTypeDescription
watchbooleanIf true, the block number will be polled at the specified interval.
pollingIntervalnumberThe interval in milliseconds at which to poll the block number. Default is 30_000
queryQueryOptionsThe query options to pass to the underlying useQuery hook.
configConfig(optional) Config object to use instead of the one from context.

Returns ​

NameTypeDescription
blockNumbernumberThe latest block number
...restAdditional query state

Released under the MIT License