How to Create Your Own Cryptocurrency - An Example Using ERC-20

Beginner9/30/2024, 1:18:07 AM
As blockchain technology and cryptocurrencies evolve rapidly, many people want to learn how to issue their own cryptocurrency. This tutorial aims to provide a straightforward guide for beginners on creating and issuing their own ERC20 token on the Ethereum test network. We’ll begin by explaining what an ERC20 token is, discussing its standards and importance, and then walk readers through each step of the issuance process. Key steps include setting up a Web3 wallet, obtaining test ETH, writing smart contracts, and deploying them. By leveraging the OpenZeppelin library, we will show how to securely and efficiently create tokens that meet the ERC20 standard. This tutorial not only helps readers grasp the technical aspects of cryptocurrencies but also offers practical experience, laying the groundwork for deeper exploration of the blockchain world. Whether you're a beginner curious about blockchain technology or a developer looking to understand the cryptocurrency issuance process, this tutorial will provide ess

The blockchain sector is gaining significant attention with ongoing developments in blockchain, Bitcoin, Ethereum, cryptocurrencies, and ICOs. This prompted me to write this tutorial, the first in a series designed to help individuals understand how to use blockchain technology and cryptocurrencies to create impactful applications.

In this tutorial, I aim to guide you through the entire process, from setting up your account to issuing your first token on the Ethereum test network using a single smart contract and Metamask. This token will function as a standard ERC20 token on the Ethereum test network, equipped with core features that can serve as a versatile foundation for more complex applications beyond simple transfers.

Before You Start

Before you create your own ERC20 token, you need to prepare the following:

  1. A Web3 wallet (such as MetaMask, Phantom, or any wallet compatible with WalletConnect)
  2. Test ETH (you can get test tokens from Ethereum Sepolia Faucet ) — note that this step requires gas fees
  3. A web browser (Chrome is recommended)

What is ERC20 Token?

ERC stands for Ethereum Request for Comment, with 20 being the proposal identification number. The purpose of ERC-20 is to enhance the Ethereum network. It is one of the most significant ERC standards and has become the technical framework for creating tokens on the Ethereum blockchain through smart contracts. ERC-20 outlines a set of rules that all Ethereum-based tokens must adhere to, defining them as blockchain-based assets that can be sent and received, have value, operate on the Ethereum blockchain, and incur gas fees for transactions.

In 2015, German developer Fabian Vogelsteller contributed to Ethereum’s history by commenting on the project’s GitHub page. This marked his 20th comment, during which he first mentioned ERC-20. As Ethereum rapidly expanded, ERC-20 was introduced as a solution to the network’s scalability challenges.

The formal recognition and adoption of ERC-20 as an Ethereum Improvement Proposal (EIP-20), co-authored by Vogelsteller and Ethereum co-founder Vitalik Buterin, occurred at the end of 2017.

Prior to the ERC-20 standard, token creators had to start from scratch, leading to inconsistencies among different tokens. Developers needed to fully understand the smart contract code of other tokens due to the absence of a standardized structure, complicating matters for wallets and exchanges that had to review each token’s code for support. Adding new tokens to applications became a complex task.

With the introduction of the ERC-20 standard, its standardized features, interoperability, and transferability have enabled wallets and exchanges to integrate multiple tokens and facilitate exchanges between them easily. The smart contracts employed in ERC-20 tokens can automatically execute and enforce complex financial transactions, which is essential for DeFi platforms. On these platforms, tokens can represent various financial instruments, such as loans or shares in liquidity pools.

The ERC-20 standard specifies six mandatory and three optional functions that smart contracts must implement.

Here are the required functions and their descriptions:

  • totalSupply: A method that defines the total supply of tokens; if this limit is reached, the smart contract will not create new tokens.
  • balanceOf: A method that returns the number of tokens a specific wallet address holds.
  • transfer: A method that deducts a specified amount of tokens from the total supply and allocates them to the user.
  • transferFrom: An alternative method for transferring tokens between users.
  • approve: A method to check if the smart contract permits a certain number of tokens to be allocated to a user, considering the total supply.
  • allowance: Similar to the approve method, but checks if one user has enough balance to send a specific amount of tokens to another user.

