ZTP-20

Simple Summary

A standard interface for tokens.

Abstract

The following standard allows for the implementation of a standard API for tokens within smart contracts. This standard provides basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party.

Motivation

A standard interface allows any tokens on Zetrix to be re-used by other applications: from wallets to decentralized exchanges.

Specification Token Methods

Metadata

name

Returns the name of the token - e.g. "MyToken"

OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

self.name = function(paramObj) {
    let name = ...;
    return name;
};

Query Example

To get the token name, use the following request and expect the response below:

Request:

Response:

Sample query Function:

symbol

Returns the symbol of the token. E.g. “MYTKN”

OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present.

Query Example

To get the token symbol, use the following request and expect the response below:

Request:

Response:

Sample query Function:

decimals

Returns the number of decimals the token uses - e.g. 6, means to divide the token amount by 1000000 to get its user representation.

Query Example

To get the token decimals, use the following request and expect the response below:

Request:

Response:

Sample query Function:

Core

totalSupply

Returns the total token supply.

Query Example

To get the total token supply, use the following request and expect the response below:

Request:

Response:

Sample query Function:

balanceOf

Returns the account balance of another account with address account.

Query Example

To get the balance of an account, use the following request and expect the response below:

Request:

Response:

Sample query function:

transfer

Transfers value amount of tokens to address to. The function SHOULD throw an exception if the message caller’s account balance does not have enough tokens to spend.

Submit transfer Example

To transfer tokens, use the following request and expect the response below:

Request:

Response:

Sample main Function:

transferFrom

Transfers value amount of tokens from address from to address to.

The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and/or to charge fees in sub-currencies. The function SHOULD throw an exception unless the from account has deliberately authorized the sender of the message.

Submit transferFrom Example

To transfer tokens from another account, use the following request and expect the response below:

Request:

Response:

Sample main Function:

approve

Allows spender to withdraw from your account multiple times, up to the value amount. If this function is called again it overwrites the current allowance with value.

Submit approve Example

To approve a spender, use the following request and expect the response below:

Request:

Response:

Sample main Function:

allowance

Returns the amount which spender is still allowed to withdraw from owner.

Query allowance Example

To check the allowance for a spender, use the following request and expect the response below:

Request:

Response:

Sample main Function:

Extension

Permit

The permit function enables gasless approvals for ZTP20 tokens by allowing an owner to approve a spender via an off-chain signature, instead of an on-chain approve transaction. This design is inspired by EIP-2612, adapted for the Zetrix / ZTP20 execution environment and cryptographic primitives.

The permit mechanism allows a token holder to approve an allowance via an off-chain signature, which may subsequently be submitted on-chain by any relayer that pays the associated transaction fee.

Function Signature

Parameters

Parameter
Type
Description

owner

address

Token holder granting the allowance

spender

address

Address receiving spending rights

value

int64 (string)

Allowance amount to approve

deadline

int64 (string)

Expiration timestamp for the permit

p

bytes

Public key of the signer

s

bytes

Signature generated by the owner

Invoke Example

The permit function is a main contract function (transaction/invoke), not a query. It is used to submit a transaction that enables gasless approval for a spender using an off-chain signature.

Sample main function call:

Sample request:


Last updated