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 create your own ERC20 token, you need to prepare the following:
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:
Beyond the essential functions mentioned earlier, there are additional optional functions that can improve the token’s usability:
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.
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.
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.
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()))); } }
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”).
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.
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.
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.
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!
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 create your own ERC20 token, you need to prepare the following:
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:
Beyond the essential functions mentioned earlier, there are additional optional functions that can improve the token’s usability:
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.
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.
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.
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()))); } }
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”).
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.
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.
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.
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!