Skip to content

getClassAt

Action for getting Starknet contract class at a specific address.

Import

import { getClassAt } from "starkweb/core";

Usage

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

Parameters

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

contractAddress

Hex

The address of the contract to get the class for.

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

chainId (optional)

Hex | undefined

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

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

Return Type

import { type GetClassAtReturnType } 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 { getClassAt } from "starkweb/core";
import { mainnet, testnet } from "starkweb/chains"; 
import { config } from "./config";
 
// Get class at address on current chain
const classInfo = await getClassAt(config, {
  contractAddress: "0x123...", 
});
console.log("Contract ABI:", classInfo.abi);
 
// Get class at address on specific chain
const mainnetClass = await getClassAt(config, {
  contractAddress: "0x456...",
  chainId: mainnet.chain_id, 
});

Error

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