Beyond the essential functions mentioned earlier, there are additional optional functions that can improve the token’s usability:

  • name: A method that returns the token’s name.
  • symbol: A method that returns the token’s symbol.
  • decimals: A method that indicates the number of decimal places for the token. This defines the smallest unit of the token. For instance, if an ERC-20 token has a decimals value of 6, it means the token can be divided up to six decimal places.

If you are familiar with object-oriented programming, you can think of ERC-20 as an interface. To make your token an ERC-20 token, you must implement the ERC-20 interface, which requires you to include these six essential functions. Essentially, the ERC-20 interface serves as a template, and any contract that aims to be classified as an ERC-20 token must design and implement its functions using this template.

Start Creating Your Own ERC20 Token

Obtain Test ETH

To start deploying your contract on the Ethereum Sepolia test network, you need to install the MetaMask browser extension or use another Web3 wallet, like Phantom, or any wallet compatible with WalletConnect. After setting up your wallet, you’ll need to get some test ETH. You can obtain this from the Ethereum Sepolia Faucet, which is specifically designed for the Ethereum Sepolia test network. Getting test ETH is straightforward: simply visit the faucet website, connect your wallet address or enter your address, and follow the instructions. You can also share a tweet for extra rewards, or you can select the option “No thanks, just send me 0.05 ETH” to receive your test ETH directly. However, keep in mind that you need to have at least 0.001 ETH in your Ethereum mainnet account to use the QuickNode test coin faucet.

Writing the Smart Contract

There are many tokens that comply with the ERC20 standard currently running on the Ethereum blockchain, developed by various groups. These implementations differ; some focus on minimizing gas costs, while others prioritize enhancing security. To create a strong and secure token, many developers opt for OpenZeppelin’s ERC20 token standard. OpenZeppelin is a thoroughly tested and community-reviewed library of reusable smart contracts that includes a reliable and secure ERC20 token framework. It ensures that token development is compliant and secure, making it the go-to choice for many token developers today.

For ease and security, we will use the OpenZeppelin ERC-20 contract to create our token in this guide. With OpenZeppelin, we don’t need to write the entire ERC-20 interface; we simply import the library contract and utilize its functions. In this instance, we will issue 1 million ERC-20 tokens named MNT.

Next, head over to the Ethereum Remix IDE (the integrated development environment for Ethereum that supports the Solidity programming language) and create a new Solidity file, such as - MyNewToken.sol.

  1. Create a New File in Ethereum Remix IDE

Please paste the following code into your new Solidity script:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

contract MyNewToken is ERC20 { constructor() ERC20(“MyNewToken”, “MNT”) { _mint(msg.sender, 1000000 (10 * uint256(decimals()))); } }

  1. Copy and paste the above code for the token issuance smart contract.

Here’s what the code does:

The SPDX-License-Identifier comment indicates the license under which the contract is released.

Pragma directive specifies the version of the compiler that will be used.

The ERC20 contract is imported from OpenZeppelin and serves as the foundation for your token.

MyNewToken is the name of your contract, which inherits from the ERC20 contract.

constructor function initializes your token with the name (“MyNewToken”) and symbol (“MNT”).

The _mint function within the constructor creates the initial supply of tokens. In this case, 1 million tokens are minted and assigned to the address that deploys the contract. The total number of tokens is adjusted according to the decimals value, which defaults to 18 in the OpenZeppelin implementation.

Because we imported the ERC20 smart contract from OpenZeppelin and the MyNewToken contract inherits from it, there is no need to define all the functions ourselves. All functions defined in the ERC20 contract are included in the MyNewToken contract. If you’d like to see a more detailed version of the complete ERC-20 code, you can refer to this file.

