Deploying an ERC-20 Token Using Remix and OpenZeppelin
This guide walks you through deploying an ERC-20 token using Remix, an online Solidity IDE, and OpenZeppelin, a library of secure and reusable smart contract templates.
Prerequisites
- Open the Remix IDE.
- Install the MetaMask extension and configure it to connect to the Xone testnet.
- Fund your MetaMask wallet with Test XOC from a Faucet.
Let’s get started
Step 1: Create the ERC-20 Contract.
-
In Remix, create a new file in the
contracts
folder and name itexample.sol
. -
Add the following code to
example.sol
:
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
contract Test is ERC20, ERC20Permit {
constructor() ERC20("example", "EXAMPLE") ERC20Permit("example") {
_mint(msg.sender, 10000 * 10 ** decimals());
}
}
Change the parameters in the constructor to customize the token:
name: The name of your token. example
symbol: The symbol of your token. EXAMPLE
initialSupply: The initial supply of your token 10000(in whole units, it will be multiplied by 10^decimals() within the contract).
In this example, the token name is "example", the symbol is "EXAMPLE", and the initial supply is 10,000 tokens.
Step 2: Compile the Contract.
-
Click on the 【Solidity Compiler】 tab on the left sidebar.
-
Select the appropriate compiler version (0.8.x).
-
Click on 【Advanced Configuration】 to expand the advanced settings.
-
Choose EVM Version 【paris】.
-
Enable optimization (default 200)
-
Click 【Compile example.sol】.
Step 3: Deploy the Contract.
-
Click on the 【Deploy & Run Transactions】 tab on the left sidebar.
-
Set the environment to Injected Provider - MetaMask if you are using MetaMask, or JavaScript VM for a simulated environment.
-
Click 【Deploy】.
Step 4: Expand the Deployed Contract.
-
In the Deployed Contracts section, find the contract you just deployed.
-
Click on the contract name to expand it. This will show you a list of available functions and variables that you can interact with.
-
Check smart contract address (e.g.: 0xb1a04485443d937e8eEbd260AE954BC3C006422F).
Step 5: Add the Token to MetaMask.
-
Open MetaMask and click 【Import Tokens】.
-
Paste the contract address (in this case
0xb1a04485443d937e8eEbd260AE954BC3C006422F
) of your deployed token. -
MetaMask will auto-detect the token symbol and decimals. Click 【Add Custom Token】.
-
Check your token balance.