Zetrix Documentation (EN)
  • Introduction
    • Overview of Zetrix
    • Why Build on Zetrix
  • GETTING STARTED
    • Quick Start Guide
    • Key Concept
  • ARCHITECTURE
    • Blockchain Layer
    • Consensus Mechanism
      • DPos
      • BFT
    • Node Type
    • Security
  • DEVELOPER RESOURCES
    • Smart Contract Development Toolkit
    • Smart Contract
      • Introduction
      • ZTP Standard
        • ZTP-20
        • ZTP-165
        • ZTP-721
        • ZTP-1155
      • Syntax
    • API
      • Overview
      • HTTP
      • Websocket
      • Keypair
    • SDK
      • Node.js
      • Go
      • Java
    • Interoperability
    • Testing and Auditing
      • Asset Issuance
      • Legal Evidence
      • Smart Contract Assets
    • Verifiable Credentials
      • Getting Started
      • API Reference
  • Node & Validator
    • Overview and System Requirements
    • Node Installation
      • Dedicated Address
      • Docker Deployment
    • Maintenance
    • Node Monitoring
    • Common Problems
  • GOVERNANCE
    • On-Chain Governance
    • Distribution of Interests
  • TOKENOMICS
    • Native Token
    • Staking and Rewards
    • Gas Fees and Transaction
  • ECOSYSTEM
    • DApps and Projects
    • Partnerships
    • Explorer and Analytics
  • Wallets
    • Supported Wallets
    • Wallet Intergration
  • Blockchain as a Service
    • BaaS
      • Zetrix Service
        • Core
        • Transaction
        • Contract
    • Zetrix Oraclize
    • Scheduler Contract
  • MISC
    • Burn Address
  • Troubleshooting & FAQ
    • Terminology
    • Security Best Practices
  • Community & Support
    • Developer Community
    • Official Support
    • Contributing to the Blockchain
Powered by GitBook
On this page
  • Simple Summary
  • Abstract
  • Motivation
  • Specification Token Methods
  • Zetrix Ecosystem Proposals
  1. DEVELOPER RESOURCES
  2. Smart Contract
  3. ZTP Standard

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

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.

self.symbol = function () {
    let info = BasicOperationUtil.loadObj(CONTRACT_INFO);
    return info.symbol;
};

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.

self.decimals = function () {
        let info = BasicOperationUtil.loadObj(CONTRACT_INFO);
        return info.decimals;
};

totalSupply

Returns the total token supply.

self.totalSupply = function () {
    let info = BasicOperationUtil.loadObj(CONTRACT_INFO);
    let supply = info.supply;
    if (supply === false) {
        supply = "0";
    }
    return supply;
};

balanceOf

Returns the account balance of another account with address account.

self.balanceOf = function (paramObj) {
    let balance = BasicOperationUtil.loadObj(BasicOperationUtil.getKey(BALANCES_PRE, paramObj.account));
    if (balance === false) {
        balance = "0";
    }
    return balance;
};

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.

self.transfer = function (paramObj) {
    _transfer(Chain.msg.sender, paramObj.to, paramObj.value);
    return true;
};

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.

self.transferFrom = function (paramObj) {
    let spender = Chain.msg.sender;
    self.p.spendAllowance(paramObj.from, spender, paramObj.value);
    _transfer(paramObj.from, paramObj.to, paramObj.value);
    return true;
};

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.

self.approve = function (paramObj) {
    self.p.approve(Chain.msg.sender, paramObj.spender, paramObj.value);
    return true;
};

allowance

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

self.allowance = function (paramObj) {
    let allowance = BasicOperationUtil.loadObj(BasicOperationUtil.getKey(ALLOWANCES_PRE, paramObj.owner, paramObj.spender));
    if (allowance === false) {
        allowance = "0";
    }
    return allowance;
};
PreviousZTP StandardNextZTP-165

Last updated 3 months ago

Sample ZTP20 contract can be found .

Zetrix Ecosystem Proposals
here