Now, take some time to customize the smart contract to fit your needs. You can also change the token name and symbol by modifying this section: ERC20(“MyNewToken”, “MNT”).

Deploy the Smart Contract

Once you have customized your smart contract, the next step is to compile it.

Step 1: Click on the Solidity Compiler button. Check the compiler version and ensure the correct contract is selected. Since your smart contract includes the line pragma solidity ^0.8.20; the compiler version should be at least 0.8.20. Next, click the Compile MyNewToken.sol button. If everything is successful, you will see a green checkmark on the compile button.

  1. Compile the Smart Contract

  1. Compilation Successful (Green Checkmark)

Step 2: Navigate to the Deploy & Run Transactions tab. Under the Environment section, choose the Injected Provider option for deployment. Before proceeding, ensure that your MetaMask is set to the Sepolia test network and that you have selected the MyNewToken contract for deployment. Finally, click the Deploy button to deploy your contract.

  1. Choose Injected Provider as Your Local Web3 (MetaMask) Wallet

  1. Connect Your Web3 Wallet

  1. Confirm Contract Deployment and Choose the Network (This is a Test Network)

If you’re not sure how to switch networks, open the MetaMask extension, click on the network selector in the upper left corner, and choose Sepolia. If it’s not visible, ensure that the “Show Test Networks” option is enabled. For instructions on adding the QuickNode RPC URL to MetaMask, please check the QuickNode Guide.

Note: You will need to cover GAS fees to exchange for test ETH.

Step 3: Confirm the transaction in MetaMask:

Congratulations! Your token contract has now been successfully deployed on the Ethereum Sepolia test network, and you officially own your first token!

Author: Deniz
Translator: Paine
Reviewer(s): KOWEI、Edward、Elisa
Translation Reviewer(s): Ashely
* The information is not intended to be and does not constitute financial advice or any other recommendation of any sort offered or endorsed by Gate.io.
* This article may not be reproduced, transmitted or copied without referencing Gate.io. Contravention is an infringement of Copyright Act and may be subject to legal action.

How to Create Your Own Cryptocurrency - An Example Using ERC-20

Beginner9/30/2024, 1:18:07 AM
As blockchain technology and cryptocurrencies evolve rapidly, many people want to learn how to issue their own cryptocurrency. This tutorial aims to provide a straightforward guide for beginners on creating and issuing their own ERC20 token on the Ethereum test network. We’ll begin by explaining what an ERC20 token is, discussing its standards and importance, and then walk readers through each step of the issuance process. Key steps include setting up a Web3 wallet, obtaining test ETH, writing smart contracts, and deploying them. By leveraging the OpenZeppelin library, we will show how to securely and efficiently create tokens that meet the ERC20 standard. This tutorial not only helps readers grasp the technical aspects of cryptocurrencies but also offers practical experience, laying the groundwork for deeper exploration of the blockchain world. Whether you're a beginner curious about blockchain technology or a developer looking to understand the cryptocurrency issuance process, this tutorial will provide ess

The blockchain sector is gaining significant attention with ongoing developments in blockchain, Bitcoin, Ethereum, cryptocurrencies, and ICOs. This prompted me to write this tutorial, the first in a series designed to help individuals understand how to use blockchain technology and cryptocurrencies to create impactful applications.

In this tutorial, I aim to guide you through the entire process, from setting up your account to issuing your first token on the Ethereum test network using a single smart contract and Metamask. This token will function as a standard ERC20 token on the Ethereum test network, equipped with core features that can serve as a versatile foundation for more complex applications beyond simple transfers.

Before You Start

Before you create your own ERC20 token, you need to prepare the following:

  1. A Web3 wallet (such as MetaMask, Phantom, or any wallet compatible with WalletConnect)
  2. Test ETH (you can get test tokens from Ethereum Sepolia Faucet ) — note that this step requires gas fees
  3. A web browser (Chrome is recommended)

What is ERC20 Token?

