Creating Custom ERC20s
Prerequisites
Foundry
For this tutorial, we will be using Foundry toolkit to develop, compile, and deploy our contracts. If you do not have Foundry installed, follow the Foundry installation instructions.
Setup
First, we need to create a new directory for our project.
Next, we will initialize a new Foundry project side that directory.
Once the project is initialized, we can proceed to installing the required dependencies needed for this tutorial. In this case, we only need Initia’s EVM contracts.
Implementing the Contract
Before writing our contract, we first need to rename the template contract to NewInitiaERC20.sol
We then update the contract from the template to be our custom ERC20 contract. Start by importing the InitiaCustomERC20
contract from the @initia/initia-evm-contracts
package.
Next, we need to extend the InitiaCustomERC20
contract and add the constructor to initialize the contract with the name, symbol, and decimals of our custom ERC20. For this tutorial, we will simply customize the base contract by adding a logic to mint tokens to the contract deployer. during deployment.
Our contract implementation is now ready. However, if we try to compile the contract using forge compile
, we will get an error.
This is because the default Counter.t.sol
expects the original Counter.sol
contract to be available. To fix this, we will rename Counter.t.sol
to NewInitiaERC20.t.sol
.
We will also replace the file contents with placeholder content.
Now running forge compile
should work without any errors.
Deploying the Contract
Now that Our contract is compiled and ready, we can deploy it to the MiniEVM. To accomplish this, we will use Foundry’s forge create
command
To confirm that the contract was deployed successfully, we can try querying the balance of our deployer account using Foundry’s cast call
command.
Was this page helpful?