A Simple Development Guide to ERC20 Contract Creation

Posted By : Puja

Dec 30, 2020

What is an ERC20 token?

 

An ERC20 token is a technical standard token that is employed in the Ethereum blockchain. With the assistance of this token, we develop a token and a smart contract for a dApp.

 

The language used for creating the contract is called Solidity. It is syntactically far more like c++, and JavaScript. If you have an idea regarding these languages, you'll be able to understand Solidity and
begin making an ERC-20 token-based smart contract. ERC is an acronym for "Ethereum Request for comment." If we are making our ERC20 token then we have to perform the implementation of 6 functions, out of which 3 are optional. We can give any name and symbol to our token.

 

Functions

 

1.function totalSupply() public read returns (uint256):-

 

It simply tells how many tokens you can create. It is read-only. Thus, its uses for viewing the information, we do not change the state. It provides a total quantity of tokens that exist in the network.

 

2.function balanceOf(address tokenOwner) public read returns (uint):-

 

This operation provides the account balance of a token owner's account and gets settled for tokenOwner address as a parameter.

 

3.function allowance(address tokenOwner, address spender):-

 

This operation provides a quantity with the token owner that a spender is allowed to spend. It takes the address of the token owner and the sender's address. The number returned is the quantity set in the approved operation.

 

4.function transfer(address to, uint tokens) public returns (bool):

 

This operation is employed to transfer a fixed quantity of tokens to an address from the token contract. It takes the recipient address and also the number of tokens as operational parameters. The function returns true on the success of the transaction and false on the failure of the transaction.

 

5.function approve(address spender, uint tokens) public returns (bool):-

 

This operate is employed to account address is eligible to pay the tokens specified. The function returns true on the success of the transaction and false on the failure of the transaction.

 

6.function transferFrom(address from, address to, uint tokens) public returns (bool):-

 

This function is used to transfer token between any two senders and receivers. The function returns true on the success of the transaction and false on the failure of the transaction.
Events:-

event Transfer(address indexed from, address indexed to, uint tokens):-
It's just an indication of "is Transfer function completed successfully or not?".
event Approval(address indexed tokenOwner, address indexed spender, uint tokens):- It informs us when approval happened successfully.

 

The field in ERC20 token:-

 

Public constant name:-A name could be anything as you provide, like name="mytoken."
String public constant symbol:- We could also provide a specific symbol to recognize our token.
uint8 public constant decimals = eighteen:-
Decimals denote the number of decimal positions a token worth may be displayed.

 

Needs to perceive some things in Contract:-

 

mapping(address => uint256) balances;

 

Mapping employed in Solidity to store one thing in key tries like HashMap in java you'll release. Here, the address is the account address and uint256 indicates knowledge has to hold on to its sort uint256.
mapping(address => mapping (address => uint256)) allowed:-

 

The second mapping object, allowed, can embrace all of the accounts approved to withdraw from a given account along with the withdrawal total allowed for every.

 

Deployment of an ERC20 token:-

 

You can deploy your ERC20 tokens to the main network, but it's charged with ETH, an additional gas fee. Instead of this, we will use
test network to deploy its operations, similar to the mainnet.

 

If we have a tendency to ar on the most network of Ethereum, we'd need to use actual cash, like EUR or USD.  We can add the MetaMask extension to our browser. It additionally permits us to make multiple accounts and use ether that we tend to get from a faucet for transactions and the preparation of a contract. 
  

Leave a

Comment

Name is required

Invalid Name

Comment is required

Recaptcha is required.

blog-detail

November 22, 2024 at 10:51 pm

Your comment is awaiting moderation.

By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.

Chat with Us
Telegram Button
Youtube Button

Contact Us

Oodles | Blockchain Development Company

Name is required

Please enter a valid Name

Please enter a valid Phone Number

Please remove URL from text