Bitcoin Forum
May 08, 2024, 09:24:43 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: create your own erc20 cryptocurrency - full guide  (Read 65 times)
xiangwei22 (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
May 11, 2022, 01:50:39 AM
 #1

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.

Code:
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:



Code:
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.
 

Code:
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:


Code:
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.
1715203483
Hero Member
*
Offline Offline

Posts: 1715203483

View Profile Personal Message (Offline)

Ignore
1715203483
Reply with quote  #2

1715203483
Report to moderator
1715203483
Hero Member
*
Offline Offline

Posts: 1715203483

View Profile Personal Message (Offline)

Ignore
1715203483
Reply with quote  #2

1715203483
Report to moderator
1715203483
Hero Member
*
Offline Offline

Posts: 1715203483

View Profile Personal Message (Offline)

Ignore
1715203483
Reply with quote  #2

1715203483
Report to moderator
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715203483
Hero Member
*
Offline Offline

Posts: 1715203483

View Profile Personal Message (Offline)

Ignore
1715203483
Reply with quote  #2

1715203483
Report to moderator
xiangwei22 (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
May 11, 2022, 01:58:39 AM
 #2

should i do a tutorial how to create an ico token next time ?
laredo7mm
Hero Member
*****
Offline Offline

Activity: 1498
Merit: 537



View Profile
May 11, 2022, 02:25:37 AM
 #3

should i do a tutorial how to create an ico token next time ?

I do not know how it will be useful for newbies or general users. Because everybody doesn't need to create an erc20 token. It is not something that you eat or need for any purpose if you are not starting a project. But every project hires a developer to create their token and smart contract because it's not that expensive for a project that is aiming for millions of dollars in market cap. Also, it can also be found on google so few will be interested.

xiangwei22 (OP)
Jr. Member
*
Offline Offline

Activity: 34
Merit: 1


View Profile
May 11, 2022, 02:27:49 AM
 #4

should i do a tutorial how to create an ico token next time ?

I do not know how it will be useful for newbies or general users. Because everybody doesn't need to create an erc20 token. It is not something that you eat or need for any purpose if you are not starting a project. But every project hires a developer to create their token and smart contract because it's not that expensive for a project that is aiming for millions of dollars in market cap. Also, it can also be found on google so few will be interested.



my intention is to use my knowledge to help other newbies on the forum
Apocollapse
Hero Member
*****
Offline Offline

Activity: 966
Merit: 752



View Profile
May 11, 2022, 03:54:06 AM
 #5

should i do a tutorial how to create an ico token next time ?
Yes, we really need your guide.

Plagiarism
User: xiangwei22
Post link: https://bitcointalk.org/index.php?topic=5398107.0

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.

Code:
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:



Code:
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.
 

Code:
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:


Code:
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.


Original sources
Quote
https://www.toptal.com/ethereum/create-erc20-token-tutorial
The goal of this article is to demonstrate how to create an ERC20 token 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 defacto standard for Ethereum tokens. In other words, most Ethereum contracts out there today are ERC20-compliant. This article will detail how you can create your own Ethereum token, but before we get started, let’s take a closer look at the ERC20 standard.

ERC20 token illustration

What makes ERC20 tokens so attractive and successful? There are several factors in play:

ERC20 tokens are simple and easy to deploy, as you will see in this tutorial.
The ERC20 standard solves a significant problem, as blockchain-based marketplaces and crypto-wallets need a single, standardized set of commands to communicate with the range of tokens they manage. This includes interaction rules between different tokens, as well as token purchase rules.
It was the first popular specification to offer Ethereum token standardization. It was not by any 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 executed on the Ethereum Virtual Machine (EVM) in a decentralized manner.
Solidity: the Smart Contract Programming Language

Ethereum smart contracts are written in Solidity. While there are alternative languages, hardly anyone uses them for this purpose. Solidity is similar to JavaScript, so if you have some knowledge of JavaScript, or even Java and other C-like languages, you should have no trouble figuring out that a piece of code in Solidity does, even before you actually master Solidity enough to use it.

This is where the fun starts, as you should be able to start creating a simple ERC20 contract in no time. This is a straightforward task, simple enough that this article will demonstrate how you can write and deploy an ERC20 token in under an hour.

The token we will be creating in this demonstration will be a bare-bones ERC20 implementation, without too many bells and whistles. However, I have seen many similarly simple tokens in the real world, and they tend to do quite well.
Overview of ERC20 Token Standard
What is ERC20?

Put simply, the ERC20 standard defines a set of functions to be implemented by all ERC20 tokens so as to allow integration with other contracts, wallets, or marketplaces. 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);

ERC20 functions allow an external user, say a crypto-wallet app, to find out a user’s balance and transfer funds from one user to another with proper 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 emitted when a user is granted rights to withdraw tokens from an account, and after the tokens are actually transferred.

In addition to standard ERC20 functions, many ERC20 tokens also feature additional fields and some have become a de-facto part of the ERC20 standard, if not in writing then in practice. Here are a few examples of such fields.

string public constant name;
string public constant symbol;
uint8 public constant decimals;

Here are a few points regarding ERC20 and Solidity nomenclature:

    A public function can be accessed outside of the contract itself
    view basically means constant, i.e. the contract’s internal state will not be changed by the function
    An event is Solidity’s way of allowing clients e.g. your application frontend to be notified on specific occurrences within the contract

Most Solidity language constructs should be clear if you already possess essential Java/JavaScript skills.
Writing an ERC20 Token in Solidity

ERC20 tokens in solidity

Now that we’ve outlined the basics and explained what it takes to create an ERC20 token, it is time to start writing some logic.

First, we need to define two mapping objects. This is the Solidity notion for an associative or key/value array:

mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;

The expression mapping(address => uint256) defines an associative array whose keys are of type address— a number used to denote account addresses, and whose values are of type uint256 — a 256-bit integer typically used to store token balances.

The first mapping object, balances, will hold the token balance of each owner account.

The second mapping object, allowed, will include all of the accounts approved to withdraw from a given account together with the withdrawal sum allowed for each.

As you can see, the value field of the allowed mapping is by itself a mapping plotting account address to its approved withdrawal sum.

These mappings together with all other contract fields will be stored in the blockchain and will be mined resulting in changes being propagated to all network user nodes.

Blockchain storage is expensive and users of your contract will need to pay for, one way or another. Therefore you should always try to minimize storage size and writes into the blockchain.

Now that we have the required data structures in place, we can start to actually write the ERC20 logic into the appropriate functions.

Dervish doff
Member
**
Offline Offline

Activity: 1134
Merit: 10


View Profile
May 11, 2022, 09:20:38 AM
 #6

your tutorial is very useful, just for knowledge it's okay, who knows one day there will be an opportunity to run a project, there is already knowledge from you, in making erc20 tokens, but it must be reviewed, for certainty and accuracy, keep working mate, review then for how to make tokens for other networks, you are one step ahead of crypto lovers, for tokens based on erc20 very expensive shipping costs, if indeed you have a solution to minimize costs, shares are highly expected.
Victorik
Member
**
Offline Offline

Activity: 966
Merit: 14

Tontogether | Save Smart & Win Big


View Profile
May 11, 2022, 10:14:29 AM
 #7

Thanks for sharing the knowledge for free. But honestly, not everyone would want to create a token. Speaking for myself, I don't have that kind of ambition of owning an ERC 20 token.
But anyways, thanks .

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!