Contract Types
Contract Type Hierarchy
The contract type system follows a layered inheritance pattern, starting from a base interface and extending to specialized contract types for different token standards.
Base Interfaces
IContract
The IContract interface serves as the foundation for all contract types. It defines the core functionality required for contract interactions, including address management, event decoding, calldata encoding, and simulation configuration.
All contract interfaces and classes ultimately implement this base interface.
BaseContractProperties
The BaseContractProperties interface extends IContract and adds support for dynamic property access through symbol indexing. This enables contract instances to expose ABI-defined methods as callable properties, with each method returning a CallResult object.
IOP_NETContract
The IOP_NETContract interface extends BaseContractProperties and represents the base interface for all OP_NET smart contracts. It includes the deployer() method, which is common to all deployed contracts on OP_NET.
Token Standard Interfaces
IOP20Contract
The IOP20Contract interface extends IOP_NETContract and defines the standard for fungible tokens on OP_NET. This interface is analogous to ERC-20 on Ethereum and includes methods for token metadata, balance queries, transfers, allowances, and signature-based approvals.
IOP20SContract
The IOP20SContract interface extends IOP20Contract with additional functionality for pegged tokens and stablecoins. It includes methods for managing peg rates, staleness thresholds, and peg authority transfers, enabling tokens that maintain a fixed exchange rate with external assets.
IOP721Contract
The IOP721Contract interface extends IOP_NETContract and defines the standard for non-fungible tokens (NFTs) on OP_NET. This interface is analogous to ERC-721 on Ethereum and includes methods for token ownership, transfers, approvals, and metadata management.
IExtendedOP721Contract
The IExtendedOP721Contract interface extends IOP721Contract with additional functionality for NFT collections that require minting controls, reservations, and claims. This interface is suitable for NFT launches and collections with controlled distribution mechanisms.
Contract Classes
IBaseContract
The IBaseContract<T> abstract class implements IContract and provides the core implementation for all contract interactions. It is a generic class that accepts a type parameter extending BaseContractProperties, enabling type-safe method calls based on the contract's ABI.
This class handles ABI parsing, calldata encoding and decoding, event processing, gas estimation, and communication with the provider.
BaseContract
The BaseContract<T> class extends IBaseContract<T> and adds JavaScript Proxy functionality. This proxy enables dynamic method resolution, allowing contract instances to expose ABI-defined methods as first-class properties. When a method is called on the contract instance, the proxy intercepts the call, encodes the calldata, executes the call through the provider, and returns a typed CallResult object.
Factory Function
getContract
The getContract<T>() factory function is the recommended approach for creating type-safe contract instances. It accepts a generic type parameter that specifies the contract interface (such as IOP20Contract or IOP721Contract), along with the contract address, ABI, provider, network, and optional sender address. The function returns a BaseContract<T> instance that exposes all ABI-defined methods as strongly-typed functions.