Skip to content

Explorers

The StarknetConfig provider accepts an optional explorer property to configure the block explorer used by the useExplorer hook.

Starknet React ships with the following block explorers (in alphabetical order):

  • Starkscan
  • Viewblock
  • Voyager

The Explorer interface

The Explorer interface is used to generate links to the block explorer. It provides the following properties and methods.

  • name: string: human-friendly explorer name.
  • block({ hash?: string, number?: number }): string: link to the specified block, either by hash or number.
  • transaction(hash: string): string: link to the specified transaction.
  • contract(address: string): string: link to the specified contract.
  • class(hash: string): string: link to the specified class.

Explorer factory

StarknetConfig expects an explorer factory, that is a function with the following signature:

 
type ExplorerFactory<T extends Explorer = Explorer> = (
  chain: Chain,
) => T | null;

Starknet React ships with the following explorer factories:

  • starkscan
  • viewblock
  • voyager

useExplorer hook

You can get an instance of the current explorer already initialized for the current chain using the useExplorer hook.

import { useExplorer } from "@starknet-react/core";
 
const explorer = useExplorer();
 
const name = explorer.name
const link = explorer.block({ number: 123 })