Skip to main content
Version: 8.6.0

Class: ContractInterface

Interface for interacting with Starknet smart contracts

Provides methods for calling contract functions, estimating fees, and managing contract state. Supports both read-only calls and state-changing invocations.

Remarks

The interface provides multiple ways to interact with contracts:

  • Direct method calls for convenience
  • Generic call/invoke methods for flexibility
  • Fee estimation and transaction population
  • Event parsing and contract validation

Implemented by

Indexable

[key: string]: AsyncContractFunction | any

Dynamic method access - allows calling contract methods directly

Constructors

constructor

new ContractInterface(): ContractInterface

Returns

ContractInterface

Properties

abi

Abstract abi: Abi

Contract ABI (Application Binary Interface)

Defined in

src/contract/interface.ts:67


address

Abstract address: string

Contract address on Starknet

Defined in

src/contract/interface.ts:72


providerOrAccount

Abstract providerOrAccount: ProviderOrAccount

Provider for read operations or Account for write operations

Defined in

src/contract/interface.ts:77


classHash

Optional Abstract classHash: string

Optional contract class hash for optimization

Defined in

src/contract/interface.ts:82


functions

Readonly functions: Object

Contract methods that return promises (async operations)

Index signature

[name: string]: AsyncContractFunction

Defined in

src/contract/interface.ts:87


callStatic

Readonly callStatic: Object

Contract methods for read-only calls (state queries)

Index signature

[name: string]: AsyncContractFunction

Defined in

src/contract/interface.ts:92


populateTransaction

Readonly populateTransaction: Object

Contract methods that return populated transactions for batching

Index signature

[name: string]: ContractFunction

Defined in

src/contract/interface.ts:97


estimateFee

Readonly estimateFee: Object

Contract methods for fee estimation

Index signature

[name: string]: ContractFunction

Defined in

src/contract/interface.ts:102

Methods

attach

attach(address, abi?): void

Attach the contract to a different address with optional new ABI

Parameters

NameTypeDescription
addressstringNew contract address to interact with
abi?AbiOptional new ABI to use (defaults to current ABI)

Returns

void

Example

contract.attach('0x123...', newAbi);
// Now contract.address === '0x123...' and uses newAbi

Defined in

src/contract/interface.ts:120


isDeployed

isDeployed(): Promise<ContractInterface>

Verify that a contract is deployed at the current address

Returns

Promise<ContractInterface>

Promise resolving to this contract instance if deployed

Throws

If no contract is found at the address

Example

try {
await contract.isDeployed();
console.log('Contract is deployed');
} catch (error) {
console.log('Contract not found at address');
}

Defined in

src/contract/interface.ts:137


call

call(method, args?, options?): Promise<CallResult>

Call a read-only contract method (view function)

Parameters

NameTypeDescription
methodstringName of the contract method to call
args?ArgsOrCalldataMethod arguments as array or calldata
options?CallOptionsCall options including block identifier and parsing settings

Returns

Promise<CallResult>

Parsed result from the contract method

Example

const balance = await contract.call('balanceOf', [userAddress]);
const name = await contract.call('name', [], { blockIdentifier: 'latest' });

Defined in

src/contract/interface.ts:152


invoke

invoke(method, args?, options?): Promise<{ transaction_hash: string }>

Invoke a state-changing contract method (external function)

Parameters

NameTypeDescription
methodstringName of the contract method to invoke
args?ArgsOrCalldataMethod arguments as array or calldata
options?ExecuteOptionsExecution options including transaction details

Returns

Promise<{ transaction_hash: string }>

Transaction response with hash

Example

const tx = await contract.invoke('transfer', [recipient, amount]);
const receipt = await provider.waitForTransaction(tx.transaction_hash);

Defined in

src/contract/interface.ts:171


estimate

estimate(method, args?, options?): Promise<EstimateFeeResponseOverhead>

Estimate fee for invoking a contract method

Parameters

NameTypeDescription
methodstringName of the contract method to estimate
args?ArgsOrCalldataMethod arguments as array or calldata
options?ObjectEstimation options including block identifier
options.blockIdentifier?BlockIdentifier-

Returns

Promise<EstimateFeeResponseOverhead>

Fee estimation details

Example

const feeEstimate = await contract.estimate('transfer', [recipient, amount]);
console.log('Estimated fee:', feeEstimate.overall_fee);

Defined in

src/contract/interface.ts:190


populate

populate(method, args?): Invocation

Populate transaction data for a contract method call

Parameters

NameTypeDescription
methodstringName of the contract method
args?ArgsOrCalldataMethod arguments as array or calldata

Returns

Invocation

Invocation object for batching or inspection

Example

const invocation = contract.populate('transfer', [recipient, amount]);
// Use in account.execute([invocation1, invocation2, ...])

Defined in

src/contract/interface.ts:210


parseEvents

parseEvents(receipt): ParsedEvents

Parse events from a transaction receipt using the contract's ABI

Parameters

NameTypeDescription
receiptGetTransactionReceiptResponseTransaction receipt from waitForTransaction

Returns

ParsedEvents

Array of parsed events with decoded data

Example

const receipt = await provider.waitForTransaction(txHash);
const events = contract.parseEvents(receipt);
events.forEach((event) => {
console.log('Event:', event.name, event.data);
});

Defined in

src/contract/interface.ts:226


isCairo1

isCairo1(): boolean

Check if the contract is implemented in Cairo 1

Returns

boolean

True if the contract uses Cairo 1, false for Cairo 0 (legacy)

Example

if (contract.isCairo1()) {
console.log('Using Cairo 1 features');
}

Defined in

src/contract/interface.ts:239


getVersion

getVersion(): Promise<ContractVersion>

Get the Cairo and compiler version of the contract

Returns

Promise<ContractVersion>

Object containing cairo version and compiler version

Example

const version = await contract.getVersion();
console.log(`Cairo ${version.cairo}, Compiler ${version.compiler}`);

Defined in

src/contract/interface.ts:251


typedv2

typedv2<TAbi>(tAbi): TypedContractV2<TAbi>

Create a typed contract instance with full TypeScript support

Type parameters

NameType
TAbiextends Abi

Parameters

NameTypeDescription
tAbiTAbiThe typed ABI interface for compile-time type checking

Returns

TypedContractV2<TAbi>

Typed contract instance with IntelliSense support

Example

const typedContract = contract.typedv2(erc20Abi);
// Now typedContract.transfer() has full type safety

Defined in

src/contract/interface.ts:264


withOptions

withOptions(options): ContractInterface

Set execution options for subsequent contract interactions

Parameters

NameTypeDescription
optionsWithOptionsOptions to override for contract interactions

Returns

ContractInterface

This contract instance with the specified options applied

Example

contract.withOptions({
blockIdentifier: 'latest',
parseResponse: false,
});
// Now all subsequent calls use these options

Defined in

src/contract/interface.ts:280