ERC stands for Ethereum Request for Comment, with 20 being the proposal identification number. The purpose of ERC-20 is to enhance the Ethereum network. It is one of the most significant ERC standards and has become the technical framework for creating tokens on the Ethereum blockchain through smart contracts. ERC-20 outlines a set of rules that all Ethereum-based tokens must adhere to, defining them as blockchain-based assets that can be sent and received, have value, operate on the Ethereum blockchain, and incur gas fees for transactions.

In 2015, German developer Fabian Vogelsteller contributed to Ethereum’s history by commenting on the project’s GitHub page. This marked his 20th comment, during which he first mentioned ERC-20. As Ethereum rapidly expanded, ERC-20 was introduced as a solution to the network’s scalability challenges.

The formal recognition and adoption of ERC-20 as an Ethereum Improvement Proposal (EIP-20), co-authored by Vogelsteller and Ethereum co-founder Vitalik Buterin, occurred at the end of 2017.

Prior to the ERC-20 standard, token creators had to start from scratch, leading to inconsistencies among different tokens. Developers needed to fully understand the smart contract code of other tokens due to the absence of a standardized structure, complicating matters for wallets and exchanges that had to review each token’s code for support. Adding new tokens to applications became a complex task.

With the introduction of the ERC-20 standard, its standardized features, interoperability, and transferability have enabled wallets and exchanges to integrate multiple tokens and facilitate exchanges between them easily. The smart contracts employed in ERC-20 tokens can automatically execute and enforce complex financial transactions, which is essential for DeFi platforms. On these platforms, tokens can represent various financial instruments, such as loans or shares in liquidity pools.

The ERC-20 standard specifies six mandatory and three optional functions that smart contracts must implement.

Here are the required functions and their descriptions:

  • totalSupply: A method that defines the total supply of tokens; if this limit is reached, the smart contract will not create new tokens.
  • balanceOf: A method that returns the number of tokens a specific wallet address holds.
  • transfer: A method that deducts a specified amount of tokens from the total supply and allocates them to the user.
  • transferFrom: An alternative method for transferring tokens between users.
  • approve: A method to check if the smart contract permits a certain number of tokens to be allocated to a user, considering the total supply.
  • allowance: Similar to the approve method, but checks if one user has enough balance to send a specific amount of tokens to another user.

Beyond the essential functions mentioned earlier, there are additional optional functions that can improve the token’s usability:

  • name: A method that returns the token’s name.
  • symbol: A method that returns the token’s symbol.
  • decimals: A method that indicates the number of decimal places for the token. This defines the smallest unit of the token. For instance, if an ERC-20 token has a decimals value of 6, it means the token can be divided up to six decimal places.

If you are familiar with object-oriented programming, you can think of ERC-20 as an interface. To make your token an ERC-20 token, you must implement the ERC-20 interface, which requires you to include these six essential functions. Essentially, the ERC-20 interface serves as a template, and any contract that aims to be classified as an ERC-20 token must design and implement its functions using this template.

Start Creating Your Own ERC20 Token

Obtain Test ETH

To start deploying your contract on the Ethereum Sepolia test network, you need to install the MetaMask browser extension or use another Web3 wallet, like Phantom, or any wallet compatible with WalletConnect. After setting up your wallet, you’ll need to get some test ETH. You can obtain this from the Ethereum Sepolia Faucet, which is specifically designed for the Ethereum Sepolia test network. Getting test ETH is straightforward: simply visit the faucet website, connect your wallet address or enter your address, and follow the instructions. You can also share a tweet for extra rewards, or you can select the option “No thanks, just send me 0.05 ETH” to receive your test ETH directly. However, keep in mind that you need to have at least 0.001 ETH in your Ethereum mainnet account to use the QuickNode test coin faucet.

Writing the Smart Contract

There are many tokens that comply with the ERC20 standard currently running on the Ethereum blockchain, developed by various groups. These implementations differ; some focus on minimizing gas costs, while others prioritize enhancing security. To create a strong and secure token, many developers opt for OpenZeppelin’s ERC20 token standard. OpenZeppelin is a thoroughly tested and community-reviewed library of reusable smart contracts that includes a reliable and secure ERC20 token framework. It ensures that token development is compliant and secure, making it the go-to choice for many token developers today.

