Now that you understand more about what ERC-20 tokens are, and how Remix is structured, it is time to create and deploy your own ERC-20 token! In this section, you will learn how to create and deploy an ERC-20 token using Remix.IDE!
A Web3 Wallet (e.g OKX wallet or a WalletConnect-compatible wallet)
Testnet Ethereum ( You can request some at the Ethereum Sepolia Facuet)
A Web Browser (e.g., Google Chrome)
Download a Web3 wallet. You can download OKX’s wallet from here or read more about installing a Web3 compatible wallet on our website.
Once your wallet is set up, you will have to acquire some test ETH from the Ethereum Sepolia Facuet. Simply enter your wallet address and login to Alchemy to a small amount of test ETH.
Open Remix and make a new Solidity file, for instance NewToken.sol.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("MyToken", "MT") {
_mint(msg.sender, 1000000 * (10 ** uint256(decimals())));
}
}
Click on the Compile button. Do verify that the compiler’s version is at least 0.8.20 because of the line pragma solidity ^0.8.20;
in the editor pane. You should see a green tick mark on the Compile button! Well done!
To help you understand the code better, here is a breakdown of the code we have written in Step 3!
SPDX-License-Identifier Comment:
Pragma Directive:
Importing ERC-20 from OpenZeppelin:
Creating MyToken Contract:
MyToken
contract is being defined and it extends the functionality of the ERC-20 contract. This means it inherits all the functions and features from the ERC-20 contract.Constructor Function:
Minting Initial Supply:
_mint
function within the constructor is used to mint an initial supply of tokens. In this example, 1 million tokens are created and assigned to the address that deploys the contract.Decimals Adjustment:
decimals
value. The decimals
value is a standard in ERC-20 contracts and is often set to 18 by default in OpenZeppelin’s implementation.You can see the full ERC-20 code on the OpenZeppelin website here.
Great! Now click on the Deploy & Run Transaction button. For deployment, use the Injected Provider option under Environment. Connect to your Web3 wallet and select the Sepolia Test network. Then, click deploy.
If you receive an error message before deployment - “This contract may be abstract”, ensure that the correct contract is selected under the Contract tab.
Confirm the transaction in your Web3 wallet. In this case, we are using the OKX wallet.
Confirm the transaction in your wallet.
Congratulations! Your contract is now deployed on Ethereum’s Sepolia test network! To see the contract that you have deployed, click on "Deployed Contracts" to see the functions of the contract. You should be able to edit the contract name as well.
Congratulations! You have created your very own token on the Ethereum Sepolia Test network!
Utilizing the input to store and retrieve a value incurs a gas cost, and the nuanced aspect lies in the distinction between storing and retrieving.
Both operations approximately cost 23500 gas. However, there’s an important nuance: the gas cost for the retrieve function is only applicable when it is called by another contract. When called from the web, there is no gas cost because you are merely reading data from the blockchain. In this case, you are not instructing the EVM to perform a computational task, making the retrieval operation free when accessed from the web.
Navigate back to the File Explorer by clicking the double document icon in the upper left corner. You will now observe a folder named "artifacts" that has been included in your project. This folder houses various build artifacts, including the ABI for your contract, which will prove valuable in the future but may currently contribute to clutter.
To disable this, you can deactivate artifact generation. Click the settings gear in the bottom left corner and then uncheck the first checkbox labeled "Generate contract metadata...".