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!

Before we get started I would like to give you some important links for ERC20 Tokens

Many Ethereum development standards focus on token interfaces. These standards help ensure smart contracts remain composable, so for instance when a new project issues a token, that it remains compatible with existing decentralized exchanges
A standard interface for fungible (interchangeable) tokens, like voting tokens, staking tokens or virtual currencies
An interactive smart contract generator based on OpenZeppelin Contracts that allows users to create tokens using standards, ensuring composability

These resources will guide you on your journey through this workshop while also allowing you the opportunity to dig a little deeper on these subject matter.


As we begin our Workshop and learn to create and deploy your very own ERC20 Token, we will use the Remix in-browser IDE.

OPEN THIS LINK!

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)

It should look something like this

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

Selecting File Explorer
Creatinig a new File
A new File in your File Explorer should look like this

The Token.sol code looks like this

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "@openzeppelin/contracts@4.6.0/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts@4.6.0/access/AccessControl.sol";

contract Token is ERC20, AccessControl {
	bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

	constructor() ERC20("Chainlink Bootcamp 2024 Token", "CLBoot24") {
    	_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    	_grantRole(MINTER_ROLE, msg.sender);
	}

	function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
    	_mint(to, amount);
	}

	function decimals() public pure override returns (uint8) {
    	return 2;
	}    
}

You can also find the code here in this Github Repository

Token.sol Source Code

Do not deploy this contract yet - we'll get there ๐Ÿ˜„


UPDATING TOKEN INFO

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.

constructor() ERC20("Chainlink Bootcamp 2024 Token", "CLBoot24") {

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!

It should look like this

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.

Example of Metamask Transaction Confirmation

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

Your deployed contracts will appear here

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.

This is how you would copy the address of your token

Open your Metamask and make sure the tokens tab is opened

Token Tab in Metamask

Scroll to the bottom and select the "Import tokens" option

Import Tokens will appear near the bottom of the Tokens tab within Metamask

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.

It should look something like this

Confirm and Import the token into your Metamask

It should look like this

MINTING TOKENS

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.

Example of an expanded deployed Token Contract within the REMIX IDE

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.

Example of expanding the Mint Function so we can input the parameters required

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!

Example of filled in parameters for Mint Function

Make sure to copy your wallet address by opening your Metamask and clicking this field

Clicking your wallet address in Metamask like this will Copy it to your clipboard

or you can copy it directly from the REMIX IDE

You can also copy through clicking this clipboard button within 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.

balanceOf Example

Last updated