Skip to content

useRuntimeVersion

The useRuntimeVersion hook provides access to the current runtime version of the connected chain.

Import

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

Usage

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

function RuntimeVersionDisplay() {
  const { data: runtimeVersion, isLoading, error } = useRuntimeVersion()
  
  if (isLoading) {
    return <div>Loading runtime version...</div>
  }
  
  if (error) {
    return <div>Error: {error.message}</div>
  }
  
  if (!runtimeVersion) {
    return <div>No runtime version available</div>
  }
  
  return (
    <div>
      <h3>Runtime Version</h3>
      <p>Spec Version: {runtimeVersion.specVersion}</p>
      <p>Impl Version: {runtimeVersion.implVersion}</p>
      <p>Impl Name: {runtimeVersion.implName}</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
dataSubstrateRuntimeVersion | undefinedCurrent runtime version information
errorError | nullAny error that occurred during the query
isLoadingbooleanWhether the query is currently loading
isErrorbooleanWhether there's an error
isSuccessbooleanWhether the query was successful

SubstrateRuntimeVersion Object

The data property is of type SubstrateRuntimeVersion from the dedot library, which contains runtime version information.

PropertyTypeDescription
specVersionnumberThe specification version of the runtime
implVersionnumberThe implementation version of the runtime
implNamestringThe name of the runtime implementation
authoringVersionnumberThe authoring version of the runtime
specNamestringThe name of the runtime specification

TIP

The runtime version is fetched using React Query and automatically cached. The hook will only refetch when the chain changes or when the cache is invalidated.

Released under the MIT License.