Creating a Custom ERC-20 Token

Overview

This section provides a guide on creating a custom ERC-20 token using the Initia platform's precompiled contracts. We will use two specific precompiled interfaces from Initia's library: IERC20 for the ERC-20 token standard and ERC20Registry for registering the token within the ecosystem.

A developer interested in creating a standard ERC-20 token can utilize the factory contract deployed at 0x101FA200c0b44FAAC6944d30C04a97cDe6E6B19c. Refer to @initia/evm-precompiles/erc20_factory/ERC20Factory.sol for more details.

If the minitia deployer doesn't support custom erc20 tokens, you won't be able to deploy cosmos bank supported custom erc20 tokens. Therefore, you should check /minievm/evm/v1/params before proceeding.

Sample Contract Implementation

Here is an example of how to implement a custom ERC-20 token by extending both the IERC20 and ERC20Registry. The contract includes necessary functions and modifiers to ensure compliance and functionality.

import { IERC20 } from "@initia/evm-precompiles/i_erc20/IERC20.sol";
import { ERC20Registry } from "@initia/evm-precompiles/erc20_registry/ERC20Registry.sol";

contract ERC20 is IERC20, ERC20Registry {
    constructor() register_erc20 {
        // Token initialization logic here (e.g., initial mint)
    }
    
    // Transfer function with a modifier to register the transaction in the ERC20 registry
    function transfer(
        address recipient, 
        uint256 amount
    ) external register_erc20_store(recipient) returns (bool) {
        // Logic for transferring tokens
    }

    // TransferFrom function to handle delegated transfers, with a modifier to register transactions
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external register_erc20_store(recipient) returns (bool) {
        // Logic for transferring tokens from one account to another on behalf of the sender
    }
    
    // Internal mint function to create new tokens, with a modifier to register the minting action
    function _mint(address to, uint256 amount) internal register_erc20_store(to) {
        // Logic for minting new tokens
    }
}

Conclusion

By integrating these components into your ERC-20 contract, you can leverage the advanced features of the Initia platform, ensuring that your token operates smoothly within both the Initia and broader Ethereum ecosystems. This setup not only aligns with standard ERC-20 operations but also enhances functionality with specific adaptations for the Cosmos environment.

Last updated

Logo

© 2024 Initia Foundation, All rights reserved.