call
Action for making a read-only call to a Starknet contract.
Import
import { call } from 'starkweb/core'
Usage
import { call } from 'starkweb/core'
import { config } from './config'
const result = await call(config, {
address: '0x123...',
abi: [...],
functionName: 'balanceOf',
args: ['0x456...']
})
Parameters
import { type CallParameters } from "starkweb/core";
address
Address
The address of the contract to call.
abi
Abi
The ABI of the contract.
functionName
string
The name of the function to call.
args (optional)
readonly unknown[]
The arguments to pass to the function.
blockIdentifier (optional)
BlockIdentifier
The block at which to perform the call (number, hash, or 'latest').
chainId (optional)
Hex | undefined
The chain ID to make the call on.
Return Type
import { type CallReturnType } from "starkweb/core";
Returns the result of the contract call.
Example
example.ts
import { call } from "starkweb/core";
import { erc20Abi } from "./abis/erc20";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
// Call at latest block
const balance = await call(config, {
address: "0x123...",
abi: erc20Abi,
functionName: "balanceOf",
args: ["0x456..."],
});
// Call on specific chain
const supply = await call(config, {
address: "0x123...",
abi: erc20Abi,
functionName: "totalSupply",
chainId: mainnet.chain_id,
});
Error
import { type CallErrorType } from "starkweb/core";
TanStack Query
import {
type CallData,
type CallOptions,
type CallQueryFnData,
type CallQueryKey,
callQueryKey,
callQueryOptions,
} from "starkweb/query";