banner



Do I Need To Register My Icon Tokens From Erc20 Tokens To Icon Tokens

Cryptocurrencies have recently become popular, opening endless possibilities to companies, individuals, and DAOs. If you want to learn how to create and deploy an ERC20 Token In 20 minutes, that'due south the right identify to be.

In this tutorial, you're going to empathise how to create a cryptocurrency using Solidity and the ERC20 Token standard (Ethereum request of comment) maintained by OpenZeppelin.

Nosotros will first write the Smart Contract using REMIX IDE, an online IDE specifically made for Ethereum development with Solidity. We'll then ready upwards a local environment using Hardhat to deploy your own cryptocurrency on the Bombay Polygon Testnet.

By the end of this tutorial you'll learn:

  • Develop and deploy an Ethereum Smart Contracts using the 9 IDE.
  • How to create and deploy an ERC20 Token with Solidity.
  • Setup a local Ethereum development environment using Hardhat.
  • Deploy a cryptocurrency on Polygon Bombay.
  • Visualize your own cryptocurrency on MetaMask.
  • How to start your own cryptocurrency.

It is not assumed whatsoever previous Solidity knowledge, although is suggested to have some previous programming cognition before starting this tutorial. If you don't know where to start, I highly advise you go and check the complete web3 roadmap (Updated this twelvemonth).

That said, let's dig direct into how to develop and deploy an ERC20 token.

How To Create an ERC20 Token: Fix The Environment With REMIX

Nosotros'll learn how to create and deploy an ERC20 Token Smart Contract using REMIX, an easy-to-use, free, with a smashing Solidity compatible IntelliJ feature, and decent compile-time errors, IDE.

Navigate to remix.ethereum.org, open the contacts folder, and create a new file called "Token.sol":

How to Develop a Cryptocurrency with REMIX IDE

Whenever a new Solidity file is created, it'south mandatory to add together the License-identifier and the pragma to specify the Solidity version the compiler should use to build our code.

In the Token.sol file, write the post-obit code:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.8.0;        

The "^" means the lawmaking is compatible with whatever version of the compiler from Solidity 0.8.0 to 0.eight.9.

Now we need to import the ERC20 token contract from OpenZeppelin, simply offset, let me briefly go through what is an ERC20 Token, important to sympathize if yous desire to create your own cryptocurrency.

If you're already familiar with this concept, feel free to skip to the next paragraph.

How to Create and Deploy an ERC20 Token: What is an ERC20?

Co-ordinate to the official OpenZeppelin documentation:

"An ERC20 token contract keeps track offungible tokens: any token is exactly equal to whatsoever other token; no tokens have special rights or beliefs associated with them. This makes ERC20 tokens useful for things similar amedium of commutation currency,voting rights,staking, and more."

Simply put ERC20 is nothing more than than a class, with its methods and members, that runs the logic of what nosotros commonly phone call cryptocurrencies, with a broader meaning though, as it also finds applications in other apply cases.

OpenZeppelin on the other paw is considered the standard library maintaining ERC contracts classes.

If you desire to read more about the ERC20 token standard, here'south a couple of resources:

  • What Is ERC-xx and What Does It Hateful for Ethereum?
  • ERC20 tokens – But Explained

At present that we have a cursory understanding of why we're importing the OpenZeppelin library, and what ERC20 ways, allow'south continue learning how to create and deploy an ERC20 Token.


How to Create and Deploy an ERC20 Token

Import the OpenZeppelin ERC20 contract in the Token.sol file:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.8.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";        

And initialize the Token, inheriting from the ERC20.sol contract:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.viii.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";   contract DevToken is ERC20{ }        

Hither we're declaring a new contract chosen "DevToken", using the Solidity keyword contract, while inheriting from the ERC20 OpenZeppelin'southward contract using the "is" keyword.

Inheriting from the ERC20 contract will give united states access to methods like _mint() and balanceOf(). If you want to have a look through all the available methods, you can bank check the official ERC20 documentation.

The next step is to create a cryptocurrency is to call the contract's constructor and provide the name and symbol of the Token. To do and so, within the contract, write the following code:

          contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){      } }        

