Create & Deploy ERC20
In this section we will go over how to create and deploy our own ERC20 token using the existing ERC20 Token Standards!
Last updated
In this section we will go over how to create and deploy our own ERC20 token using the existing ERC20 Token Standards!
Last updated
Before we get started I would like to give you some important links for ERC20 Tokens
As we begin our Workshop and learn to create and deploy your very own ERC20 Token, we will use the Remix in-browser IDE.
When you enter the Remix IDE, make sure you are in DEPLOY & RUN TRANSACTIONS view on the left.
Ensure your environment is selected as the "Injected Provider - Metamask", and you're connected to the Ethereum Sepolia testnet; Network Id - (11155111)
This workshop takes place on the Sepolia Testnet, so we will also make sure that the network we are connected to reflects that. Sepolia Network Id - (11155111)
Next we will be creating our own Token.sol smart contract within Remix.
In the Remix FILE EXPLORER, you will create a new file and name that file Token.sol
You will create a new file and name that file Token.sol
The Token.sol code looks like this
You can also find the code here in this Github Repository
You may choose your own Token name and symbol by changing the inputs in the constructor()
function. You can give your token whatever name and token symbol you like!
On the first line of the constructor function, which is the first function ran upon contract deployment. A constructor function is only run once.
Switch to the Solidity Compiler; the icon on the left of the Remix IDE that looks like a "S". Make sure you check the auto-compile box, so that you don't have to keep manually clicking the compile button each time you write new lines of code!
To confirm that your contract has been compiled properly you want to see that Green Check Mark on the lefthand side.
Switch to the Deploy & Run Transactions tab - the 5th Icon and click the Deploy button
Upon clicking the deploy button, it will bring up Metamask and ask you to confirm the transaction.
When your transaction is confirmed you can find the UI for interacting with your deployed contract at the bottom lefthand side of the REMIX IDE
Now we are going to import our newly created Token to our Metamask Wallet & Mint 100 Tokens to ourselves
First we will want to copy our Token Address from the Remix UI's button.
Open your Metamask and make sure the tokens tab is opened
Scroll to the bottom and select the "Import tokens" option
Paste your Token Address into the TToken Contract Address Field within the Import Tokens page in Metamask. You may pause a couple of seconds for Metamask to grab data from your deployed contract and full up those text boxes.
Confirm and Import the token into your Metamask
We will interact with our deployed ERC20 token contract and mint 100 tokens for ourselves (our wallet).
Go to the REMIX IDE and click on the DEPLOYED CONTRACTS Icon on the lower lefthand side of the screen.
Expand the Token.sol contract that you've just deployed.
We will be using the orange colouredmint()
function. To the right of the input box click on the down pointing arrow to see all the inputs that function expects.
The parameters required for the Mint function is as follows
to
: your wallet address
amount: 10000
We use 10000 as the amount because in our contract we have a function which declares the amount of decimal points our custom ERC20 token has. We went with 2 because we wanted it to be as close to Fiat currencies as possible. Solidity doesn't work well with floating point numbers (numbers with decimal points like 100). So in Solidity , $100 would be represented as 100 x (10^N) where N is the number of decimal places.
Our custom token has 2 decimal places, so 100 of our token would be represented in solidity as 100 x (10^2) which is 100 x 100 or 10,000.
It's worth noting that many ERC tokens and native tokens like Ether have 18 decimal places!
Make sure to copy your wallet address by opening your Metamask and clicking this field
or you can copy it directly from the REMIX IDE
Click the Transact button within the Mint Function and confirm the transaction when Metamask pops open.
To check the balance of your token within your wallet you will use the balanceOf
Function with your wallet address as the parameter. You'll see the quantity of tokens that you have just created and minted into your Wallet.
Do not deploy this contract yet - we'll get there