Create a Mintable ERC-20 Token on Avalanche C-Chain

·

The ERC-20 token standard is a foundational pillar of the Ethereum ecosystem, defining a common set of rules for creating and managing fungible tokens. As the Avalanche network continues to expand, many developers are bringing their Ethereum-based projects and innovative use cases to its high-throughput, low-cost environment. This guide provides a detailed walkthrough for creating your own mintable ERC-20 token and deploying it on the Avalanche C-Chain using the Fuji Testnet.

Avalanche's C-Chain (Contract Chain) is fully compatible with the Ethereum Virtual Machine (EVM). This powerful feature allows developers to deploy existing Solidity smart contracts directly to Avalanche without learning a new programming language or rebuilding their projects from scratch. We will leverage this compatibility to deploy a standard, mintable token contract.

Prerequisites and Initial Setup

Before you begin the token creation process, ensure you have the Core wallet installed and configured. This wallet will be essential for managing your testnet funds and interacting with your deployed contract.

The first step is to enable Testnet mode within your Core wallet. Navigate to Settings and then select Advanced. Here, you will find the option to turn on Testnet Mode. Enabling this feature automatically switches your wallet's interface to the Fuji Testnet, the designated environment for testing and development.

Acquiring Testnet AVAX

To perform any operations on the network, such as deploying contracts, you need AVAX to pay for gas fees. Initially, your Fuji Testnet balance will be zero. Avalanche provides a Faucet that distributes test tokens to developer addresses.

If your wallet already holds a balance on the Avalanche Mainnet, you can simply paste your C-Chain address into the faucet to request test tokens. If you are a new user without a mainnet balance, you can request a faucet coupon through the Avalanche Guild. Alternatively, the official Avalanche Discord server is a valuable resource where administrators and moderators can often assist developers in obtaining the testnet AVAX required for their projects.

Creating the Token Contract with Remix IDE

For writing, compiling, and deploying our smart contract, we will use Remix IDE, a powerful web-based development environment.

  1. Open Remix: Navigate to the Remix Ethereum IDE in your browser.
  2. Create a New File: Click the "Create new file" button in the left-hand sidebar. You will be prompted to name the file.
  3. Import OpenZeppelin Contracts: Instead of writing a token contract from scratch, we will use a secure, audited implementation from OpenZeppelin. In your new file, paste the following line:

    import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";

    Save the file. Remix will automatically fetch and import the entire OpenZeppelin contracts repository based on this import statement. This provides access to the ERC20PresetMinterPauser.sol contract, which is an ERC-20 standard-compliant token that includes minting and pausing functionality. By deploying this contract, you will become its owner, granting you the privileged ability to create new tokens.

Compiling the Smart Contract

With the contract file ready, the next step is compilation.

  1. Navigate to the "Solidity compiler" tab in Remix.
  2. Select a compiler version that is compatible with the contract. The imported file specifies its version with a pragma statement (e.g., pragma solidity ^0.8.0). You must select a compiler version that is 0.8.0 or higher, such as 0.8.29.
  3. Once the correct compiler is selected, click the "Compile" button. If there are no syntax errors or version mismatches, the contract will compile successfully.

Deploying to Avalanche C-Chain

After successful compilation, you are ready to deploy your contract to the Fuji Testnet.

  1. Go to the "Deploy & run transactions" tab in Remix.
  2. Set the Environment: Click on the "Environment" dropdown and select "Injected Provider - MetaMask" (which will connect to your Core wallet via WalletConnect). A pop-up will appear asking you to connect your account; confirm this connection. Once connected, your Core wallet address should appear in the "ACCOUNT" field.
  3. Select the Contract: In the contract dropdown menu directly above the "Deploy" button, select ERC20PresetMinterPauser.sol.
  4. Deploy: Click the "Deploy" button. You will be prompted to confirm the transaction first in Remix and then in your Core wallet. Confirm both prompts. This transaction deploys your unique token contract to the Avalanche C-Chain.

Verifying the Deployment

After confirming the transaction, your contract is live on the testnet. You can verify this using a block explorer.

  1. Upon deployment, Remix's console will log a transaction hash. Expand this log and copy the hash.
  2. Paste this transaction hash into the search bar of the Snowtrace Testnet Explorer and press enter.
  3. The explorer will display all details of the deployment transaction, including your wallet address (the deployer) and the newly created contract address for your token. Make a note of this contract address.

Minting Your New Tokens

Now that your token contract is deployed, you can mint your initial supply.

  1. In the "Deploy & run transactions" tab of Remix, find your deployed contract listed in the "Deployed Contracts" section. Expand it to see all available functions.
  2. Find the mint function and expand it. This function requires two parameters: an address to receive the tokens and the amount to mint.
  3. Enter your wallet address and the desired amount. Remember that ERC-20 tokens use the smallest unit (like wei for ETH). To mint 1000 tokens (assuming your token uses 18 decimals), you would enter 1000000000000000000000 (1000 followed by 18 zeros).
  4. Click "transact" and confirm the transaction in your wallet. The tokens will be minted and sent directly to your specified address.

Viewing and Managing Your Token in Core

After minting, you need to manually add your custom token to your Core wallet to view and transfer it.

  1. In your Core wallet, ensure you are on the Avalanche C-Chain network.
  2. Click on your assets list and select "Manage Tokens."
  3. Choose "Add Custom Token."
  4. Paste the contract address you copied from the Snowtrace explorer earlier.
  5. Click "Add Token." Your wallet will now display your token balance (e.g., 1000 tst).
  6. You can now send your custom tokens to other addresses directly from your Core wallet interface. 👉 Explore more strategies for managing digital assets

Frequently Asked Questions

What is the Avalanche C-Chain?
The C-Chain is the default smart contract blockchain on the Avalanche network. It is fully EVM-compatible, meaning any tooling or smart contract written for Ethereum can be deployed on it with minimal to no changes, offering developers a familiar environment with faster finality and lower transaction costs.

Why use the Fuji Testnet?
The Fuji Testnet is a testing environment that mimics the Avalanche Mainnet but uses valueless tokens. It allows developers to experiment, debug, and deploy their smart contracts without spending real funds or risking real assets, making it an essential sandbox for safe development.

Do I need to know Solidity to create a token?
While this guide uses a pre-written contract from OpenZeppelin, a basic understanding of Solidity is highly beneficial for customizing token logic, understanding security implications, and debugging potential issues during deployment and interaction.

What can I do with my newly created token?
On the testnet, you can test full token lifecycle operations: minting, transferring between accounts, approving spending allowances for other addresses, and burning. This is perfect for testing the integration of your token into a dApp or exchange before a mainnet launch.

Why didn't my tokens appear automatically?
Blockchain wallets like Core cannot automatically detect every possible custom token. You must provide the specific contract address so the wallet knows which token data to fetch from the blockchain and display in your interface.

Are these real, valuable tokens?
No. The tokens created and minted on the Fuji Testnet have no monetary value. They are solely for testing and development purposes. To create a token on the Avalanche Mainnet, you would follow the same process but switch your wallet and Remix environment to the mainnet.