At this point your code should look similar this:

          // SPDX-License-Identifier: GPL-iii.0  pragma solidity ^0.viii.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";  contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){      } }                  

Groovy!🎉 1 final step earlier testing our ain Cryptocurrency and moving to more complex topics, we now need to effectively deploy our ERC20 Token.


How To Create an ERC20 Token: Mint The Cryptocurrency

As said before, inheriting from the ERC20 contract, gives united states of america access to the _mint() method used to create new tokens, and ship them to a given address, exactly what we demand now.

Minting is defined equallythe procedure of validating information, creating a new block, and recording that information into the blockchain. But put, "mint" means: creating something, similar a number of Tokens, or an NFT, and saving it on the blockchain.

Allow's say nosotros want to create thou tokens and send them to our wallet, to achieve this, nosotros can add the following code in the constructor:

          contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){         _mint(msg.sender,thou*10**eighteen);     } }                  

At that place's a lot going on hither, let's take a second to empathise it:

First of all, we're calling the _mint() office, which is responsible to consequence the tokens, and wants two parameters:

  • to: address of the wallet/contract that volition receive the tokens,
  • corporeality: corporeality of tokens to send.

The "to" statement, is taken from msg.sender, a special variable which value is the address of the wallet/contract calling the contract. The amount, on the other mitt, needs to take care of the decimals, and that's why nosotros're passing such a big number, let me go through it for a second.

A Note On Decimals

When dealing with cryptocurrencies yous may want to exist able to send capricious amounts, like 0.004ETH. Unfortunately, Solidity and the Ethereum Virtual Machine do not back up decimals: merely integer numbers can be used. This means that just whole numbers can be sent (1, 4, five), and this, of course, poses an issue.

So what'due south the workaround?

Information technology'due south very simple, a token contract can use larger integer values (the EVM supports 256-fleck integers) so that a balance of 1000000000000000000 represents 1 ETH with eighteen decimal places, hence a transfer of 4000000000000000 will represent to 0.004ETH being sent.

We that in mind, when calculating our total supply, we have to take account of the total corporeality of tokens, including the decimal places we want to accept.

If you lot want a full max supply of 1.000.000.000 tokens, with 18 decimal places, similar Ethereum and many other cryptocurrencies accept, you want to pass 1000000000*10**xviii that is (1000000000000000000000000000).

On the other hand, when sending ii tokens the method to call will actually be:

          transfer(recipient, 2 * x**18);        

Ok now that nosotros sympathize what'southward going on in the mint function, permit's exam our ERC20 Token contract.


Deploy Your ERC20 Token Cryptocurrency

On REMIX, click on the Solidity icon on the left side of the screen, and click on compile. You might also want to actuate car compile, to allow REMIX to mind for code changes, and compile your code.

GIF of Vitto compiling the token with REMIX IDE

This will compile the Token.sol code, populating the artifacts binder with our Token'south Contract abi (application binary interface) and their binary version, used to deploy it on the blockchain.

Now that we have our artifacts, click on the Ethereum logo nether the Solidity icon, select your contract in the dropdown carte, and click on deploy:

Deploy smart contracts with REMIX - How to Create and Deploy an ERC20 Token - In 20 minutes

Congratulations! 🎉 If everything worked every bit expected, you lot've just created and deployed an ERC20 token!


Interact With Your First Cryptocurrency

Remember? When deployed, our smart contract should have issued 1000 tokens to our wallet! If y'all watch, right above the Deploy button, there'south the "account" field:

Account after contract deployment on REMIX

That'south the address of the wallet we used to deploy our ERC20 Token contract, nosotros can say that because there's some Ethereum missing, the Gas fees we paid to deploy the contract on the Ethereum Virtual Auto.

If everything worked every bit expected, we should now meet the issued corporeality of tokens in the residue of our wallet's accost.

To test this out, every bit yous can detect, right nether the deploy push, and "Deployed Contracts", in that location's your deployed ERC20 token. Clicking on the dropdown menu volition requite y'all access to all of the ERC20 methods, that your contract has inherited or implemented:

