Skip to content

useGenesisHash

The useGenesisHash hook provides access to the genesis hash of the connected chain.

Import

tsx
import { useGenesisHash } from '@luno-kit/react'

Usage

tsx
import { useGenesisHash } from '@luno-kit/react'

function GenesisHashDisplay() {
  const { data: genesisHash, isLoading, error } = useGenesisHash()
  
  if (isLoading) {
    return <div>Loading genesis hash...</div>
  }
  
  if (error) {
    return <div>Error: {error.message}</div>
  }
  
  if (!genesisHash) {
    return <div>No genesis hash available</div>
  }
  
  return (
    <div>
      <h3>Genesis Hash</h3>
      <p>Hash: {genesisHash}</p>
      <p>Short: {genesisHash.slice(0, 10)}...</p>
    </div>
  )
}
ts
import { createConfig, kusama, polkadot, polkadotjsConnector } from '@luno-kit/react'

const config = createConfig({
  appName: 'luno with-vite example',
  chains: [polkadot, kusama],
  connectors: [polkadotjsConnector()],
  autoConnect: true,
});

Return Value

The hook returns an object with the following properties:

PropertyTypeDescription
dataHexString | undefinedThe genesis hash of the chain
errorError | nullAny error that occurred during the query
isLoadingbooleanWhether the query is currently loading

TIP

The data property is of type HexString from the dedot library, which represents a 0x${string}.
The genesis hash is fetched using React Query and cached indefinitely. The hook will only refetch when the chain changes or when the cache is invalidated.

Released under the MIT License.