or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

contract-deployment.mdcontract-interaction.mdevent-management.mdindex.mdtransaction-handling.md
tile.json

contract-interaction.mddocs/

Contract Interaction

Core contract instantiation and method calling functionality. Provides the main Contract class for interacting with deployed smart contracts with automatic ABI encoding/decoding and dynamic method generation.

Capabilities

Contract Class

Main class for interacting with deployed smart contracts. Generates dynamic methods based on the contract ABI.

/**
 * Main contract interaction class with dynamic method generation
 * Extends BaseContract with dynamic ABI-based method creation
 */
class Contract extends BaseContract {
  /** Dynamic methods generated from contract ABI */
  readonly [key: string]: ContractFunction | any;
}

/**
 * Base contract functionality shared across contract classes
 */
class BaseContract {
  /** Contract address (checksummed) */
  readonly address: string;
  /** Contract ABI interface for encoding/decoding */
  readonly interface: Interface;
  /** Signer for sending transactions (optional) */
  readonly signer: Signer;
  /** Provider for blockchain interaction (optional) */
  readonly provider: Provider;
  /** Direct access to contract functions without result processing */
  readonly functions: { [name: string]: ContractFunction };
  /** Read-only method calls (automatically used for view/pure functions) */
  readonly callStatic: { [name: string]: ContractFunction };
  /** Gas estimation for contract methods */
  readonly estimateGas: { [name: string]: ContractFunction<BigNumber> };
  /** Transaction preparation without sending */
  readonly populateTransaction: { [name: string]: ContractFunction<PopulatedTransaction> };
  /** Event filter generators for contract events */
  readonly filters: { [name: string]: (...args: Array<any>) => EventFilter };
  /** Promise resolving to the contract address (handles ENS resolution) */
  readonly resolvedAddress: Promise<string>;
  /** Reference to deployment transaction if contract was deployed */
  readonly deployTransaction: TransactionResponse;
}

Usage Examples:

import { Contract } from "@ethersproject/contracts";
import { JsonRpcProvider } from "@ethersproject/providers";

const provider = new JsonRpcProvider("https://mainnet.infura.io/v3/YOUR_KEY");

// Create contract instance
const erc20Abi = [
  "function name() view returns (string)",
  "function symbol() view returns (string)",
  "function decimals() view returns (uint8)",
  "function totalSupply() view returns (uint256)",
  "function balanceOf(address owner) view returns (uint256)",
  "function transfer(address to, uint256 amount) returns (bool)",
  "event Transfer(address indexed from, address indexed to, uint256 value)"
];

const contract = new Contract("0xA0b86a33E6417c5F4c6aB273FA2B7C9C4EC5c5e2", erc20Abi, provider);

// Call view functions (automatically uses callStatic)
const name = await contract.name();
const balance = await contract.balanceOf("0x...");

// With signer for transactions
import { Wallet } from "@ethersproject/wallet";
const wallet = new Wallet("YOUR_PRIVATE_KEY", provider);
const contractWithSigner = contract.connect(wallet);

// Send transaction
const tx = await contractWithSigner.transfer("0x...", "1000000000000000000");
await tx.wait();

Contract Constructor

Creates a new contract instance with the specified address, ABI, and signer/provider.

/**
 * Create a new contract instance
 * @param addressOrName - Contract address or ENS name
 * @param contractInterface - Contract ABI (array, JSON, or Interface object)
 * @param signerOrProvider - Signer for transactions or Provider for read-only access
 */
constructor(
  addressOrName: string,
  contractInterface: ContractInterface,
  signerOrProvider?: Signer | Provider
);

Connection Management

Methods for connecting to different signers or providers, and attaching to different contract addresses.

/**
 * Connect to a different signer or provider
 * @param signerOrProvider - New signer, provider, or address string
 * @returns New contract instance with the specified connection
 */
connect(signerOrProvider: Signer | Provider | string): Contract;

/**
 * Attach to a different contract address using same ABI and connection
 * @param addressOrName - New contract address or ENS name
 * @returns New contract instance at the specified address
 */
attach(addressOrName: string): Contract;

Deployment Waiting

Wait for contract deployment to be confirmed on the blockchain.

/**
 * Wait for contract deployment to be confirmed
 * @returns Promise resolving to this contract instance once deployed
 */
deployed(): Promise<Contract>;

Fallback Function

Call the contract's fallback function directly.

/**
 * Call contract fallback function
 * @param overrides - Transaction overrides (gas, value, etc.)
 * @returns Transaction response
 */
fallback(overrides?: TransactionRequest): Promise<TransactionResponse>;

Static Methods

Utility methods available on the Contract class.

/**
 * Calculate contract address from deployment transaction
 * @param transaction - Transaction with from address and nonce
 * @returns Calculated contract address
 */
static getContractAddress(transaction: { from: string; nonce: BigNumberish }): string;

/**
 * Create Interface from contract ABI
 * @param contractInterface - Contract ABI specification
 * @returns Interface object for ABI operations
 */
static getInterface(contractInterface: ContractInterface): Interface;

/**
 * Check if value is an Indexed event parameter
 * @param value - Value to check
 * @returns True if value is Indexed
 */
static isIndexed(value: any): value is Indexed;

Types

/** Contract ABI specification formats */
type ContractInterface = string | ReadonlyArray<Fragment | JsonFragment | string> | Interface;

/** Generic contract method wrapper */
type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;