Understanding View vs modify functions in Solidity - How to Develop a Cryptocurrency

The colour of the buttons represents whether the representing part modifies whatever value on the blockchain, costing Gas (Orange), or it's a simple view office just reading and returning a value (Blue).

Betwixt those buttons, there'due south one saying "balanceOf", information technology requires an address as an input and will retrieve the associated amount of ERC20 Tokens. Let's utilize it:

  1. Copy the wallet accost clicking on the "copy" icon near the wallet address.
  2. Curlicue downwardly in the token methods and search for "balanceOf".
  3. Paste the wallet address in the field.
  4. Click the blue balanceOf button.
  5. Check the amount.
Check your token balance with remix
This should requite us back a total corporeality of 1000000000000000000000 tokens, that'south considering nosotros chose to give the Token 18 decimals. To convert the corporeality we tin but divide the number by ten^18 and get back 1000, or go to eth-converter.com to convert on the fly (equally we're using the same amount of decimals equally Ethereum).

Well done, you lot've just created your own cryptocurrency! 🎉

Unfortunately, though, there are ii issues at the moment:

  1. Our Token is not yet accessible from outside REMIX because currently deployed on the Remix EVM, a virtual machine that acts as a blockchain, non accessible by anything except your REMIX instance.
  2. Instead of issuing all the tokens on deployment, as we're doing now, we might want to event the tokens as a reward, as a consequence of an action, or simply in small-scale batches.

Let'southward first accost the offset issue, how to handle token supply.

Note: REMIX uses a hosted virtual ethereum environment, that can be compared to a testnet but it's not publicly accessible outside the environs itself. Your contract won't be deployed on the actual Ethereum mainnet, nor in a publicly accessible testnet.


How to Develop an ERC20: Create A Token Supply That Works

When y'all need to create your own cryptocurrency supply, we have 3 primary choices:

  • Fixed Supply
  • Uncapped Lazy Supply
  • Capped Lazy Supply

At this signal, our token has a Fixed supply issued on deployment, let'due south explore what information technology means, and the alternatives we accept when developing our cryptocurrencies.

Fixed Supply

The total supply of the token is issued on deployment and sent to the deploying wallet address.

In this case, we cull a total supply beforehand and issue the whole amount to our wallet when the contract's constructor gets called, leaving us the try of distributing the tokens among different holders.

If nosotros don't desire to upshot all the tokens at one time, though, nosotros should opt for a lazy minting approach.

Uncapped Lazy Supply

Tokens aren't minted and issued in a unique batch on deployment, but in small quantities and sent to the specified wallet(s), consequently to ane or more actions.

In this instance, the full max supply is regulated through economic-driven principles and not on a hard-coded value.

Recollect of a Miner validating a transaction and getting tokens back every bit a reward, or a user stacking their tokens to receive periodic rewards.

The absenteeism of a hardcoded Max supply, though, could brand your token inflationary, incurring a loss of value over time, or worst putting its security at risk. Even if this goes outside the focus of this tutorial, is good to understand that we tin, and should, cap our supply.

Capped Lazy Supply

Like in the Uncapped Lazy Supply mechanism, the tokens are issued in pocket-sized quantities, with the only difference that here the max-supply is decided beforehand and hardcoded in the smart contract, or passed on deployment.

In this tutorial, we're going to broadly explore all the methods to create the supply of our Tokens.


ERC20 Token Supply – Fixed supply

Let's say we want a token with a fixed supply of 1000 Dev Tokens (like we did in our code) initially allocated to the wallet that deploys the contract, to practice then we simply called the _mint() private role inside the Token Constructor:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.8.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";  contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){         _mint(msg.sender,1000*10**18);     } }                  

Knowing that the constructor gets called merely in one case, on deployment, this smart contract not only transferred 1000 tokens (the amount has eighteen decimal places: see a note on decimals section) to our wallet simply made it as well impossible to mint whatever new token, non having an exposed _mint() function in its code.

