Skip to content

getClass

Action for getting Starknet contract class information.

Import

import { getClass } from "starkweb/core";

Usage

index.ts
import { getClass } from "starkweb/core";
import { config } from "./config";
 
const classInfo = await getClass(config, {
  classHash: "0x123...", 
});

Parameters

import { type GetClassParameters } from "starkweb/core";

classHash

Hex

The hash of the contract class to retrieve.

index.ts
import { getClass } from "starkweb/core";
import { config } from "./config";
 
const classInfo = await getClass(config, {
  classHash: "0x123...", 
});

chainId (optional)

Hex | undefined

The chain ID to get the class from. If not provided, uses the current chain.

index.ts
import { getClass } from "starkweb/core";
import { mainnet } from "starkweb/chains"; 
import { config } from "./config";
 
const classInfo = await getClass(config, {
  classHash: "0x123...",
  chainId: mainnet.chain_id, 
});

Return Type

import { type GetClassReturnType } from "starkweb/core";

Returns the contract class information including:

chainId

Hex

The chain ID of the network.

abi

Abi

The contract's ABI.

program

string

The contract's Cairo program.

Example

example.ts
import { getClass } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains"; 
import { config } from "./config";
 
// Get class on current chain
const classInfo = await getClass(config, {
  classHash: "0x123...", 
});
console.log("Contract ABI:", classInfo.abi);
 
// Get class on specific chain
const mainnetClass = await getClass(config, {
  classHash: "0x456...",
  chainId: mainnet.chain_id, 
});

Error

import { type GetClassErrorType } from "starkweb/core";