TheCryptoist.comsmart contracts ERC20 TOKEN DEPLOYMENT

ERC20 TOKEN DEPLOYMENT


thumbnail for video & guides for cryptoist.org tutorial on deploying erc20 token to ethereum network

Deploying ERC20 Fungible Token for Beginners

In this guide, we will be demonstrating a Deployment of an ERC20 Fungible Token to POA’s Sokol Live Test Network using the Truffle environment and OpenZeppelin library of well-established Smart Contracts. OpenZeppelin Contracts follow ERC Standards & are battle-tested for production use cases. This guide is for beginners who would like to get comfortable with using Solidity & its tools; surrounding its development. Clone the Github repository to try on your own & for additional comments within code or follow along with the video on YouTube & here.

Be sure to have final contracts audited before use in production environment to prevent loss of assets.

Install Global Dependencies

  • node
  • npm || yarn
  • truffle
  • ganache-cli (optional)

ERC20 Fungible Token Deployment tutorial is performed within a Debian Linux Environment, therefore, certain commands & methods may differ from a Windows, MacOS, or other Linux distribution environments.

Obtain Mnemonic Seed Phrase

This method of obtaining 12-word mnemonic seed phrase should ONLY be used during the development phase in during your project. For production use, be sure to obtain mnemonic seed in a more secure manner to prevent loss of assets. Any 12-word mnemonic seed phrase obtained through an Ethereum wallet will work with this tutorial. If you already have one you would like to use, please skip this step and move onto setting up your development environment.

ganache-cli -m 'twelve word seed phrase from ethereum wallet goes here'

If you do not have a BIP39 12-word seed phrase from an Ethereum wallet, start ganache-cli without the flag & argument to obtain one for development purposes. Be sure to save the 12-word seed phrase to a file named .secret within your projects root directory.

Setting up project environment

Let’s create a new folder for our project & cd into it with the following command. Replace HashGuideCoin with the desired name of your project.

mkdir HashGuideCoin && cd $_

$_ takes the argument from previous command performed within bash terminal, some versions of bash may need double quotes surrounding the arg.

Before we begin, let’s initialize our node project to allow use of the node package manager npm || yarn & our truffle project while we are at it. I

npm init -y && truffle init

OR

yarn init -y && truffle init

Now that our project directory is initialized, we can install dependencies needed for our project. Install these using desired package manager.

npm install --save @openzeppelin/contracts @truffle/hdwallet-provider

OR

yarn add @openzeppelin/contracts @truffle/hdwallet-provider

Now that we have out dependencies installed for our ERC20 project, we can open up our project with desired code IDE. I will be using VSCode in this guide, but you may use whatever you are most comfortable with. If new to Solidity programming, make sure to install your IDE’s extension for .sol file extension to provide syntax highlighting and code completion to simplify the process.

code .

OR

code /path/to/project/root

Configuring truffle-config.js

We will be configuring truffle within our project with the ability to deploy to a live network (Live Test networks such as: Sokol, Ropsten, Kovan, etc || Main Networks such as: Ethereum, POA Core, Binance Smart Chain, etc) using truffle’s HDWallet-Provider AND with the ability to use a local javascript-based EVM development network, provided by ‘ganache-cli’ running in the terminal.

In this guide, we will not be going over truffle’s migrations feature as it could complicate things and extend further than this guide needs to go. It is safe to delete the following files provided by default by truffle but leaving the directories alone;
./contracts/Migrations.sol && ./migrations/1_initial_migrations.js

./truffle-config.js

Image of code for truffle solidity tool's truffle-config.js file
To Copy & Paste code, please clone & star github repo @ https://github.com/hashguide/erc20-tutorial

Writing our Smart Contract

Smart Contracts in this guide will be written in the Solidity Programming Language. Make sure any solidity contract file has the .sol file extension. Also, it is recommended to install IDE’s Solidity Extension to allow for syntax highlighting & code completion, if you haven’t done so yet.

Create a new file in the contracts folder based upon the contract’s definition. In my project, I will be deploying HashGuideCoin, my file will be named HashGuideCoin.sol

./contracts/HashGuideCoin.sol

Image of code for ERC20 Token Deployment using OpenZeppelin Contracts & Truffle
To Copy & Paste code, please clone & star github repo @ https://github.com/hashguide/erc20-tutorial

Constructor arguments are required to deploy this ERC20 contract. We can find these inside ‘@openzeppelin/contracts/token/ERC20/ERC20.sol’

Creating Deployment Script

Create new file inside the ‘migrations’ folder & name it 1_deploy_contracts.js Scripts inside the ‘migrations’ folder are run in numerical order. If you need additional scripts run during deployment, name them accordingly.
Example: 1_initial_migrations.js && 2_deploy_contracts.js would run in that exact order.

./migrations/1_deploy_contracts.js

Image of migrations script for truffle to deploy HashGuideCoin ERC20 Token
To Copy & Paste code, please clone & star github repo @ https://github.com/hashguide/erc20-tutorial

I hope this guide helped you on your journey & if you have found it useful, please make sure to show support by Bookmarking this website for future guides & to Follow & Subscribe to my Social Media Accounts below, thank you!

Lots more useful guides will be coming soon from hashguide & would love to hear any input, advice or requests from anyone interested! If you have a request on what you’d like to see, please make sure to contact me!

You can email me @ hg@cryptoist.org
Join my Telegram Group @ https://t.me/hash_guide

YouTube Tutorial

https://www.youtube.com/watch?v=8Y3rZOyM8JA

thoughts & comments

Your email address will not be published. Required fields are marked *