For ease and security, we will use the OpenZeppelin ERC-20 contract to create our token in this guide. With OpenZeppelin, we don’t need to write the entire ERC-20 interface; we simply import the library contract and utilize its functions. In this instance, we will issue 1 million ERC-20 tokens named MNT.

Next, head over to the Ethereum Remix IDE (the integrated development environment for Ethereum that supports the Solidity programming language) and create a new Solidity file, such as - MyNewToken.sol.

  1. Create a New File in Ethereum Remix IDE

Please paste the following code into your new Solidity script:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

contract MyNewToken is ERC20 { constructor() ERC20(“MyNewToken”, “MNT”) { _mint(msg.sender, 1000000 (10 * uint256(decimals()))); } }

  1. Copy and paste the above code for the token issuance smart contract.

Here’s what the code does:

The SPDX-License-Identifier comment indicates the license under which the contract is released.

Pragma directive specifies the version of the compiler that will be used.

The ERC20 contract is imported from OpenZeppelin and serves as the foundation for your token.

MyNewToken is the name of your contract, which inherits from the ERC20 contract.

constructor function initializes your token with the name (“MyNewToken”) and symbol (“MNT”).

The _mint function within the constructor creates the initial supply of tokens. In this case, 1 million tokens are minted and assigned to the address that deploys the contract. The total number of tokens is adjusted according to the decimals value, which defaults to 18 in the OpenZeppelin implementation.

Because we imported the ERC20 smart contract from OpenZeppelin and the MyNewToken contract inherits from it, there is no need to define all the functions ourselves. All functions defined in the ERC20 contract are included in the MyNewToken contract. If you’d like to see a more detailed version of the complete ERC-20 code, you can refer to this file.

Now, take some time to customize the smart contract to fit your needs. You can also change the token name and symbol by modifying this section: ERC20(“MyNewToken”, “MNT”).

Deploy the Smart Contract

Once you have customized your smart contract, the next step is to compile it.

Step 1: Click on the Solidity Compiler button. Check the compiler version and ensure the correct contract is selected. Since your smart contract includes the line pragma solidity ^0.8.20; the compiler version should be at least 0.8.20. Next, click the Compile MyNewToken.sol button. If everything is successful, you will see a green checkmark on the compile button.

  1. Compile the Smart Contract

  1. Compilation Successful (Green Checkmark)

Step 2: Navigate to the Deploy & Run Transactions tab. Under the Environment section, choose the Injected Provider option for deployment. Before proceeding, ensure that your MetaMask is set to the Sepolia test network and that you have selected the MyNewToken contract for deployment. Finally, click the Deploy button to deploy your contract.

  1. Choose Injected Provider as Your Local Web3 (MetaMask) Wallet

  1. Connect Your Web3 Wallet

  1. Confirm Contract Deployment and Choose the Network (This is a Test Network)

If you’re not sure how to switch networks, open the MetaMask extension, click on the network selector in the upper left corner, and choose Sepolia. If it’s not visible, ensure that the “Show Test Networks” option is enabled. For instructions on adding the QuickNode RPC URL to MetaMask, please check the QuickNode Guide.

Note: You will need to cover GAS fees to exchange for test ETH.

Step 3: Confirm the transaction in MetaMask:

Congratulations! Your token contract has now been successfully deployed on the Ethereum Sepolia test network, and you officially own your first token!

Author: Deniz
Translator: Paine
Reviewer(s): KOWEI、Edward、Elisa
Translation Reviewer(s): Ashely
* The information is not intended to be and does not constitute financial advice or any other recommendation of any sort offered or endorsed by Gate.io.
* This article may not be reproduced, transmitted or copied without referencing Gate.io. Contravention is an infringement of Copyright Act and may be subject to legal action.
Start Now
Sign up and get a
$100
Voucher!