here i come with a new tutoral. how to create an erc20 cryptocurrency. it took me a while to write it.
How to create your own cryptocurrency simply?
The goal of this article is to show how to create an ERC20-like cryptocurrency in as little time as possible.
Let's start with the basics: what is an ERC20 token? In recent years, the ERC20 token specification has become the de facto standard for Ethereum tokens (or Ethereum-derived blockchains). In other words, most of the Ethereum contracts available today are ERC20 compliant.
This guide details how you can create your own ERC20-like token on the Ethereum blockchain, but before we get started, let's take a closer look at the ERC20 standard.
What makes ERC20 tokens so attractive and successful?
There are several factors at play: ERC20 tokens are simple and easy to deploy, as you will see in this tutorial.
The ERC20 standard solves an important problem, as blockchain-based markets and crypto-wallets need a single, standardized set of commands to communicate with the range of tokens they manage. This includes the rules of interaction between the different tokens, as well as the rules of token exchanges.
It was the first popular specification to propose the standardization of tokens on the Ethereum blockchain. It was by no means the first, but thanks to its popularity, it quickly became the industry standard. Just like other Ethereum tokens, ERC20 tokens are implemented as smart contracts and run on the Ethereum virtual machine (EVM) in a decentralized manner (on the blockchain). Solidity: the programming language of "Smart Contract" or Smart Contracts Ethereum smart contracts are written in Solidity. Although there are alternative languages, almost no one uses them for this purpose. Solidity is similar to JavaScript, so if you have some knowledge of JavaScript, or even Java and other C-type languages, you shouldn't have a hard time understanding what a piece of code in Solidity does, even before you master Solidity enough to use it.
This is where the fun begins, as you should be able to start creating a simple ERC20 contract in no time. This is a simple task, simple enough for this article to explain how to write and deploy an ERC20 token in less than an hour. The token we will create in this demonstration will be a simple ERC20 implementation, without too many bells and whistles. However, I have seen many similar simple tokens in the real world, and they tend to work well.
Presentation of the ERC20 token standard What is an ERC20? Simply put, the ERC20 standard defines a set of functions to be implemented by all ERC20 tokens in order to allow integration with other contracts, wallets or cryptocurrency markets. This set of functions is rather short and basic.
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);
The functions of ERC20 tokens allow an external user, for example a crypto-wallet application, to know a user's balance and transfer funds from one user to another with appropriate authorization. The smart contract defines two specifically defined events:
event Approval(address indexed tokenOwner, address indexed spender,
uint tokens);
event Transfer(address indexed from, address indexed to,
uint tokens);
These events will be invoked or issued when an account is granted the right to withdraw tokens from an account, and after the tokens are actually transferred. In addition to the functions of standard ERC20 tokens, many ERC20 tokens also have additional fields and some have become a de facto part of the ERC20 standard, if not in writing, in practice. Here are some examples of these fields.
string public constant name;
string public constant symbol;
uint8 public constant decimals;
Here are some points about ERC20 and Solidity: A public function is accessible outside the contract itself, view means essentially constant, that is, the internal state of the contract will not be modified by the function. An Event is how Solidity allows customers, e.g. your app, to be notified of specific events in the contract. Most Solidity language constructs should be clear if you already possess the essential Java/JavaScript skills.
Write an ERC20 token in Solidity Now that we've outlined the basics and explained what it takes to create an ERC20 token, it's time to start writing logic. First, we need to define two mapping objects. Here is the notion of Solidity for an associative or key / value array:
mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;
Write an ERC20 token in Solidity Now that we've outlined the basics and explained what it takes to create an ERC20 token, it's time to start writing logic. First, we need to define two mapping objects. Here is the notion of Solidity for an associative or key / value array:
As you can see, the value field of the authorized mapping is in itself a mapping of the tracing account address with its approved withdrawal sum. These mappings as well as all other contract fields will be stored in the blockchain and will be exploited, which will cause the changes to spread to all user nodes in the network. Blockchain storage is expensive and the users of your contract will have to pay, one way or another. Therefore, you should always try to minimize the storage size and writes in the blockchain. Now that we have the required data structures in place, we can start writing the ERC20 logic in the appropriate functions.