Nosotros can bank check the token residual of the address that deployed the token by calling the balanceOf() method, just like nosotros did before.

So, what if we want to result tokens over time and not in a unique batch?

ERC20 Token Supply – Uncapped Lazy Supply

To reach this we tin simply move the mint function from our constructor to a new public function that tin can be called nether different circumstances:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.8.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";  contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){}      function issueToken() public{         _mint(msg.sender, yard*10**xviii);     } }                  

In this instance, every time issueToken() is called, the caller volition receive that amount of tokens. Of course, we can too laissez passer arguments to vary the issued corporeality of coins or the receiver:

          // SPDX-License-Identifier: GPL-three.0  pragma solidity ^0.eight.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";  contract DevToken is ERC20{     constructor() ERC20("DevToken", "DVT"){}      function issueToken(address receiver, uint256 amount) public{         _mint(receiver, amount);     } }                  

The issue here is that, without any further command, there's no limit to the number of tokens a user tin outcome. Every bit a workaround, nosotros can cap the total supply of the Token.

ERC20 Token Supply – Capped Modular Supply

To add a max supply to our Token, nosotros can employ the ERC20Capped OpenZeppelin library.

ERC20Capped is a sub-class of ERC20Mintable that in turn inherits from the standard ERC20 contract. This allows us to substitute the ERC20.sol library in our code, with ERC20Capped, while maintaining methods such as _mint() and balanceOf().

We'll also need to specify a cap value by passing a uint256 argument to our Token constructor and feeding it into the ERC20Capped constructor.

Let'southward import the ERC20Capped library from OpenZeppelin, and add together the post-obit code to the Token.sol contract:

          // SPDX-License-Identifier: GPL-three.0  pragma solidity ^0.viii.0;  import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";  contract DevToken is ERC20Capped{     constructor(uint256 cap) ERC20("DevToken", "DVT") ERC20Capped(cap){ }      function issueToken() public{         _mint(msg.sender, 1000*x**xviii);     } }        

We tin can now examination our Capped token using REMIX, just similar we did before:

  1. Click on the Solidity Icon and compile your code
  2. Select your Token contract from the dropdown menu
  3. Insert the cap corporeality in the deploy field
  4. Click on Deploy
  5. Click on the "cap" button method to retrieve the cap value
Compile your capped ERC20 token example

Equally y'all tin meet, in the example, we've inserted a cap value of 10000000000000000 that, because the 18 decimal places, corresponds to a max supply of 0.01 DVT. Using the issueToken() method will now revert the transaction throwing a "cap exceeded" error:

Error when cap is exceeded ERC20

Now that we accept a mintable Token at that place is one issue left to solve: everyone tin mint information technology by calling the issueToken() function, and that rises a huge security consequence. Gladly, in that location is a solution to it: Owned contracts.


How to Create a ERC20 Token – Security and Access Control

Copying what the OpenZeppelin documentation on access-command tells us:

Access control, or "who is allowed to practice this affair", is incredibly of import when dealing with smart contracts. The access control of your contract may govern who can mint tokens, vote on proposals, freeze transfers, and many other things.

It is thereforecritical to understand how you lot implement it, lest someone else steals your whole system.

The most common and basic grade of access control is the concept ofownership where there's merely an account allowed to perform sensitive tasks on a contract (the possessor). This arroyo is perfectly reasonable for contracts that take a single administrative user.

OpenZeppelin provides Ownable for implementing buying in contracts.

To use it, nosotros'll need to import the contract in our lawmaking, add it as a super-grade of our Token contract, only like we did before, and add together a function modifier to the issueToken() function Add LINK:

          // SPDX-License-Identifier: GPL-3.0  pragma solidity ^0.8.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol";  contract DevToken is ERC20, Ownable{     constructor() ERC20("DevToken", "DVT"){}      function issueToken() public onlyOwner{         _mint(msg.sender, g*x**18);     } }                  

Every bit we can find, the Token contract is at present inheriting both from the ERC20, and Ownable contract, this gives us access to the onlyOwner office modifier applied to the issueToken() function.

