OP-20 Standard

The OP-20 standard provides a unified specification for fungible tokens within the OP_NET ecosystem. This reference is intended for developers who need to implement compliant tokens or integrate OP-20 functionality into their applications.

IOP20 Interface

The IOP20 interface specifies all methods and properties that an OP-20 token must implement:

IOP20 Interfaceassemblyscript
interface IOP20 {
    name(): string;
    symbol(): string;
    decimals(): u8;
    icon(): string;
    totalSupply(): u256;
    metadata(): 
        {name: string, symbol: string, icon: string, decimals: u8, totalSupply: u256, domainSeparator: u8[32]};
    domainSeparator(): u8[32];
    balanceOf(owner: Address): u256;
    nonceOf(owner: Address): u256;
    allowance(owner: Address, spender: Address): u256;
    safeTransfer(to: Address, amount: u256, data?: u8[]): void;
    safeTransferFrom(from: Address, to: Address, amount: u256, data?: u8[]): void;
    transfer(to: Address, amount: u256): void;
    transferFrom(from: Address, to: Address, amount: u256): void;
    burn(amount: u256): void;
    increaseAllowance(spender: Address, amount: u256): void;
    decreaseAllowance(spender: Address, amount: u256): void;
    increaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, 
        deadline: u64, signature: u8[]): void;
    decreaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, 
        deadline: u64, signature: u8[]): void;
}

Methods & Properties Reference

name(): string
symbol(): string
decimals(): u8
icon(): string
totalSupply(): u256
metadata(): { name: string, symbol:string, icon: string, decimals: u8, totalSupply: u256, domainSeparator: u8[32] }
domainSeparator(): u8[32]
balanceOf(owner: Address): u256
nonceOf(owner: Address): u256
allowance(owner: Address, spender: Address): u256
safeTransfer(to: Address, amount: u256, data?: u8[]): void
safeTransferFrom(from: Address, to: Address, amount: u256, data?: u8[]): void
transfer(to: Address, amount: u256): void
transferFrom(from: Address, to: Address, amount: u256): void
burn(amount: u256): void
increaseAllowance(spender: Address, amount:u256): void
decreaseAllowance(spender: Address, amount: u256): void
increaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, deadline: u64, signature: u8[]): void
decreaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, deadline: u64, signature: u8[]): void

Events

The OP-20 standard defines three events: Approved, Burned, and Transferred. These are already implemented by the ApprovedEvent, BurnedEvent, and TransferredEvent classes respectively:

Eventsassemblyscript
class ApprovedEvent extends NetEvent {
    constructor(owner: Address, spender: Address, amount: u256);
}

class BurnedEvent extends NetEvent {
    constructor(from: Address, amount: u256);
}

class TransferredEvent extends NetEvent {
    constructor(operator: Address, from: Address, to: Address, amount: u256);
}

Events Reference

Approved(owner: Address, spender: Address, amount: u256)
Burned(from: Address, amount: u256)
Transferred(operator: Address, from: Address, to: Address, amount: u256)

Callbacks

The OP-20 standard currently includes one callback, defined by the IOP20Receiver interface:

Callbacksassemblyscript
interface IOP20Receiver {
    onOP20Received(operator: Address, from: Address, amount: u256, data: u8[]): u32;
}

Callback Reference

onOP20Received(operator: Address, from: Address, amount: u256, data: u8[]): u32

Data Structures

The OP-20 data structures are defined as follows:

Structuresassemblyscript
OP712Domain(
    domainType: u8[32],
    nameHash: u8[32],
    versionHash: u8[32],
    chainId: u8[32],
    protocolId u8[32] ,
    verifyingContract: Address
);


OP20AllowanceIncrease(
    typeHash: u8[32],
    owner: Address,
    spender: Address,
    amount: u256,
    nonce: u256,
    deadline: u64
);

OP20AllowanceDecrease(
    typeHash: u8[32],
    owner: Address,
    spender: Address,
    amount: u256,
    nonce: u256,
    deadline: u64
);

Data Structures Reference

OP712Domain
OP20AllowanceIncrease
OP20AllowanceDecrease