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;
icon(): string;
decimals(): u8;
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 and Properties
name(): string| Name | Type | Description |
|---|---|---|
| name | string | Token name. |
symbol(): stringReturns the token symbol.
| Name | Type | Description |
|---|---|---|
| symbol | string | Token symbol. |
icon(): stringReturns the token's icon URL (http(s) or ipfs) or identifier for wallet/UI display.
| Name | Type | Description |
|---|---|---|
| icon | string | Icon URL. |
decimals(): u8Returns the number of decimal places used by the token. Valid range: 0-32. A value of 0 creates indivisible tokens.
| Name | Type | Description |
|---|---|---|
| decimals | u8 | Number of decimals. |
totalSupply(): u256Returns the current circulating amount of tokens.
| Name | Type | Description |
|---|---|---|
| totalSupply | u256 | Current total supply. |
metadata():
{
name: string,
symbol:string,
icon: string,
decimals: u8,
totalSupply: u256,
domainSeparator: u8[32]
}Returns all token metadata in a single call.
| Name | Type | Description |
|---|---|---|
| name | string | Token name. |
| symbol | string | Token symbol. |
| icon | string | Icon URL. |
| decimals | u8 | Number of decimals. |
| totalSupply | u256 | Current total supply. |
| domainSeparator | u8[32] | 32-byte domain separator hash. |
domainSeparator(): u8[32]Returns a SHA-256 hash representing the unique domain separator. The hash must be derived from the OP712Domain structure.
| Name | Type | Description |
|---|---|---|
| domainSeparator | u8[32] | 32-byte domain separator hash. |
balanceOf(owner: Address): u256Returns the actual token balance for an address. Non-existent addresses must return 0.
| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - |
| Name | Type | Description |
|---|---|---|
| balance | u256 | Balance. |
nonceOf(owner: Address): u256Returns the current nonce for an address. Non-existent addresses must return 0.
| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - |
| Name | Type | Description |
|---|---|---|
| nonce | u256 | Current nonce. |
allowance(owner: Address, spender: Address): u256Returns the spender's remaining allowance from the owner's account. Non-existent addresses must return 0.
| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - | |
| spender | Address | - |
| Name | Type | Description |
|---|---|---|
| remaining | u256 | Remaining allowance. |
safeTransfer(to: Address, amount: u256, data?: u8[]): voidTransfers 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.
| Name | Type | Required | Description |
|---|---|---|---|
| to | Address | - | |
| amount | u256 | - | |
| data? | u8[] | - | Optional data. |
| Type | Description |
|---|---|
| Transferred | Must emit a Transferred event. |
safeTransferFrom(from: Address, to: Address, amount: u256, data?: u8[]): voidTransfers 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
| Name | Type | Required | Description |
|---|---|---|---|
| from | Address | - | |
| to | Address | - | |
| amount | u256 | - | |
| data? | u8[] | - | Optional data. |
| Type | Description |
|---|---|
| Transferred | Must emit a Transferred event. |
transfer(to: Address, amount: u256): voidTransfers 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.
| Name | Type | Required | Description |
|---|---|---|---|
| to | Address | - | |
| amount | u256 | - |
| Type | Description |
|---|---|
| Transferred | Must emit a Transferred event. |
transferFrom(from: Address, to: Address, amount: u256): voidTransfers 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.
| Name | Type | Required | Description |
|---|---|---|---|
| from | Address | - | |
| to | Address | - | |
| amount | u256 | - |
| Type | Description |
|---|---|
| Transferred | Must emit a Transferred event. |
burn(amount: u256): voidAtomically 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.
| Name | Type | Required | Description |
|---|---|---|---|
| amount | u256 | - |
| Type | Description |
|---|---|
| Burned | Must emit a Burned event. |
increaseAllowance(spender: Address, amount:u256): voidAtomically 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.
| Name | Type | Required | Description |
|---|---|---|---|
| spender | Address | - | |
| amount | u256 | - |
| Type | Description |
|---|---|
| Approved | Must emit an Approved event. |
decreaseAllowance(spender: Address, amount: u256): voidAtomically 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.
| Name | Type | Required | Description |
|---|---|---|---|
| spender | Address | - | |
| amount | u256 | - |
| Type | Description |
|---|---|
| Approved | Must emit an Approved event. |
increaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, deadline: u64, signature: u8[]): voidAtomically 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.
| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - | |
| spender | Address | - | |
| amount | u256 | - | |
| deadline | u64 | - | |
| signature | u8[] | - |
| Type | Description |
|---|---|
| Approved | Must emit an Approved event. |
decreaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, deadline: u64, signature: u8[]): voidAtomically 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.
| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - | |
| spender | Address | - | |
| amount | u256 | - | |
| deadline | u64 | - | |
| signature | u8[] | - |
| Type | Description |
|---|---|
| Approved | Must emit an Approved event. |
Events
The OP_20 standard defines three events: Approved, Burned, and Transferred. These are already implemented by the OP20ApprovedEvent, OP20BurnedEvent, and OP20TransferredEvent classes respectively:
Approved
class OP20ApprovedEvent extends NetEvent
constructor(owner: Address, spender: Address, amount: u256);
}Reference
constructor(owner: Address, spender: Address, amount: u256)| Name | Type | Required | Description |
|---|---|---|---|
| owner | Address | - | Token owner. |
| spender | Address | - | Authorized spender. |
| amount | u256 | - | New total allowance (not delta). |
Burned
class OP20BurnedEvent extends NetEvent {
constructor(from: Address, amount: u256);
}Reference
constructor(from: Address, amount: u256)| Name | Type | Required | Description |
|---|---|---|---|
| from | Address | - | Address losing tokens. |
| amount | u256 | - | Number of tokens destroyed. |
Transferred
class OP20TransferredEvent extends NetEvent {
constructor(operator: Address, from: Address, to: Address, amount: u256);
}Reference
constructor(operator: Address, from: Address, to: Address, amount: u256)| Name | Type | Required | Description |
|---|---|---|---|
| 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;
}Reference
onOP20Received(operator: Address, from: Address, amount: u256, data: u8[]): u32Smart 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.
| Name | Type | Required | Description |
|---|---|---|---|
| operator | Address | - | Who initiated the transfer. |
| from | Address | - | Original token owner. |
| amount | u256 | - | Number of tokens received. |
| data | u8[] | - | Additional data. |
| Name | Type | Description |
|---|---|---|
| value | u32 | To accept the transfer, return value must be ON_OP20_RECEIVED_SELECTOR (0xd83e7dbc). To reject it, return any other values. |
Data Structures
OP712Domain
OP712Domain(
domainType: u8[32],
nameHash: u8[32],
versionHash: u8[32],
chainId: u8[32],
protocolId u8[32] ,
verifyingContract: Address
);Reference
OP712Domain| Name | Type | Required | Description |
|---|---|---|---|
| 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. |
OP20AllowanceIncrease
OP20AllowanceIncrease(
typeHash: u8[32],
owner: Address,
spender: Address,
amount: u256,
nonce: u256,
deadline: u64
);Reference
OP20AllowanceIncrease| Name | Type | Required | Description |
|---|---|---|---|
| typeHash | u8[] | - | sha256('OP20AllowanceIncrease(address owner,address spender,uint256 amount,uint256 nonce,uint64 deadline)') |
| owner | Address | - | |
| spender | Address | - | |
| amount | u256 | - | |
| nonce | u256 | - | |
| deadline | u64 | - |
OP20AllowanceDecrease
OP20AllowanceDecrease(
typeHash: u8[32],
owner: Address,
spender: Address,
amount: u256,
nonce: u256,
deadline: u64
);Reference
OP20AllowanceDecrease| Name | Type | Required | Description |
|---|---|---|---|
| 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. |