Alchemy: Create Your Own ERC20 Cryptocurrency
Learn how to create your own ERC20 Cryptocurrency.
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.
This tool is available on a Linux or macOS system.
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.
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
Create a new folder for your project:
mkdir myFirstToken
yarn add hardhat @nomiclabs/hardhat-waffle @nomiclabs/hardhat-ethers ethers ethereum-waffle
npx hardhat
Select ‘Create a Basic Sample Project’ > ‘Leave Default Root’ > ‘Add a .gitignore’.
Select the ‘Create App’ button to get started.

Set the chain to ‘Polygon’, and the network to ‘Mumbai’.



Add the following code into the module.exports section:
module.exports = {
solidity: "0.8.4",
networks:{
mumbai:{
url: 'ALCHEMY_HTTP_URL',
}
}
};
Replace ALCHEMY_HTTP_URL with your Alchemy HTTP key we previously copied.
yarn add dotenv
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.
PRIVATE_KEY=â€CRYPTO WALLET PRIVATE KEYâ€
Replace the value with your wallet’s private key.
require('dotenv').config()
Then in the module.exports section, add the following accounts: line:
module.exports = {
solidity: "0.8.4",
networks:{
mumbai:{
url: 'YOUR ALCHEMY POLYGON MUMBAI ENDPOINT',
accounts: [`0x${process.env.PRIVATE_KEY}`]
}
}
};
Overall, your hardhat.config.js file should resemble the following:
require("@nomiclabs/hardhat-waffle");
require('dotenv').config()
​
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
​
for (const account of accounts) {
console.log(account.address);
}
});
​
module.exports = {
solidity: "0.8.4",
networks:{
mumbai:{
url: 'YOUR ALCHEMY POLYGON MUMBAI ENDPOINT',
accounts: [`0x${process.env.PRIVATE_KEY}`]
}
}
};
// SPDX-License-Identifier: GPL-3.0
​
pragma solidity ^0.8.0;
​
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
​
contract TokenName is ERC20{
constructor(uint256 totalSupply) ERC20("TokenName", "TKN"){
_mint(msg.sender, totalSupply);
}
}
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.
const hre = require("hardhat");
​
async function main() {
const TokenName = await hre.ethers.getContractFactory("TokenName");
const tokenName = await TokenName.deploy("1000000000000000000000000000");
​
await tokenName.deployed();
​
console.log("Token deployed to:", devToken.address);
}
​
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Replace TokenName and tokenName with the name of the token you configured in
Token.sol.
Use the following command to compile:
npx hardhat compile
Navigate to the Polygon faucet, select the Mumbai network, and send some MATIC to your wallet address.
npx hardhat run ./scripts/deploy.js --network mumbai
Take note of the contract address that gets returned.
This tutorial uses Metamask. If you are using another wallet provider, the workflow will differ.
Make sure you are on the Mumbai network, then scroll down to ‘Import Tokens’.


Then select ‘Add Custom Token’.
Congratulations! You’ve created your own Cryptocurrency!
If you have any questions, please join our Discord server, or send us an email at [email protected]​