Skip to main content
Tutorial GitHub Repository For developers looking to create standard ERC20 tokens on EVM rollups, the recommended approach is to use the ERC20Factory contract.

Project Setup

First, create a new project directory:
Initialize the project and install the required dependencies:
Create two directories:
  • src: For your script files.
  • abis: For your contract ABIs.
Download the ERC20 and ERC20Factory ABIs into the abis directory:

Setting Up Environment Variables

Create a .env file in your project root:
This file will store your private environment variables, such as your wallet’s private key and the deployed ERC20Factory contract address. These values are required for signing transactions and interacting with the MiniEVM. The ERC20Factory contract is automatically deployed on all MiniEVM rollups as part of the chain’s bootstrapping process. To retrieve the deployed factory address, query {ROLLUP_REST_URL}/minievm/evm/v1/contracts/erc20_factory. {ROLLUP_REST_URL} refers to the REST endpoint of the rollup you are interacting with. Example:
Example response:
Store this address in your .env file as ERC20_FACTORY_ADDRESS. Next, export an EVM-compatible private key from your Ethereum wallet. This private key will be used to sign and send transactions to the MiniEVM. Your .env file should look like this:
Never share your .env file or private key. Anyone with this key can control your account. Keep it local and add .env to your .gitignore so it is never committed to Git.

Development

Creating the Chain Configuration File

To interact with the MiniEVM using Viem, you need a chain configuration file. This file contains essential details about the chain, including the chain ID, name, native currency, and RPC URLs. Create a chain.js file in the src directory:
Add the following configuration:

Interacting with the ERC20Factory Contract

Next, create a script to interact with the ERC20Factory contract:
Start with the imports:
Load the environment variables:
You can also find factory addresses on the Networks page or by calling the /minievm/evm/v1/contracts/erc20_factory endpoint on any MiniEVM rollup.
To interact with the chain and contracts, create a wallet client and a public client:
Now you can create a new ERC20 token using the createERC20 method of the ERC20Factory contract. Implement the createERC20 function:

Full Script Reference

Here is the entire script for reference:

Running the Script

Run the script to create a new ERC20 token:
A successful run outputs something like this:
You have now successfully created a new ERC20 token on the MiniEVM!