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.src: For our contract source codeabis: For our contract ABIs
abis directory.
Predeployed contract
TheERC20Factory 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:
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 calledchain.js in the src directory.
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 aindex.js in the src directory.
src/index.js
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.src/index.js
src/index.js
createERC20 method of the ERC20Factory contract.
src/index.js
src/index.js