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.

Contract interface hierarchy
OP_NET Contract Interface Hierarchy — UML Class Diagram <<interface>> IContract + address: Address | string + p2op: string + setSender(sender): void + decodeEvents(events): OPNetEvent[] + encodeCalldata(method, ...args): Buffer + currentGasParameters(): Promise + decodeEvent(event): OPNetEvent <<abstract>> IBaseContract<T extends BaseContractProperties> + address: string | Address + provider: AbstractRpcProvider + interface: BitcoinInterface + network: Network - defineInternalFunctions(): void implements BaseContract<T> - proxify(): T & BaseContract<T> Proxy-based ABI method resolution <<factory>> getContract <<interface>> BaseContractProperties + [key: symbol]: CallResult <<interface>> IOP_NETContract + deployer(): Promise<CallResult> <<interface>> IOP20Contract + name(): Promise<Name> + symbol(): Promise<SymbolOf> + decimals(): Promise<Decimals> + totalSupply(): Promise<TotalSupply> + balanceOf(owner): Promise<BalanceOf> + transfer(to, amount): Promise<Transfer> + transferFrom(from, to, amt): Promise + allowance(owner, spender): Promise + increaseAllowance(spender, amt): Promise + burn(amount): Promise<Burn> + mint(address, amount): Promise<Mint> <<interface>> IOP721Contract + name(): Promise<NameNFT> + symbol(): Promise<SymbolNFT> + totalSupply(): Promise<TotalSupplyNFT> + ownerOf(tokenId): Promise<OwnerOfNFT> + balanceOf(owner): Promise<BalanceOfNFT> + tokenURI(tokenId): Promise<TokenURI> + approve(op, tokenId): Promise + safeTransfer(to, tokenId, data): Promise + safeTransferFrom(from, to, ...): Promise + setApprovalForAll(op, bool): Promise + burn(tokenId): Promise<BurnNFT> <<interface>> IOP20SContract + pegRate(): Promise<PegRate> + pegAuthority(): Promise<PegAuthority> + isStale(): Promise<IsStale> + updatePegRate(newRate): Promise + transferPegAuthority(addr): Promise + acceptPegAuthority(): Promise + renouncePegAuthority(): Promise <<interface>> IExtendedOP721Contract + setMintEnabled(enabled): Promise + isMintEnabled(): Promise<IsMintEnabled> + airdrop(addresses, amounts): Promise + reserve(quantity): Promise<ReserveNFT> + claim(): Promise<ClaimNFT> + purgeExpired(): Promise<PurgeExpiredNFT> Legend: extends implements creates interface abstract / class factory

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.

How Everything Connects

Contract Type Relationships
OP_NET Contract Type Relationships Interface Hierarchy — defines contract capabilities Class Hierarchy — provides implementation <<interface>> IContract <<interface>> BaseContractProperties <<interface>> IOP_NETContract <<interface>> IOP20Contract <<interface>> IOP721Contract <<interface>> IOP20SContract <<interface>> IExtendedOP721Contract <<interface>> IContract <<abstract>> IBaseContract<T> T extends BaseContractProperties implements BaseContract<T> - proxify(): T & BaseContract<T> <<factory function>> getContract<T>() creates How They Connect Interface Hierarchy Defines the API surface for each contract type. IOP20Contract declares fungible token methods such as transfer, balanceOf, and allowance. IOP721Contract declares NFT methods such as ownerOf, tokenURI, and safeTransfer. IOP20SContract and IExtendedOP721Contract add specialized extensions (peg, mint control). Class Hierarchy Provides the single runtime implementation. IBaseContract implements IContract and handles ABI encoding, decoding, gas estimation, and RPC provider calls for all contract types. BaseContract adds a Proxy that dynamically resolves ABI methods at runtime, typed via the generic T parameter from the interfaces. T binds to Legend: extends implements creates / binds interface abstract / class factory