getPublicClient
Action for getting a configured Public Client instance for interacting with Starknet.
Import
import { getPublicClient } from "starkweb/core";
Usage
index.ts
import { getPublicClient } from "starkweb/core";
import { config } from "./config";
const client = getPublicClient(config);
Parameters
import { type GetPublicClientParameters } from "starkweb/core";
chainId (optional)
Hex | undefined
ID of chain to get client for. If not provided, uses the current chain.
index.ts
import { getPublicClient } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
const client = getPublicClient(config, {
chainId: mainnet.chain_id,
});
Return Type
import { type GetPublicClientReturnType } from "starkweb/core";
PublicClient
A configured public client instance with public actions for interacting with Starknet.
Example
example.ts
import { getPublicClient } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
// Get public client for specific chain
const client = getPublicClient(config, {
chainId: mainnet.chain_id,
});
// Use public client
const blockNumber = await client.getBlockNumber();
const balance = await client.getBalance({ address: "0x123..." });
Error
Throws when:
- Chain is not configured
- Transport is not found
TanStack Query
import {
type GetPublicClientData,
type GetPublicClientQueryFnData,
type GetPublicClientQueryKey,
getPublicClientQueryKey,
getPublicClientQueryOptions,
} from "starkweb/query";