What is TRC20?

Introduction

TRC20 (TRC20 Token Standard) is a token standard based on the implementation of smart contract when using TRON network to issue a token.

Implementation Rules

3 Optional Items:

  1. Token Name
string public constant name = “TRONEuropeRewardCoin”;
string public constant symbol = “TERC”;
uint8 public constant decimals = 6;

6 Required Items

The code below is a brief TRC20 smart contract:

contract TRC20 {function totalSupply() constant returns (uint theTotalSupply);function balanceOf(address _owner) constant returns (uint balance);function transfer(address _to, uint _value) returns (bool success);function transferFrom(address _from, address _to, uint _value) returns (bool success);function approve(address _spender, uint _value) returns (bool success);function allowance(address _owner, address _spender) constant returns (uint remaining);event Transfer(address indexed _from, address indexed _to, uint _value);event Approval(address indexed _owner, address indexed _spender, uint _value);}
contract MyTRCToken {    uint256 _totalSupply = 1000000;    function totalSupply() constant returns (uint256 theTotalSuppl {        theTotalSupply = _totalSupply;        return theTotalSupply;    }}
contract MyTRCToken {    mapping(address => uint256) balances;    address public owner; // Owner of this contract    function balanceOf(address _owner) constant returns (uint256 balance) {        return balances[_owner];    }}
contract MyTRCToken {    mapping(address => uint256) balances;    function transfer(address _to, uint256 _amount) returns (bool success) {        if (balances[msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) {            balances[msg.sender] -= _amount;            balances[_to] += _amount;            Transfer(msg.sender, _to, _amount); // trigger event            return true;        } else {                   return false;               }    }}
contract MyTRCToken {    mapping(address => mapping (address => uint256)) allowed;    function approve(address _spender, uint256 _amount) returns (bool success) {        allowed[msg.sender][_spender] = _amount;
// msg.sender is the third party's account
Approval(msg.sender, _spender, _amount);
// trigger event
return true; } }
contract MyTRCToken {    mapping(address => uint256) balances;    function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {        if (balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount > 0 && balances[_to] + _amount > balances[_to]) {            balances[_from] -= _amount;            balances[_to] += _amount;            Transfer(_from, _to, _amount);            return true;        } else {                   return false;               }    }}
  1. Contract C wants to transfer 10 TRX to Bob from Alice. Call transferFrom(Alice, Bob, 10) using contract C’s account.
  2. Call allowance(Alice, C) to query the remaining tokens that the contract C can transfer from Alice’s account.

2 Event Functions

event Transfer(address indexed _from, address indexed _to, uint256 _value)
event Approval(address indexed _owner, address indexed _spender, uint256 _value)

References

https://github.com/tronprotocol/tips/blob/master/tip-20.md

For more information

Github: https://github.com/tronprotocol

--

--

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