This guide will walk you through the process of deploying an ERC20 token on a local blockchain using Remix IDE and adding it to MetaMask for testing purposes.
Step 1: Set up Remix IDE
- Open Remix IDE in your browser at https://remix.ethereum.org/
- Create a new file named
Token.sol
in the File Explorer
Step 2: Write the ERC20 Token Contract
Paste the following code into Token.sol
:
pragma solidity ^0.8.0;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
constructor(uint256 initialSupply) ERC20("Token", "TOK") {
_mint(msg.sender, initialSupply);
}
}
Step 3: Compile the Contract
- Click on the “Solidity Compiler” tab in the left sidebar
- Select the appropriate compiler version (0.8.0 or higher)
- Click “Compile Token.sol”
Step 4: Deploy the Contract
- Switch to the “Deploy & Run Transactions” tab
- Set the environment to “Injected Provider - MetaMask”
- Ensure MetaMask is connected to your local blockchain
- Set the initial supply (e.g., 1000000000000000000000 for 1000 tokens with 18 decimals)
- Click “Deploy” and confirm the transaction in MetaMask
Step 5: Add the Token to MetaMask
- Copy the deployed contract address
- Open MetaMask and click “Import tokens”
- Paste the contract address into the “Token Contract Address” field
- The token symbol and decimals should auto-populate
- Click “Add Custom Token”
Your ERC20 token is now deployed on your local blockchain and added to MetaMask. You can use it for testing purposes, such as transferring tokens between accounts or interacting with other smart contracts.
Remember to reset your local blockchain and redeploy the token when needed, as local blockchains are not persistent.