Returns the token name.
This is a read-only method.
// How to encode the Calldata parameters
// 1st parameter: selector (method to call)
// 2nd parameter: address1
// 3rd parameter: amount1
const calldata = new BytesWriter(
SELECTOR_BYTE_LENGTH +
ADDRESS_BYTE_LENGTH +
U256_BYTE_LENGTH);
calldata.writeSelector('FUNCTION SELECTOR HERE');
calldata.writeAddress(address1);
calldata.writeU256(amount1);
// How to decode BytesWriter return values
const response = Blockchain.call(token, calldata);
if (response.data.byteLength != 0){
thow new Revert('Invalid response.');
}
// Decode response
const value = response.data.readU256();
const name = response.data.readStringWithLength();The OP20 class is the OP_NET concrete implementation of the OP-20 standard. It implements the IOP20 interface and extends ReentrancyGuard, which provides both OP_NET base class inheritance and built-in reentrancy attack protection.
Protected methods can be overridden to implement custom logic or extend the default behavior, providing flexibility for specialized token implementations.
abstract class OP20 extends ReentrancyGuard implements IOP20 {
public name(_: Calldata): BytesWriter;
public symbol(_: Calldata): BytesWriter;
public decimals(_: Calldata): BytesWriter;
public icon(_: Calldata): BytesWriter;
public totalSupply(_: Calldata): BytesWriter;
public maximumSupply(_: Calldata): BytesWriter;
public metadata(_: Calldata): BytesWriter;
public domainSeparator(_: Calldata): BytesWriter;
public balanceOf(calldata: Calldata): BytesWriter;
public nonceOf(calldata: Calldata): BytesWriter;
public allowance(calldata: Calldata): BytesWriter;
public safeTransfer(calldata: Calldata): BytesWriter;
public safeTransferFrom(calldata: Calldata): BytesWriter;
public transfer(calldata: Calldata): BytesWriter;
public transferFrom(calldata: Calldata): BytesWriter;
public burn(calldata: Calldata): BytesWriter;
public increaseAllowance(calldata: Calldata): BytesWriter;
public decreaseAllowance(calldata: Calldata): BytesWriter;
public increaseAllowanceBySignature(calldata: Calldata): BytesWriter;
public decreaseAllowanceBySignature(calldata: Calldata): BytesWriter;
// Used for token deployments
public instantiate(params: OP20InitParameters, skipDeployerVerification: boolean = false): void;
// Overrides
protected _balanceOf(owner: Address): u256;
protected _allowance(owner: Address, spender: Address): u256;
protected _safeTransfer(from: Address, to: Address, amount: u256, data: Uint8Array): void;
protected _transfer(from: Address, to: Address, amount: u256): void;
protected _spendAllowance(owner: Address, spender: Address, amount: u256): void;
protected _callOnOP20Received( from: Address, to: Address, amount: u256,data: Uint8Array): void;
protected _increaseAllowance(owner: Address, spender: Address, amount: u256): void;
protected _decreaseAllowance(owner: Address, spender: Address, amount: u256): void;
protected _increaseAllowanceBySignature(owner: Address,spender: Address,amount: u256,deadline: u64,signature: Uint8Array): void;
protected _decreaseAllowanceBySignature(owner: Address, spender: Address, amount: u256, deadline: u64, signature: Uint8Array): void;
protected _verifySignature(typeHash: u8[], owner: Address, spender: Address, amount: u256, deadline: u64, signature: Uint8Array): void;
protected _buildDomainSeparator(): Uint8Array;
protected _mint(to: Address, amount: u256): void;
protected _burn(from: Address, amount: u256): void;
}Returns the token name.
This is a read-only method.
Returns the token symbol.
This is a read-only method.
Returns the number of decimal places used by the token. Valid range: 0-32. A value of 0 creates indivisible tokens.
This is a read-only method.
Returns the token's icon URL (http(s) or ipfs) for wallet/UI display.
This is a read-only method.
Returns the current circulating amount of tokens.
This is a read-only method.
Returns the maximum number of tokens that can exists.
This is a read-only method.
Get all token metadata in a single call.
This is a read-only method.
Returns a SHA-256 hash representing the unique domain separator. The hash must be derived from the OP712Domain structure.
Calls the protected _buildDomainSeparator() method, which provides the default implementation.
This is a read-only method.
Returns the actual token balance for an address. Non-existent addresses return 0.
Calls the protected _balanceOf() method, which provides the default implementation.
This is a read-only method.
Returns the current nonce for an address. Non-existent addresses return 0.
This is a read-only method.
Returns the "spender's" remaining allowance from the "owner's" account. Non-existent addresses return 0.
Calls the protected _allowance() method, which provides the default implementation.
This is a read-only method.
Transfers amount of tokens from the caller's account to the to address with delivery confirmation for contract recipients. An arbitrary data payload can be specified.
The following validations are performed:
Calls the protected _safeTransfer() method, which provides the default implementation.
Transfers amount of tokens from the from address to the to address with delivery confirmation for contract recipients. An arbitrary data payload can be specified.
The following validations/actions are performed:
Calls the protected _spendAllowance() and _safeTransfer() methods, which provides the default implementation.
Transfers amount of tokens from the caller's account to the to address.
The following validations are performed:
Calls the protected _transfer() method, which provides the default implementation.
Transfers amount of tokens from the from address to the to address.
The following validations/actions are performed:
Calls the protected _spendAllowance() and _transfer() methods, which provides the default implementation.
Atomically subtract amount from the caller’s balance and reduce totalSupply by the same amount.
The following validations are performed:
Calls the protected _burn() method, which provides the default implementation.
Atomically increase spender allowance permission on the owner's account for the specified amount.
The following validations/actions are performed:
Calls the protected _increaseAllowance() method, which provides the default implementation.
Atomically decrease spender allowance permission on the owner's account for the specified amounts.
The following validations/actions are performed:
Calls the protected _decreaseAllowance() method, which provides the default implementation.
Atomically increase spender allowance off-chain on the owner's account for the specified amount.
The following validations/actions are performed:
Calls the protected _increaseAllowanceBySignature() method, which provides the default implementation.
Atomically decrease spender allowance off-chain on the owner's account for the specified amount.
The following validations/actions are performed:
Calls the protected _decreaseAllowanceBySignature() method, which provides the default implementation.
Initialize the token metadata only once, immediately after deployment. After initialization, these values are immutable.
By default only the deployer may initialize. If deployer verification is skipped, a designated non-deployer may perform this one-time initialization.
Checks the balance map for the given owner address and returns the current balance, or 0 if the owner is not found.
Checks the allowance map for the given owner and spender addresses and returns the remaining allowance, or 0 if none is set.
Performs the actual safe transfer operation for the specified amount from the from address to the to address:
Performs the actual transfer operation for the specified amount from the from address to the to address:
Spends the given amount by reducing the available allowance from the allowance map:
Calls onOP20Received on the recipient contract with calldata conforming to the method specification. The method reverts:
Performs the actual allowance increase operation for the specified amount:
Performs the actual allowance decrease operation for the specified amount:
Performs the actual signed allowance increase operation:
Performs the actual signed allowance decrease operation:
Validates the signature and increments the owner's nonce on success:
Constructs the domain separator buffer compliant with the OP712Domain structure, which is then used to generate the SHA-256 hash.
Mints new tokens to the specified address:
Burns existing tokens from the specified address:
The OP20 class emits the three OP-20 standard events: Approved, Burned, and Transferred.
Additionally, the OP20 class emits a Minted event, which is specific to this implementation and is implemented by the MintedEvent class.
class ApprovedEvent extends NetEvent {
constructor(owner: Address, spender: Address, amount: u256);
}
class BurnedEvent extends NetEvent {
constructor(from: Address, amount: u256);
}
class MintedEvent extends NetEvent {
constructor(to: Address, amount: u256)
}
class TransferredEvent extends NetEvent {
constructor(operator: Address, from: Address, to: Address, amount: u256);
}
Emitted when allowance is modified through any method.
The following OP20 methods emits this event in their provided implementations:
Emitted when tokens are permanently removed from circulation, decreasing total number of tokens in circulation (totalSupply).
The following OP20 methods emits this event in their provided implementations:
Emitted when new tokens are created, increasing total number of in circulation (totalSupply).
The following OP20 methods emits this event in their provided implementations:
Emitted on all successful transfers.
The following OP20 methods emits this event in their provided implementations:
The IOP20Receiver interface is not implemented by the OP20 abstract class. Instead, derived classes must provide their own implementation.
interface IOP20Receiver {
onOP20Received(callData: Calldata): BytesWriter;
}
// Example
@final
export class ContractEx extends ReentrancyGuard implements IOP20Receiver {
...
public override execute(method: Selector, calldata: Calldata): BytesWriter {
let writer: BytesWriter;
switch (method) {
case encodeSelector('onOP20Received(address,address,uint256,bytes)'):
return this.onOP20Received(calldata);
default:
return super.execute(method, calldata);
}
return writer;
}
public onOP20Received(calldata: Calldata): BytesWriter {
const operator = calldata.readAddress();
const from = calldata.readAddress();
const amount = calldata.readU256();
const data: Uint8Array = calldata.readBytesWithLength();
// Custom logic here if needed
...
const writer = new BytesWriter(SELECTOR_BYTE_LENGTH);
writer.writeSelector(ON_OP_20_RECEIVED_SELECTOR);
return writer;
}
...
}The token metadata used to initialize the token when calling the instantiate() method during deployment.
Type definitions only, not concrete implementations:
These type definitions define the data schema used by methods for signature validation and hash generation, such as signed allowance operations and the domainSeparator method.
Refer to the OP-20 Standard specification for detailed definitions.