What is ERC-20?
ERC stands for Ethereum Request for Comment. Essentially, they are standards that have been approved by the community and are used to convey technical requirements and specifications for certain use cases.
ERC-20 specifically is a standard which outlines the technical specification of a fungible token.
Most tokens on Ethereum comply with the ERC-20 specification. Following a standard like ERC-20 allows application developers which use ERC-20 tokens to easily support all ERC-20 tokens without having to write specialized code for them individually.
For example, decentralized exchanges like Uniswap allow you to swap any token for any other token. This is only possible because pretty much all tokens follow the ERC-20 standard, so Uniswap could write code which works with all tokens following the standard.
Prerequisites
Make sure you have downloaded and installed MetaMask
Select the Sepolia Testnet network to work with
Request some Sepolia Testnet ETH from a faucet to work with - Ethereum Sepolia Faucet | Free 0.1 sETH per day | LearnWeb3
Once you have set all of these up, let's get started!
Writing the code
We are using Remix IDE for writing the smart contract.
In Remix, create a new contract file, I named mine LW3Token.sol - you can name it whatever you want!
In the contract, write the following code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "https://github.com/OpenZeppelin/openzeppelin-
contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract LW3Token is ERC20 {
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {
_mint(msg.sender, 10 * 10 ** 18);
}
}
Compiling
Compile your contract by either pressing Save (CTRL + S on Windows, Command + S on Mac), or by going over to the Compiler tab in Remix, selecting LW3Token.sol, and hitting Compile.
Deploying
Head over to the Deploy and Run Transactions tab in Remix.
Select the Injected Provider - MetaMask environment (ensure you are on the Sepolia Test Network), and connect your Metamask wallet.
Select the LW3Token.sol contract, and enter values for the constructor arguments _name and _symbol.
Click Transact and approve the transaction from Metamask to deploy your contract!
When deployed, the contract should show up under the Deployed Contracts section. Click the Copy Address button to copy the contract address.
Go to Sepolia Etherscan and search for your contract address and you should see it there!
Viewing Tokens in Metamask
You may notice that even though you minted tokens to your address, they don't show up in Metamask.
This is because Metamask cannot detect random ERC20 token balances (since there are literally hundreds of thousands of them). They have a list of the most well known ERC20 tokens that they can show automatically, but apart from that, for your own tokens, you will usually need to tell Metamask to add it to your wallet manually.
To do so:
Copy your contract address
Open Metamask and click Import Tokens in the Assets tab
Enter your Token Contract Address, and it should detect the name and number of decimals automatically
Click Add, and you will see your balance in Metamask!
Congratulations!
Congratulations! You've successfully deployed and minted your own ERC20 token! Onwards and upwards from here!
If you ran into any trouble, call me anytime, I will help you!
Thanks for reading my post.
Happy coding!