Skip to main content
Tutorial GitHub Repository 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 code
  • abis: 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.

Predeployed contract

The ERC20Factory contract is automatically deployed on all MiniEVM rollup as part of the chain’s bootstrapping process To obtain the address of the factory contract, query {ROLLUP_REST_URL}/minievm/evm/v1/contracts/erc20_factory. {ROLLUP_REST_URL} refers to the REST endpoint URL of the rollup from which you want to retrieve the address. For example, you can use the following curl command:
The address field in the response body will contain the contract address:

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:
src/chain.js

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:
src/index.js
We then defined the constant variables
  • privateKey: The private key of the account we will use to interact with the MiniEVM
  • erc20FactoryAddress: 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.
src/index.js
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.
src/index.js
Finally, we can now create a new ERC20 token using the createERC20 method of the ERC20Factory contract.
src/index.js
The final code for the script is as follows:
src/index.js

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.