onlyOwner volition run every time issueToken() gets called, verifying if the caller is the owner of the contract.

By default, the owner of an Ownable contract is the account that deployed information technology, which is usually exactly what you desire.

Now that nosotros take a reasonable agreement of how to design our token supply and how to secure its minting process, allow'southward learn how to deploy our token to a real and accessible blockchain, setting up a local development environs using Hardhat.


Fix Your Local Blockchain Developer Environment

If we want to transfer the just created Token to another wallet, list it on an exchange, or simply use it in the existent world, REMIX won't exist enough. To deploy an Ethereum smart contract to a public blockchain, such as Polygon or Ethereum, nosotros'll demand to ready an Ethereum development surround like Hardhat or Truffle.

In this tutorial, we'll utilize Hardhat, and assume yous have VSCode already installed on your device.

Start by creating a new folder:

          mkdir myFirstToken        

Navigate to the project folder, install Hardhat and the dependencies needed to compile and test our Token smart contract:

          yarn add hardhat @nomiclabs/hardhat-waffle @nomiclabs/hardhat-ethers ethers ethereum-waffle        

You can larn more virtually the dependencies we're installing, in the official Hardhat documentation.

In one case installed initialize the Hardhat setup wizard past running:

          npx hardhat        
How to Develop a Cryptocurrency - HardHat Setup wizard

Select:
Create a basic sample projection > leave default root > add a .gitignore.

This will populate our project directory with the default Hardhat files and folders.

If you're not familiar with some of the just created files and want to dig deeper into what those are, check out the create your starting time DApp with solidity guide.

The adjacent step will exist to modify the hardhat.config.js file that contains the configuration settings to connect with running blockchain instances, only first, allow's catch our Node Provider Endpoint URL.

Grab Your Mumbai Provider Endpoint Using Alchemy

When deploying something on the blockchain, you'll demand a node responsible to run your smart contract, to do so yous accept 2 options:

  • Spin upwards your own Ethereum node.
  • Use a 3rd political party node provider similar Abracadabra or Infura.

Running your own node is unremarkably discouraged, equally it's difficult to maintain, is difficult to scale, needs to be upgraded, and should ensure country consistency, requiring some serious constant engineering endeavour. (read more than about Nodes every bit a Service here)

In this case, we'll apply Abracadabra as a Mumbai Node provider, as it'southward completely gratis, like shooting fish in a barrel to set up, and has stunning features.

Navigate to alchemy.com and create a new account:

Alchemy Ethereum  and Polygon node provider homepage

Once logged in, click on "+ CREATE APP":

Alchemy ui with your applications

And fill in the fields as follow:

Name: MyProject
Description: My First Token
Environment: Evolution
Concatenation: Polygon
Network: Polygon Mumbai

And click on CREATE APP.

Select the network to deploy your first cryptocurrency

Search for the newly created app under Abracadabra Apps, and click on it.

Once on the app page, click on "VIEW Primal", and copy the HTTP Endpoint:

Copy the HTTP Polygon Mumbai Node Endpoint

At present that we accept the Polygon Mumbai endpoint copied, let's alter our hardhat.config.js file.


Modify The hardhat.config File

We're going to deploy our token to the Mumbai Polygon Testnet, but what'due south explained in the post-obit chapter, is applicable for all the Blockchain networks built on top of Ethereum (just change the hardhat.config.js setting to adapt to the desired chain).

Open the hardhat.config.js file, in the root directory of your project and add the following code inside the module.exports object:

          module.exports = {   solidity: "0.viii.four",   networks:{     mumbai:{       url: 'YOUR ALCHEMY POLYGON MUMBAI ENDPOINT',      }   } };        

The adjacent step is to add the private cardinal of the wallet we desire to use the deploy the Token on the blockchain, but offset, we need to install the dotenv library to proceed our individual cardinal secure

Allow'southward kickoff by installing dotenv.

Install dotenv

In the terminal, within the project folder, install the dotenv library by typing:

          yarn add dotenv        

and create a new .env file in the root folder of your project.

