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-xyz/midl-js-react";

Example

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

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

Parameters

NameTypeDescription
paramsUseBlockNumberParamsThe parameters for the request
params.watchbooleanIf true, the block number will be polled at the specified interval.
params.pollingIntervalnumberThe interval in milliseconds at which to poll the block number. Default is 30_000
params.queryQueryOptionsThe query options to pass to the underlying useQuery hook.

Returns

NameTypeDescription
blockNumbernumberThe latest block number
...restAdditional query state