Developer Documentation
  • What is CTEX?
  • Learn about CTEX Chain
    • Ctex Overview: vision, strategy and platform components
    • The Ctex Blockchain
      • Ctex Consensus Mechanism
      • Delegation and Staking with Validators
      • Ethereum (EVM) Compatibility and Smart Contracts
      • Boosting Ctex's Scalability
  • Empowering Global Payments with Ctex
  • Ctex Key Feature
  • Ctex Consensus
  • CTEX Clusters
    • CTEXChain Mainnet
    • CTEXChain Testnet
    • CLI Command
    • Ctex Faucet
    • Audit Report
  • Integrating with Metamask
    • Add Ctex Chain Network to Metamask
    • Config Custom Token
    • How to Reset Metamask Wallet
  • CTEX Exclusive Product
  • Ctex Coin
    • Technical
    • Utility
    • Distribution
  • Run Master Node
  • Developer Guide
    • Token Standard
      • CTEX-721 Token
      • CTEX-20 Token
  • APIs
    • accounts
    • blockNumber
    • call
    • chainId
    • estimateGas
    • gasPrice
    • getBalance
    • getBlockByHash
    • getBlockByNumber
    • getBlockTransactionCountByHash
    • getBlockTransactionCountByNumber
    • getCode
    • getLogs
    • getStorageAt
    • getTransactionByBlockHashAndIndex
    • getTransactionByBlockNumberAndIndex
    • getTransactionByHash
    • getTransactionCount
    • getTransactionReceipt
    • getUncleByBlockHashAndIndex
    • getUncleByBlockNumberAndIndex
    • getUncleCountByBlockHash
    • getUncleCountByBlockNumber
    • getWork
    • hashrate
    • mining
    • protocolVersion
    • sendRawTransaction
    • submitWork
    • syncing
    • net_listening
    • net_peerCount
    • net_version
    • web3_clientVersion
    • parity_nextNonce
    • Filter methods
    • newFilter
    • newBlockFilter
    • getFilterChanges
    • uninstallFilter
  • Depolying CTEX chain
    • Using Remix
    • Using Truffle
    • Using Hardhat
    • Using Replit
    • Using Alchemy
  • Whitepaper
  • Technical Paper
  • Yellow Paper
Powered by GitBook
On this page
  1. Developer Guide
  2. Token Standard

CTEX-20 Token

CTEX-20 Tokens on CTEX Chain

This token standard is equivalent of ERC20 built on top of the CTEX Chain network. Users would have to need CTEX in order to cover the transaction fees for sending CTEX-20 tokens. These tokens can be easily integrated into other dapps and get listed on cryptocurrency exchanges.

There is a separate smart contract for creating and issuing CTEX-20 tokens for interested parties or developers where all they have to do is enter name, ticker, details and quantity of tokens to mint it within 10 minutes.

CTEX-20 smart contract ABI:

CTEX20Contract Interface

Copy

Explainfunction totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);

event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);

CTEX Chain provides RPC APIs to developers for using Web3 library to call functions directly in a smart contract. Follow the steps below to interact with the smart contract by using Web3 Library and NodeJS.

Init Web3 Provider

Firstly, init Web3 provider by connecting CTEX Chain Fullnode RPC endpoint.

Check CTEX Chain Network page to find details about Testnet or Mainnet network information.

Copy

const Web3 = require('web3')
const web3 = new Web3('https://www.mainnet.rpc.ctexscan.com')
const chainId = 13375

Unlock Wallet

Refer Create new wallet page for creating/unlocking a new wallet.

Example:

Copy

Explain// Unlock wallet by private key
const account = web3.eth.accounts.privateKeyToAccount(pkey)
const holder = account.address
web3.eth.accounts.wallet.add(account)
web.eth.defaultAccount = holder

Init Web3 CTEX20 Contract

Copy

Explainconst ctex20Abi = require('./CTEX20.json')
const address = '[enter_your_contract_address]'
const ctex20 = new web3.eth.Contract(ctex20Abi,
        address, {gasPrice: 250000000, gas: 2000000 })

Check Balance

Use call function balanceOf() from CTEX20 contract to check token balance for any address.

Example:

Copy

Explain ctex20.methods.balanceOf(holder).call()
.then((result) => {
    console.log(result)
}).catch(e => console.log(e))

Estimate TX Fee (gas)

To send tokens, CTEX is needed to cover the transaction fees.

Method:

Copy

myContract.methods.myMethod([param1[, param2[, ...]]]).estimateGas(options[, callback])

Example:

Copy

Explain ctex20.methods.transfer(to, '500000000000000000000').estimateGas({
    from: holder
})
.then((result) => {
    console.log(result)
}).catch(e => console.log(e))

Token Transfer

To transfer CTEX20token, transfer function is used.

Example:

Copy

Explain// send 500000000000000000000 tokens to this address (e.g decimals 18)
const to = "0xdFfD678E4e06d0d56C74EBa4fef50C710c4b5291"
ctex20.methods.transfer(to, '500000000000000000000').send({
    from: holder,
    gas: 2000000,
    gasPrice: 250000000,
    chainId: chainId
})
.then((result) => {
    console.log(result)
}).catch(e => console.log(e))
PreviousCTEX-721 TokenNextAPIs

Last updated 1 year ago