Once created, add the .env file to your .gitignore, this will prevent you from pushing your secrets to GitHub or whatever other version control service yous might be using.


Note: pushing your wallet'due south individual cardinal to GitHub volition result in your fund existence stolen by bots. Make sure to go along your secrets…clandestine.

Now we need to catch our individual key, to do then, you'll need a crypto wallet.

Grab Your Wallet's Private Key

In this tutorial, we're going to utilize MetaMask, equally information technology's one of the nigh widely used and easy to prepare. If you don't already have MetaMask installed, hither's a guide on how to create your MetaMask wallet.

Once installed, motion to your MetaMask extension and:

  1. Click on the three dots menu.
  2. Click on "Account details".
  3. Click on "Consign Individual Primal".
  4. Insert your Password.
  5. and copy your private key.
Grabbing Metamask's wallet private key to deploy the Token

Salvage The Private Key in the .env file

Go back to the .env file in our project folder and declare a new variable, telephone call it "PRIVATE_VARIABLE" and assign to information technology the value of your private key:

          PRIVATE_KEY="YOUR Private KEY"        

Open up the hardhat.config.js file and initialize dotenv to gain access to the environment variables contained in the .env file. To practise so, at the outset of your hardhat.config.js file, import dotenv as follows:

          require('dotenv').config()        

Now, inside the module.exports object, right under the 'url' property, add the account we desire to utilise to deploy our Token Smart contract:

          module.exports = {   solidity: "0.8.4",   networks:{     bombay:{       url: 'YOUR ALCHEMY POLYGON MUMBAI ENDPOINT',       accounts: [`0x${procedure.env.PRIVATE_KEY}`]     }   } };                  

As you tin can notice, using JavaScript string literals, we appended '0x' to our private key, because Hardhat expects a Hexadecimal string that starts with 0x every bit a private key, MetaMask on the other hand, gives the prefix for granted, removing information technology.

We're also accessing our PRIVATE_KEY variable, using process.env.NAME_OF_VAR.

At this point our hardhat.config.js file should look like this:

          require("@nomiclabs/hardhat-waffle"); crave('dotenv').config()  job("accounts", "Prints the listing of accounts", async (taskArgs, hre) => {   const accounts = await hre.ethers.getSigners();    for (const account of accounts) {     panel.log(business relationship.address);   } });   module.exports = {   solidity: "0.8.4",   networks:{     mumbai:{       url: 'https://polygon-bombay.chiliad.alchemy.com/v2/jD_n5-Vt3zoIDgZX8ui1mtAueDGh4TQn',       accounts: [`0x${process.env.PRIVATE_KEY}`]     }   } };                  

Corking! Our hardhat.config.js is ready to deploy our contract on Polygon. Information technology'south now time to move the Token code from REMIX to our local dev environment and modify the deployment script.

Let'south kickoff by installing OpenZeppelin in our project.


Add The Token Smart Contract to Your Project

First of all, we'll need to install OpenZeppelin in our project.

In the last, inside the project folder, write:

          yarn add together @openzeppelin/contracts        

Once installed move in the "contracts" binder of our project, and create a new file named Token.sol. Go back to REMIX, copy the Token.sol Contract code we wrote a few paragraphs ago and paste information technology in the new local Token.sol file.

Note: we're going to use the Token with a fixed supply for tutorial purposes, the same volition apply to all contracts.

The code should look as follows:

          // SPDX-License-Identifier: GPL-three.0  pragma solidity ^0.viii.0;  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";  contract DevToken is ERC20{     constructor(uint256 totalSupply) ERC20("DevToken", "DVT"){         _mint(msg.sender, totalSupply);     } }        

At present we need to modify the deployment script.


Change The Deployment Script

In the "scripts" folder, within the projection directory, rename sample-script.js to "deploy.js", and open it.

Replace the content of deploy.js with the following code:

          const hre = require("hardhat");  async function main() {   const DevToken = await hre.ethers.getContractFactory("DevToken");   const devToken = expect DevToken.deploy("1000000000000000000000000000");    await devToken.deployed();    console.log("Token deployed to:", devToken.address); }  main()   .so(() => process.leave(0))   .grab((fault) => {     panel.error(error);     process.exit(1);   });                  

