How To Deploy ERC20 Token on Mainnet/Testnet Using Truffle,Infura and MetaMask

Shahzain Tariq

ERC stands for Ethereum Request For Comments. ERC20 is most Significant token on Ethereum Blockchain. https://github.com/ethereum/eips/issues/20 ≤= click on this link where you can find a ERC20 Token standard for Creating ERC20 token.

Truffle is a Framework for building decentralized applications on Ethereum Blockchain. Truffle Gives you a development enviroment, Testing Framework,compilation etc. check => https://www.trufflesuite.com/

Infura is a backend infrastructure for building and running your DAPP. You can connect to a mainnet/testnet blockchain without running a full node blockchain on your PC. Infura Makes a Blockchain Developer’s easier . =>infura.io

This article will help you migrate your ERC20 token to an Ethereum network provided by infura.In this tutorial, I will help you deploying token to Ropsten Testnet Blockchain using infura, HD wallet-provider, and truffle.

  • MetaMask(should have some ether in ropsten testnet)
  • Infura
  • Truffle
  • HD wallet-provider

For Installing Hdwallet-Provider you need this command

npm install @truffle/hdwallet-provider

NOTE: if you get an MS BUILD type of error then follow this command then try installing HD wallet-provider again

npm install -g windows-build-tools

After installing HD wallet-provider. go to https://infura.io/ and register yourself. login into your infura account you should see a CREATE NEW PROJECT button which will create a PROJECT ID, PROJECT SECRET, ENDPOINT make sure to keep these keys private.

Now we have to Edit truffle-cong.js file to use Hdwallet-provider

  • initialized HDWallet-provider in your config file. add this statement in your config file
const HDWalletProvider = require("@truffle/hdwallet-provider");
  • now we need to provide a mnemonic to our config file. This is where we will connect our metemask with truffle. so getting a mnemonic is so easy just go to metamask then go to Setting > Security & Privacy and click on Reveal Seed Phrase and paste on mnemonic
const mnemonic = "example door key ... ";

NOTE: mnemonic is the most important key in production I would highly recommend you store mnemonic in a secret file because if someone got your mnemonic key then he/she can get access to your account & can withdrawal all of your coins.

  • then add/uncomment this in you truffle-config.js file
module.exports = {
networks: {
ropsten: {
provider: () => new HDWalletProvider(

things to notice:

  • make sure to replace this statement <infura_project_id> with your infura project id
  • The HDWallet-provider takes two arguments one is mnemonic which is your meta mask seed phrase and the 2nd is a ethereum network where you want to deploy your contract if you want to deploy on a mainet put your infura mainnet ENDPOINT mainnet.infura.io/v3/<YOUR_PRJOECT_ID>it will deploy to a mainnet

SO, now we have everything set up the last we need to do is to get some ether on metamask (ropsten testnet) from the faucet. we will need some test ether to deploy the contract on a testnet

and boom you got your test ethereums now its time to deploy on a testnet

  • Compile your contract using this command
truffle compile
  • then deploy on a ropsten testnet using this following command
truffle migrate --network ropsten

if you are having a good day and everything goes well then you should see these following commands

Deploying 'Migrations'
----------------------
> transaction hash: 0x166c1791caa73cca6a75fe4258866bd1f2d1bcf2cd4c3a2a1e03fab29c42829d
> Blocks: 0 Seconds: 0
> contract address: 0x5ccb4dc04600cffA8a67197d5b644ae71856aEE4
......
......

Also:

check out the erc20 token I deployed to use the following method https://ropsten.etherscan.io/tx/0x144084a0be60e85b96a6411573c956db1bab06b1294fe2db66930a290f0948cd

learn How to Create your own ERC-20 Token smart contract here:

if you got any problem then email me at shahzaintariq01@gmail.com

来源

What do you think?

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Loading…

0

Comments

0 comments

對抗疫情金融危機,Steaker 如何增長客戶收益?

Tips for Vyper Beginners