How to Create an XRC-20 Token the Simple Way

  • XRC-20 tokens are simple and easy to deploy, as you will see in this tutorial.
  • The XRC-20 standard solves a significant problem, as blockchain-based marketplaces and crypto-wallets need a single, standardized set of commands to communicate with the range of tokens they manage. This includes interaction rules between different tokens, as well as token purchase rules.
  • It was the first popular specification to offer XinFin token standardization. It was not by any means the first, but thanks to its popularity, it will become the industry standard.
function totalSupply() public view returns (uint256);
function balanceOf(address tokenOwner) public view returns (uint);
function allowance(address tokenOwner, address spender)
public view returns (uint);
function transfer(address to, uint tokens) public returns (bool);
function approve(address spender, uint tokens) public returns (bool);
function transferFrom(address from, address to, uint tokens) public returns (bool);
event Approval(address indexed tokenOwner, address indexed spender,
uint tokens);
event Transfer(address indexed from, address indexed to,
uint tokens);
string public constant name;
string public constant symbol;
uint8 public constant decimals;
  • A public function can be accessed outside of the contract itself
  • view basically means constant, i.e. the contract’s internal state will not be changed by the function
  • An event is Solidity’s way of allowing clients e.g. your application frontend to be notified of specific occurrences within the contract
mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;
uint256 totalSupply_;
constructor(uint256 total) public {
totalSupply_ = total;
balances[msg.sender] = _totalSupply;
function totalSupply() public view returns (uint256) {
return totalSupply_;
function balanceOf(address tokenOwner) public view returns (uint) {
return balances[tokenOwner];
function transfer(address receiver,
uint numTokens) public returns (bool) {
require(numTokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender] — numTokens;
balances[receiver] = balances[receiver] + numTokens;
emit Transfer(msg.sender, receiver, numTokens);
return true;
function approve(address delegate,
uint numTokens) public returns (bool) {
allowed[msg.sender][delegate] = numTokens;
emit Approval(msg.sender, delegate, numTokens);
return true;
function allowance(address owner,
address delegate) public view returns (uint) {
return allowed[owner][delegate];
function transferFrom(address owner, address buyer,
uint numTokens) public returns (bool) {
require(numTokens <= balances[owner]);
require(numTokens <= allowed[owner][msg.sender]);
balances[owner] = balances[owner] — numTokens;
allowed[owner][msg.sender] =
allowed[from][msg.sender] — numTokens;
balances[buyer] = balances[buyer] + numTokens;
Transfer(owner, buyer, numTokens);
return true;
library SafeMath { // Only relevant functions
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a — b;
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
balances[msg.sender] = balances[msg.sender].sub(numTokens);
balances[receiver] = balances[receiver].add(numTokens);
balances[buyer] = balances[buyer].add(numTokens);
balances[owner] = balances[owner].sub(numTokens);

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Certificate Transparency Log (Part 1): Public Key Cryptography

{UPDATE} CookieCrunch Hack Free Resources Generator

ProBit Exchange Lists UME Finance (UME)


Best Twilio Authy authenticator alternative

Zen Launches announces Certik as audit partner

Key Control Mistakes all Business Owners Need to Avoid

Wisdom From The Women Leading The Cybersecurity Industry, With Maxine Holt of Omdia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ruslan wing

ruslan wing

More from Medium

XDC SmartLock Integration Project Update 11.15.21

New Listing: Hot Cross (HOTCROSS)

ICONFi starts Tax Support!

How to create and deploy an XRC-20 token on the XinFin blockchain network