Create ERC-20 Token
This tutorial guides you through the process of deploying an ERC-20 token on the Fiefdom Playground testnet blockchain.
ERC-20 tokens are a standard for creating fungible tokens on the Ethereum blockchain, and thanks to Fiefdom's EVM compatibility, the process is similar to deploying on Ethereum. By following these steps, you'll learn how to create and deploy your own ERC-20 token.
Prerequisites
Ensure you have Node.js and npm installed.
A text editor or IDE for writing and editing your smart contract code.
MetaMask or another Ethereum-compatible wallet, set up and configured for the Fiefdom network.
Some testnet FIEF in your wallet for deploying the contract.
Step 1: Setting Up Your Project
Create a new directory for your project and navigate into it.
Initialize a new Node.js project by running
npm init -y
in your terminal.Install Hardhat, a popular development environment for compiling, deploying, and testing Ethereum software. Install it using npm:
Step 2: Initializing Your Hardhat Project
Run
npx hardhat
in your project directory. Select “Create an empty hardhat.config.js” when prompted.Install the OpenZeppelin Contracts library, which provides a secure and community-audited ERC-20 implementation:
Step 3: Writing Your ERC-20 Token Contract
Create a
contracts
folder in your project root.Inside
contracts
, create a new file namedMyToken.sol
.Open
MyToken.sol
in your editor and define your ERC-20 token by extending OpenZeppelin’sERC20
contract. Here is a simple example:
This contract creates an ERC-20 token named "MyToken" with the symbol "MTK". The constructor
sets the initial token supply and assigns it to the deployer's address.
Step 4: Compiling Your Contract
Create a
hardhat.config.js
file in your project root if it’s not already there from the Hardhat setup.Configure Hardhat to use the Solidity version installed by OpenZeppelin Contracts and set up the Fiefdom Playground network configuration:
Replace /* Your private key here */
with your own private key. Be careful with your private key and consider using environment variables to keep it secure.
Compile your contract by running
npx hardhat compile
.
Step 5: Deploying Your ERC-20 Token
Create a
scripts
folder in your project root.Inside
scripts
, create a new file nameddeploy.js
.Write a deployment script in
deploy.js
:
This script deploys your MyToken
contract with an initial supply of 1,000,000 tokens (adjust the supply as needed).
Deploy your token to the Fiefdom network by running:
Last updated