We are all aware of crypto tokens are created on Ethereum Blockchain. Out of these evolving tokens, we can observe many tokens are ERC20 tokens, which are also known as fungible tokens. Through this blog post we’ll help you understand what are ERC20 tokens, how to create them and ways to deploy it in a test network.

What is ERC20?

In ERC20, ERC stands for Ethereum Request for Comments. It is an official protocol for proposing improvements to Ethereum (ERC) and it is followed by ID (20) of proposal which is always unique. ERC20 defines a set of rules which every token needs to meet to interact with each other in an Ethereum network. Tokens which are defined by using ERC20 rules are called ERC20 tokens. These tokens act as digital assets that can have values and can be sent and received in the network.

How to Create Your Own ERC20 Tokens

Here, we are concentrating on creating ERC20 Token Test Network (Rinkeby Network)

Before we start, let’s first ensure the following:

  • Create an account in test network (Rinkeby)
  • Test Ethereum in test network (Rinkeby)
  • A text editor
  • ERC20 solidity contract
  • Metamask plugin
Account in Rinkeby Test Network
  • For installing Metamask plugin follow this link Metamask Plugin
  • Once you are done with installation, create an account in Metamask
  • Change the network type in Metamask to Rinkeby

To get test Ethereum in Rinkeby network follow this link Test Ethereum in Rinkeby

You can download ERC20 token from this link ERC20 Contract

Customize ERC20 Token Contract

Once you are done with components that open the downloaded smart contract from above link. Perform the following:

  • Go to line number 14 and change the name of token to your custom name.
  • Change the symbol of the token at line number 13.
  • You can set token supply i.e. How many number of tokens are to be supplied (line number 16).
  • Decimals at line number 15.
[java]contract EvokeToken is ERC20Interface, Owned, SafeMath {
string public symbol;
string public  name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() public {
symbol = "EToken";
name = "Evoke Token";
decimals = 18;
_totalSupply = 100000000000000000000000000;
balances[0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222] = _totalSupply;
emit Transfer(address(0), 0x5A86f0cafD4ef3ba4f0344C138afcC84bd1ED222, _totalSupply);
}
//
------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply  - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from the from account to the to account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the from account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account. The spender contract function
// receiveApproval(...) is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
}[/java]

After modifying the contract with your custom changes, copy the contract code and go to Remix IDE.

Deploying ERC20 Contract using Remix IDE

  • Select the type of environment to be injected WEB3 in Remix IDE. It is at the top right corner. It will automatically link to your Metamask plugin account.
  • Make sure that you choose Rinkeby test network in your Metamask plugin.
Deploying ERC20
  • Check if the changes you made are reflecting or not. Now click on ‘Deploy Contract’.
Deploy Contract
  • Once you click on ‘Deploy Contract’, a popup will appear from the Metamask plugin asking for your permission to spend some Ethereum to deploy contract. Press ‘Submit’ to deploy the contract.
Submit Deploy Contract
  • You can track the deployed contract in your Metamask account contracts tab.
Metamask Account
  • By clicking on ‘Contract’ in you contracts tab in the Metamask plugin, you will be redirected to the Ether Scan Website for test network. There you would see the contract deployment information.
Contract Metamask Plugin
  • Click on contract address to view the contract information.
Contract Info
  • Go to contract code tab and click ‘Verify and Publish’.
Contract Code Tab
  • Once you click on ‘Verify and Publish’ option, you will get the following screen.
Contract Source Code
  • Enter the Solidity code. Make sure the contract address is same as deployed address.
Solidity Code
  • Now click on ‘Verify and Publish’. Your ERC20 token will be published in the Rinkeby Test Network.
ERC721

Ethereum Request for Comments 721 or ERC721 is a proposal introduced by Dieter Shirley. It is a standard proposal that allows smart contracts to create tradable tokens which are similar to ERC20 token. The major difference is, every ERC721 token is unique and non-fungible.

Fungibility means a characteristic of an asset having similar type that we can observe in real world as Currency. For Example, a 100 dollar currency note can be used to make purchase of one or more items of similar or lesser value. Similarly, ERC721 tokens can also be used in exchange, but their value is a result of the uniqueness associated with each token.

ERC721 Functions

Name

Function to define the name of a token.

Symbol

Provides compatibility with ERC20 token standard and defines symbol of the token.

Total Supply

Defines total number of token supply i.e., number of coins available in blockchain.

balanceOf

Used to find number of token that a given address owns.

ownerOf

It is an ownership function defining the owner of the token.

Approve

It approves the permission to transfer a token on owner’s behalf.

takeOwnership

It acts similar to a withdraw function. An outside party can call it to take tokens out of another user’s account.

transfer

It lets the owner of a token send it to another user which is similar to standalone cryptocurrency.

Evoke’s Blockchain Solutions

Evoke Technologies is a leading IT services company offering leading-edge Blockchain Solutions. Our blockchain solutions include consulting & advisory services, ICO development, solution design & implementation. We extend technical expertise and leadership to implement real-life blockchain use cases in various industries such as finance, telecom, healthcare, etc. Our team of techno-functional experts specialized in blockchain consulting empower your business by developing, testing, and deploying secured blockchain solutions that create new revenue streams, and eliminate the risk of fraud.

Evoke's Blockchain Services Contact Us

To learn more about our Blockchain solutions, get in touch now!

Author

Hari Giduturi is an experienced Blockchain Developer in Evoke Technologies and has worked on multiple technologies such as Node.js, PHP, AngularJS. In his free time, he is seen around with his camera, capturing life at its best.
Please follow and share

1 Comment

  1. Farhan

    March 5, 2019

    Excellent!

Leave a comment