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
Matadata
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 () {
let info = BasicOperationUtil.loadObj(CONTRACT_INFO);
return info.name;
};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.
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.
Core
totalSupply
Returns the total token supply.
balanceOf
Returns the account balance of another account with address account.
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.
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.
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.
allowance
Returns the amount which spender is still allowed to withdraw from owner.
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
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
Sample ZTP20 contract can be found here.
Last updated