Skip to main content
Tutorial GitHub Repository

Prerequisites

Foundry

For this tutorial, you will be using the Foundry toolkit to develop, compile, and deploy your contracts. If you do not have Foundry installed, follow the Foundry installation instructions.

Setup

First, create a new directory for your project.
Next, initialize a new Foundry project inside that directory.
Once the project is initialized, you can proceed to installing the required dependencies needed for this tutorial. In this case, you only need Initia’s EVM contracts.

Implementing the Contract

Before writing the contract, first rename the template contract to NewInitiaERC20.sol.
Then update the contract from the template to be your custom ERC20 contract. Start by importing the InitiaCustomERC20 contract from the @initia/initia-evm-contracts package.
src/NewInitiaERC20.sol
Next, extend the InitiaCustomERC20 contract and add the constructor to initialize the contract with the name, symbol, and decimals of your custom ERC20. For this tutorial, you will simply customize the base contract by adding a logic to mint tokens to the contract deployer during deployment.
src/NewInitiaERC20.sol
The contract implementation is now ready. However, if you try to compile the contract using forge compile, you will get an error. This is because the default Counter.t.sol and Counter.s.sol expect the original Counter.sol contract to be available. To fix this, rename Counter.t.sol to NewInitiaERC20.t.sol and Counter.s.sol to NewInitiaERC20.s.sol.
Now replace the contents of the NewInitiaERC20.t.sol file with the following placeholder content.
test/NewInitiaERC20.t.sol
And replace the contents of the NewInitiaERC20.s.sol file with following placeholder content.
script/NewInitiaERC20.s.sol
Now running forge compile should work without any errors.

Expected Output:

Deploying the Contract

Now that the contract is compiled and ready, you can deploy it to the MiniEVM. To accomplish this, use Foundry’s forge create command
Security Note: In this tutorial, a private key is exported directly in the terminal for simplicity. This is fine for testnet or throwaway accounts. Do not use this method for accounts holding real funds. For production usage, place sensitive keys in a .env file (ignored by git) or use a secure key manager.

Expected Output:

To confirm that the contract was deployed successfully, you can try querying the balance of your deployer account using Foundry’s cast call command.

[Expected Output]: