Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create ERC 20 Token On Ethereum With Solidity

With this article, you will learn how you can create your own Cryptocurrency or ERC20 Token on Ethereum with the help of Smart Contracts. ERC 20 token standard is a draft specification created in 2015 for implementing Tokens which defines a set of instructions that an Ethereum token can implement. A token comprises of following basic components:

  • Total supply – returns the total amount of tokens in circulation.
Syntax: function totalSupply() constant returns (uint256 totalSupply)
  • BalanceOf – It gives the balance that the address holds.
Syntax: function balanceOf(address _owner) constant returns (uint256 balance)
  • Transfer – It transfers the value to another address from your own address.
Syntax: function transferFrom(address _from, address _to, uint256 _value) returns (bool success)
  • Approve – it gives permission to another address to spend tokens on your behalf.
Syntax: function approve(address _spender, uint256 _value) returns (bool success)
  • Allowance – it tells how many tokens you have given permission to spend
Syntax: function allowance(address _owner, address _spender) constant returns (uint256 remaining)

Events:

Approval: event Approval(address indexed _owner, address indexed _spender, uint256 _value)

Transfer: event Transfer(address indexed _from, address indexed _to, uint256 _value)

Before starting the program just install a Chrome extension called Metamask.

Creating the Token on Solidity:

We will do all our programming in an IDE called Remix IDE. So copy all the methods in the proposal like the program below created in an interface called IERC20:

  • Create a Smart Contract that imports IERC20 files and implements that interface.
  • We will return a total number of Func Tokens in circulation.
  • Send the initial Balance to ourselves.
  • mapping(address) is used to store the balance.
  • We will return the balance of the address and transfer the balance.

The following program illustrates the Creation of ERC 20 Token:

pragma solidity ^0.4.21;
 
import "./IERC20.sol";

contract FuncToken is IERC20 {
uint public constant_total supply = 100000;
string public constant symbol = “FUNC”;
string public constant name = “Func Token”;   
     mapping (address => uint256) balances;
     mapping (address => mapping (address => uint256)) allowed;
     uint8 public decimals;                //How many decimals to show. 
 
     function FuncToken(){
         uint256 _initialAmount,
         string _tokenName,
         uint8 _decimalUnits,
         string _tokenSymbol
     public {
         balances[msg.sender] = _totalSupply;       // Give the creator all initial tokens
              }
 
     function transfer(address _to, uint256 _value) public returns (bool success) {
         require(balances[msg.sender] >= _value);
         balances[msg.sender] -= _value;
         balances[_to] += _value;
         emit Transfer(msg.sender, _to, _value);
         return true;
     }
 
     function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
         uint256 allowance = allowed[_from][msg.sender];
         require(balances[_from] >= _value && allowance >= _value);
         balances[_to] += _value;
         balances[_from] -= _value;
         if (allowance 

Deploying the Program:

In order to run the program, we have to follow certain procedures which are as follows. So when you are deploying the program in a test network, it will cost you some ethers to deploy it. The window will show like this:

  • Click on Accept.
  • The contract has been deployed on the network as shown below and copy the address in the address bar.

After this open the link in a new window:https://wallet.ethereum.org/contracts

  • When the link will open click on Watch token tab.
  • A window something like this will appear:

  • In the first box paste the contract address which on you have created the token. it will automatically fill all the details in the other sections of the box. As it knows the name,
  • Function, and the decimal places.
  • Next, we go to the wallet and there we will see that we have 1 million Func tokens in our wallet as we created in the program.
  • We can see this in the image shown below.

We will have to add these tokens to the Metamask wallet also. To do this just paste the Address in the Metamask and rest it will be automatically added in the Metamask wallet.

As the program has been written, we can also send these tokens to another address.
For performing this action we need to create another address same as the one listed above.

In the above image, we are sending 10 func tokens to another wallet address.

We can see that we received 10 func tokens in another address.
So we can see how easy is to create the tokens or currency and send it to another address

How to install Metamask browser extension on Chrome:

In this section, we will see how we can install Metamask and create a wallet. By this, you have to create 2 wallets so that you can learn how to transfer funds from one token to other. If you do not install this, it may result in permanent loss of tokens.

  • Click here and install metamask and Add to Chrome Extension: https://metamask.io

Creating a wallet in Metamask:

When you have installed Metamask Chrome extension click on the logo of Metamask.

  • Click on create a new wallet.
  • Enter the Password
  • It will show you 12 words which you have to write it down somewhere safe. In case you lost the wallet then this key will help you in recovering the wallet.
  • Your account is now created.

You have to create another wallet in order to practice the program of transferring the funds through the same procedure.

Conclusion:

In the above article, we studied how we can easily create an ERC20 token and transfer funds through the same. How well did you understand the article please tell us in the comments section below and do tell us how many wallets did you create through this procedure?

The post Create ERC 20 Token On Ethereum With Solidity appeared first on Eduonix Blog.



This post first appeared on Eduonix Blog Section, please read the originial post: here

Share the post

Create ERC 20 Token On Ethereum With Solidity

×

Subscribe to Eduonix Blog Section

Get updates delivered right to your inbox!

Thank you for your subscription

×