Returns the token name.
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:
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
Returns the token symbol.
- symbol: string
Returns the number of decimal places used by the token. Valid range: 0-32. A value of 0 creates indivisible tokens.
- decimals: u8
Returns the token's icon URL (http(s) or ipfs) or identifier for wallet/UI display.
- icon: string
Returns the current circulating amount of tokens.
- totalSupply: u256
Returns all token metadata in a single call.
- name: string
- symbol: string
- icon: string
- decimals: u8
- totalSupply: u256
- domainSeparator: u8[32]
Returns a SHA-256 hash representing the unique domain separator. The hash must be derived from the OP712Domain structure.
- domainSeparator: u8[32]
Returns the actual token balance for an address. Non-existent addresses must return 0.
- owner: Address
- balance: u256
Returns the current nonce for an address. Non-existent addresses must return 0.
- owner: Address
- nonce: u256
Returns the spender's remaining allowance from the owner's account. Non-existent addresses must return 0.
- owner: Address
- spender: Address
- amount: u256
Transfers amount of tokens to the "to" address with delivery confirmation for contract recipients.
The method must revert if:
- The sender have insufficient balance.
- The to is the zero address or the dead address.
- A failed acknowledgments is received.
- to: Address
- amount: u256
- data?: u8[] - Optional data.
- void
- Transferred : Must emit a Transferred event.
Transfers amount of tokens from the "from" address to the "to" address with delivery confirmation for contract recipients.
The method must revert if:
- Spends allowance is too low or not set (unless sender equals from).
- The sender have insufficient balance.
- The to is the zero address or the dead address.
- A failed acknowledgments is received.
The method must handle infinite allowance (u256.Max) without decrementing
- from: Address
- to: Address
- amount: u256
- data?: u8[] - Optional data.
- void
- Transferred : Must emit a Transferred event.
Transfers amount of tokens to the "to" address.
The method must revert if:
- The sender have insufficient balance.
- The to is the zero address or the dead address.
- to: Address
- amount: u256
- void
- Transferred : Must emit a Transferred event.
Transfers amount of tokens from the "from" address to the "to" address.
The method must revert if:
- Spends allowance is too low or not set (unless sender equals from).
- The sender have insufficient balance.
- The to is the zero address or the dead address.
The method must handle infinite allowance (u256.Max) without decrementing.
- from: Address
- to: Address
- amount: u256
- void
- Transferred : Must emit a Transferred event.
Atomically subtract amount from the caller’s balance and reduce totalSupply by the same amount.
The method must revert if:
- The caller is the zero address or the dead address.
- The amount is smaller then the caller balance.
- amount: u256
- void
- Burned : Must emit a Burned event.
Atomically increase spender allowance permission on the owner's account for the specified amount.
The method must revert if:
- The spender addresss is the zero address or the dead address.
Requirements:
- The method must handle overflow by setting allowance to u256.Max.
- spender: Address
- amount: u256
- void
- Approved : Must emit an Approved event.
Atomically decrease spender allowance permission on the owner's account for the specified amount.
The method must revert if:
- The spender addresss is the zero address or the dead address.
Requirements:
- The method must handle undeflow by setting the allowance to 0.
- spender: Address
- amount: u256
- void
- Approved : Must emit an Approved event.
Atomically increase spender allowance off-chain on the owner's account for the specified amount.
The method must revert if:
- The spender addresss is the zero address or the dead address.
- The signature verification fail.
Requirements:
- The message must be signed in accordance with the OP20AllowanceIncrease structure.
- The method must handle overflow by setting allowance to u256.Max.
- owner: Address
- spender: Address
- amount: u256
- deadline: u64
- signature: u8[]
- void
- Approved : Must emit an Approved event.
Atomically decrease spender allowance off-chain on the owner's account for the specified amount.
The method must revert if:
- The spender addresss is the zero address or the dead address.
- The signature verification fail.
Requirements:
- The message must be signed in accordance with the OP20AllowanceDecrease structure.
- The method must handle underflow by setting allowance to 0.
- owner: Address
- spender: Address
- amount: u256
- deadline: u64
- signature: u8[]
- void
- Approved : Must emit an Approved event.
Events
The OP-20 standard defines three events: Approved, Burned, and Transferred. These are already implemented by the ApprovedEvent, BurnedEvent, and TransferredEvent classes respectively:
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
- owner: Address - Token owner.
- spender: Address - Authorized spender.
- amount: u256 - New total allowance (not delta).
- from: Address - Address losing tokens.
- amount: u256 - Number of tokens destroyed.
- operator: Address - Who initiated the transfer.
- from: Address - Source of tokens.
- to: Address - Destination of tokens.
- amount: u256 - Number of tokens transferred.
Callbacks
The OP-20 standard currently includes one callback, defined by the IOP20Receiver interface:
interface IOP20Receiver {
onOP20Received(operator: Address, from: Address, amount: u256, data: u8[]): u32;
}Callback Reference
Smart contracts accepting OP-20 tokens must implement this method to provide delivery confirmation to the safe transfer operations. A return value other than ON_OP20_RECEIVED_SELECTOR or a revert must causes transfer to fail.
- operator: Address - Who initiated the transfer.
- from: Address - Original token owner.
- amount: u256 - Number of tokens received.
- data: u8[] - Additional data.
- value: u32. To accept the transfer, return value must be ON_OP20_RECEIVED_SELECTOR (0xd83e7dbc). To reject it, return any other values.
Data Structures
The OP-20 data structures are defined as follows:
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
- domainType: u8[32] - sha256('OP712Domain(string name,string version,bytes32 chainId,bytes32 protocolId,address verifyingContract)')
- nameHash: u8[32] - sha256 of the token name.
- versionHash: u8[] - sha256('1')
- chainId: u8[32] - OP_NET chain identifier.
- protocolId: u8[32] - OP_NET protocol identifier.
- verifyingContract: Address - Token contract address.
- typeHash: u8[] - sha256('OP20AllowanceIncrease(address owner,address spender,uint256 amount,uint256 nonce,uint64 deadline)')
- owner: Address
- spender: Address
- amount: u256
- nonce: u256
- deadline: u64
- typeHash: u8[] - sha256('OP20AllowanceDecrease(address owner,address spender,uint256 amount,uint256 nonce,uint64 deadline)')
- owner: Address
- spender: Address
- amount: u256
- nonce: u256
- deadline: u64 - Expiration block.