Let's briefly go through what'south going on here:

First of all, we're importing the Hardhat library, which will requite us access to utilities like getContractFactory(). We declare an async function and deploy the token passing equally an statement the totalSupply value needed in the Token constructor.

You lot can read more nearly deploying with Hardhat in the official docs.

As y'all can observe the totalSupply is passed as a string ("1000000000000000000000000000") this considering the value overflows the max int value allowed by JavaScript.

Lastly, we await for the devToken to deploy and impress its address.

The concluding few lines are just calling the principal() role and exiting in case of mistake.

Now everything is set to compile and deploy our cryptocurrency.


Compile and Deploy Your own Cryptocurrency to Polygon Mumbai

Commencement of all, as we did on REMIX, nosotros'll need to compile our Token Contract to get the Artifacts and allow the getContractFactory() function in deploy.js, to take hold of our contract.

In the terminal, run:

          npx hardhat compile        

This creates a new folder in the project root, called artifacts, and populates it with the compiled version of our Token.

Lastly, we'll need to deploy our contract, to do so, though, nosotros'll need some MATIC to pay for the Gas fees. Don't worry, we won't spend a penny, that'due south the reason nosotros're deploying on a testnet.

Get Test MATIC to deploy your cryptocurrency

Getting some test MATIC is very unproblematic:

  1. Navigate to faucet.polygon.technology.
  2. Select the Bombay network.
  3. Paste your wallet accost.
  4. Click on "Submit".
  5. Wait up to a minute to see the MATIC transferred in your wallet.
Get Test MATIC from the faucet

Now we have enough MATIC to deploy our Token Contract.

How to Deploy an ERC20 Token on Polygon Mumbai

Get back to your project folder, and run the post-obit script in the terminal:

          npx hardhat run ./scripts/deploy.js --network mumbai        

Here nosotros're telling Hardhat to run our deploy script using the Mumbai network which settings are specified in the hardhat.config.js file.

After a couple of seconds yous should see the Token Address on the Bombay network logged in the terminal:

Deploy the contract running the deploy script on mumbai
GIF is 10x speed

Fantabulous! You've but deployed your starting time Token to the Blockchain!

If everything worked as expected, y'all should now see your newly created cryptocurrency and the minted amount of tokens in your MetaMask wallet or interact with them in your DApp (larn how to develop a decentralized application)

First, though, we'll need to tell MetaMask how to observe our token.


Add together Your ERC20 Token to MetaMask

There are two steps involved to visualized your own ERC20 Toke on Metamask exercise so:

  • Add together Polygon Bombay to MetaMask.
  • Add together the new Token to Metamask.

Refer to this guide to add Polygon Bombay to MetaMask.

Adding a new Custom Token, on the other hand, is very simple, let'southward run into how.

When nosotros deployed our Token nosotros logged its on-concatenation address in the last, let's copy it and motility to MetaMask:

  1. Make sure to be on the Mumbai Testnet
  2. Scroll to the bottom of the MetaMask extension
  3. Click on "Import Tokens"
  4. Paste your token Address
  5. Click on "Add Custom Token"
Check your custom cryptocurrency token balance

Every bit you can find, MetaMask will automatically recognize the Token Symbol and the number of decimals.

Nosotros did information technology! You've just deployed your starting time cryptocurrency, congratulations!

Conclusions

I truly hope you've how to create and deploy an ERC20 token! If you have whatever issues, feel free to contact me on Twitter or leave a annotate!

Oh, and don't forget to subscribe to the Electronic mail to receive, every week, the best web3 resources to kickstart your career.

Do I Need To Register My Icon Tokens From Erc20 Tokens To Icon Tokens,

Source: https://vitto.cc/how-to-create-and-deploy-an-erc20-token-in-20-minutes/

Posted by: nelsonontowlynat.blogspot.com

0 Response to "Do I Need To Register My Icon Tokens From Erc20 Tokens To Icon Tokens"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel