Alchemy: Create Your Own ERC20 Cryptocurrency
Learn how to create your own ERC20 Cryptocurrency.
What is ERC20?
ERC20 is a token contract that keeps track of fungible tokens, such as exchange currency, staking, or other things with an exact value. ERC20 tokens do not have special rights or behaviors associated with them like non-fungible tokens (NFTs) do.
An example of ERC20 tokens are Shiba Inu (SHIB), Chainlink (LINK), and Wrapped Bitcoin (WBTC).
Read below to learn how to create your own ERC20 Cryptocurrency.
1. First, download and install S3FS-FUSE on your local environment.
This tool is available on a Linux or macOS system.
2. Set up an Access Key file for use with S3FS-FUSE.
Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs
. You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
chmod 600 ${HOME}/.passwd-s3fs
ACCESS_KEY_ID is your Filebase Access key, and SECRET_ACCESS_KEY is your Filebase Secret key. For more information on Filebase access keys, see here.
3. Mount your bucket.
You can mount a Filebase IPFS bucket with the command:
s3fs mybucket /path/to/mountpoint -o passwd_file=${HOME}/.passwd-s3fs -o url=https://s3.filebase.com
mybucket: name of your Filebase bucket
/path/to/mountpoint
4. Now, navigate into the mounted Filebase bucket.
Create a new folder for your project:
mkdir myFirstToken
5. Install Hardhat with the following command:
yarn add hardhat @nomiclabs/hardhat-waffle @nomiclabs/hardhat-ethers ethers ethereum-waffle
6. Initialize the Hardhat setup prompt with the command:
npx hardhat
Select ‘Create a Basic Sample Project’ > ‘Leave Default Root’ > ‘Add a .gitignore’.
8. From the Alchemy dashboard, we need to create an app.
Select the ‘Create App’ button to get started.
9. Create a new app. For our example, we called our app Token.
Set the chain to ‘Polygon’, and the network to ‘Mumbai’.
10. Then, from our App’s page, select ‘View Key’:
11. Copy your app’s HTTP Key:
12. Next, open the hardhat.config.js file in your project’s directory.
Add the following code into the module.exports section:
Replace ALCHEMY_HTTP_URL with your Alchemy HTTP key we previously copied.
13. Next, install dotenv:
yarn add dotenv
14. Then, copy your cryptowallet’s private key.
If you are using Metamask, follow the instructions found here.
15. Create a new file called .env
.
.env
.This will house your wallet’s private key. If you plan to upload your project files to GitHub, we recommend adding this file to your .gitignore, which will prevent this file from being pushed to GitHub where your wallet’s private key will be accessible by others.
16. In your .env
file, input the following variable:
.env
file, input the following variable:PRIVATE_KEY=”CRYPTO WALLET PRIVATE KEY”
Replace the value with your wallet’s private key.
17. In your hardhat.config.js file, insert the following line at the top of the file:
require('dotenv').config()
Then in the module.exports section, add the following accounts: line:
Overall, your hardhat.config.js file should resemble the following:
18. Create a new file called Token.sol
. Input the following content into this new file:
Token.sol
. Input the following content into this new file:Replace the values to match your desired configuration:
TokenName: Token Name
TKN: Token Symbol
This contract uses a fixed supply of tokens, meaning the total amount of tokens available to be minted and traded is a fixed value.
19. In your project’s scripts
directory, rename the file sample-script.js
to deploy.js
, and replace the existing content with the following:
scripts
directory, rename the file sample-script.js
to deploy.js
, and replace the existing content with the following:Replace TokenName and tokenName with the name of the token you configured in Token.sol.
20. Now we’re ready to compile and deploy our token on the Polygon Mumbai network.
Use the following command to compile:
npx hardhat compile
21. We’ll need some test MATIC to cover the gas fees of our transaction.
Navigate to the Polygon faucet, select the Mumbai network, and send some MATIC to your wallet address.
22. After you have MATIC in your wallet, deploy your token on the Mumbai network:
npx hardhat run ./scripts/deploy.js --network mumbai
Take note of the contract address that gets returned.
23. Now you can add your token to your Crypto Wallet.
This tutorial uses Metamask. If you are using another wallet provider, the workflow will differ.
24. Click on the Metamask browser extension.
Make sure you are on the Mumbai network, then scroll down to ‘Import Tokens’.
25. Enter your Token’s contract address that was returned when you deployed it and your Token’s symbol:
Then select ‘Add Custom Token’.
Congratulations! You’ve created your own Cryptocurrency!
Last updated