useThirdwebConfigContext
Hook for accessing the ThirdwebConfigContext from a React component.
The ThirdwebConfigContext contains information about the current chain, including its name, chain ID, RPC endpoints, and more.
import { useThirdwebConfigContext } from "@thirdweb-dev/react";
Usage
The useThirdwebConfigContext hook returns the available ThirdwebConfigContext.
import { useThirdwebConfigContext } from "@thirdweb-dev/react";
function App() {
const { chains } = useThirdwebConfigContext();
return (
<ul>
{chains.map((chain) => (
<li key={chain.name}>{chain.name}</li>
))}
</ul>
);
}
Return Value
The useThirdwebConfigContext hook returns an object with the ThirdwebConfigContext:
interface ThirdwebConfigContext {
chains: Readonly<Chain[]>;
}
export type Chain = {
name: string;
chain: string;
icon?: {
url: string;
width: number;
height: number;
format: string;
sizes?: readonly number[];
};
rpc: readonly string[];
features?: Readonly<Array<{ name: string }>>;
faucets?: readonly string[];
nativeCurrency: {
name: string;
symbol: string;
decimals: number;
};
infoURL?: string;
shortName: string;
chainId: number;
networkId?: number;
ens?: {
registry: string;
};
explorers?: Readonly<
Array<{
name: string;
url: string;
standard: string;
}>
>;
testnet: boolean;
slug: string;
slip44?: number;
};
The Chain array contains Chain objects, which contain information about the current chain. The Chain object has the following properties:
name- The human-readable name of the chainchain- The name of the chainicon- The icon of the chainrpc- An array of RPC endpointsfeatures- An array of features supported by the chainfaucets- An array of faucets available for the chainnativeCurrency- An object containing information about the native currency of the chaininfoURL- A URL containing information about the chainshortName- The short name of the chainchainId- The chain ID of the chainnetworkId- The network ID of the chainens- An object containing information about the ENS registry of the chainexplorers- An array of block explorers available for the chaintestnet- A boolean indicating whether or not the chain is a testnetslug- The slug of the chainslip44- The SLIP 44 number of the chain