Creating Standard ERC20s via ERC20Factory
For developers looking to create standard ERC20 tokens on EVM rollups, we recommend using the ERC20Factory contract.
Prerequisites
For this tutorial, we will be using Viem to interact with the MiniEVM and ERC20Factory contract. If you do not have Viem installed, follow the installation instructions.
Project Setup
First, we need to create a new directory for our project.
Next, we will initialize the project and install the Viem package.
We then create two directories:
src
: For our contract source codeabis
: For our contract ABIs
Once the two directories are created, we then add the ABI for the ERC20Factory and ERC20 contracts to the abis
directory.
Development
Creating the Chain Configuration File
To be able to interact with the MiniEVM via Viem, we need to create a chain configuration file. This file will contain various information about the chain, including the chain ID, name, native currency, and RPC URLs.
Let’s create a new file called chain.js
in the src
directory.
Next, we will add the following code to the file:
Interacting with the ERC20Factory Contract
Now that we have our chain configuration file, we can start writing the script to interact ERC20Factory contract. We will create a index.js
in the src
directory.
First, we make the necessary imports:
We then defined the constant variables
privateKey
: The private key of the account we will use to interact with the MiniEVMerc20FactoryAddress
: The address of the ERC20Factory contract on the MiniEVM
You can find the address of the ERC20Factory contract on the different in the Networks page, or by calling the /minievm/evm/v1/contracts/erc20_factory
endpoint of any MiniEVM rollups node.
To be able to interact and call methods to the chain and contract, we then need to create a public client and a wallet client.
Finally, we can now create a new ERC20 token using the createERC20
method of the ERC20Factory contract.
The final code for the script is as follows:
Running the Script
Finally, we can run the script to create a new ERC20 token.
If everything went well, you should see an output similar ot the following:
And that’s it! We have successfully created a new ERC20 token on the MiniEVM.
Was this page helpful?