PlagiarismUser:
xiangwei22Post link:
https://bitcointalksearch.org/topic/create-your-own-erc20-cryptocurrency-full-guide-5398107here 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.
Original sources When Satoshi Nakamoto, the alleged inventor of Bitcoin, defined the specifications of this bank-independent currency, he had to imagine a system of transaction validations. This work was originally devolved to private individuals, willing to use the computing power of their computer to operate a strict control of each monetary movement. When Bob sends a 1 BTC (Bitcoin) to Alice, several checks must be made:
1. Make sure Bob is Bob and not a usurper of Bob's account.
2. Make sure that Alice is Alice.
3. Verify that Bob's account has the BTC he wants to send to Alice.
4. Verify that this BTC can only be transmitted once.
5. Perform a control calculation of this transaction specific to a precise cryptological formula.
6. Check at the end of the day that this BTC is present on Alice's wallet and that it has been subtracted from Bob's wallet.
7. Enter this new transaction in the ledger that is the Bitcoin blockchain so that such a trace is kept forever.
To carry out these various checks, the one who carries out the mining must perform clever calculations involving the private key (identifier) of Bob as Alice, and also public keys specific to this transaction, a series of numbers calculated from their private keys.
As we see in point 5, the Bitcoin algorithm has been designed in such a way that each transaction can be verified according to a calculation related to cryptology. To do this, Nakamoto exploited a mathematical formula called SHA-256. Applied to any number or text, this formula returns a sequence of 256 digits called a "hash".
Mining consists, by testing a huge number of combinations, which figure could have generated the "hash" of a given transaction. The first miner who finds the solution provides a "Proof of Work" that certifies that he has found the solution to the problem. He reaps a commission – a minimal percentage of the transaction he has validated and also, regularly, new Bitcoins. This is where the analogy with traditional currency mining comes from, since this work regularly results in the creation of new BTC.
Cryptocurrencies that appeared in the wake of Bitcoin (Litecoin, Ethereum, Cardano...) exploit this same principle of mining. Bitcoin mining began to show its Achilles heel from 2017, when demand for this currency suddenly took off. At the height of the wave, the processing of some transactions was counted in hours and sometimes in days. Various solutions have been devised to remedy this.
However, Bitcoin mining was designed from the beginning to be more and more complex over the years. The reason is that only 21 million units of this currency can ever be mined. However, by 2024, more than 20 million BTC will have already been and it will take the equivalent of a century to produce the last million. As a result, while in 2009, 50 new BTC were created every 10 minutes; in 2021, that figure dropped to 6.25 every 10 minutes. At the same time, the size of its blockchain had increased - it exceeded 350 GB at the beginning of October 2021.
Mining has therefore become more and more complex and the task is now carried out by gigantic server farms located in countries such as Mongolia, Iceland or Russia. The result is what some call an ecological disaster. New currencies such as Tezos, Pearcoin, or Mina rely on a simpler mechanism, called "proof of stake" (involving a reduced number of miners trusted by the community at a given time) and blockchains much smaller than that of Bitcoin.
i hope my guide is good.
Original sourcesWhen Satoshi Nakamoto, the alleged inventor of Bitcoin, defined the specifications of this currency independent of banks, he had to imagine a system for validating transactions. This work was originally devolved to private individuals, willing to use the computing power of their computer to operate a strict control of each movement monetary.
When Bob sends a 1 BTC (Bitcoin) to Alice, several checks must be made:
Make sure that Bob is Bob and not an impersonator of the latter’s account.
Likewise make sure that Alice is Alice.
Check that Bob’s account has the BTC he wants to send to Alice.
Check that this BTC can only be transmitted once.
Perform a control calculation of this transaction specific to a precise cryptological formula.
Ultimately check that this BTC is present on the wallet (wallet) of Alice and that it was subtracted from Bob’s wallet.
Enter this new transaction in the register that is blockchain Bitcoin so that such a trace is kept ad vitam aeternam.
To carry out these various verifications, the one who carries out the mining must perform clever calculations involving the private key (identifier) of Bob as of Alice, and also of public keys specific to this transaction, ie a series of digits calculated from their private keys.
As we see in point 5, the Bitcoin algorithm has been designed so that each transaction can be verified according to a calculation linked to the cryptology. To do this, Nakamoto exploited a mathematical formula called SHA-256. Applied to any number or to any text, this formula returns a series of 256 digits called a “hash”.
Mining consists, by testing an enormous number of combinations, which number could generate the “hash” of a given transaction. The first miner who finds the solution provides a “proof of work” (Proof of Work) which certifies that it has found the solution to the problem. He collects a commission – a minimal percentage of the transaction that he validated and also, regularly new Bitcoins. This is where theanalogy with traditional currency mining, since this work regularly results in the creation of new BTCs.
Cryptocurrencies that emerged in the wake of Bitcoin (Litecoin, Ethereum, Cardano…) exploit the same principle of mining.
The mining of Bitcoin started showing its Achilles heel from 2017, when demand for this currency suddenly took off. At the height of the wave, the processing of certain transactions was counted in hours and sometimes in days. Various solutions have been devised to remedy this.
Yet Bitcoin mining was designed from the start to become more and more complex over the years. The reason is that only 21 million units of this currency can ever be mined. However, by 2024, more than 20 million BTC will have already been and it will take the equivalent of a century to produce the last million. As a result, while in 2009, 50 new BTCs were created every 10 minutes; in 2021, that number fell to 6.25 every 10 minutes. At the same time, the size of its blockchain swelled – it exceeded 350 GB in early October 2021.
Mining has therefore become more and more complex and the task is now carried out by gigantic server farms located in regions such as Mongolia, Iceland or Russia. This results in what some refer to as a ecological disaster. Cambridge University in a study published in 2021 estimated that the power consumption annual Bitcoin exceeded that of countries such as Colombia or Bangladesh and was not far removed from that of countries like Chile or Belgium.
https://yrtnews.com/how-does-cryptocurrency-mining-work/