Skip to content

hashguide/erc20-tutorial

Repository files navigation

ERC20 Fungible Token Deployment for Beginners

⚠️

If you would like to follow along with the video lesson, please visit TheCryptoist.com and find the tutorial for this lesson, the video can be found at the bottom. You can also check out YouTube.com/hashguide to subscribe and never miss another lesson again.

⭐ Thank you! ⭐

Deployment to POA's Sokol Live Test Network using the Truffle environment and OpenZeppelin library of well-established Smart Contracts.

OpenZeppelin Contracts have already been tested thoroughly and follow all ERC Standards and are up-to-date.
For Production use; be sure to have final contracts audited to prevent loss of assets.

Install Global Dependencies

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

ERC20 Tutorial is performed in a Linux Environment, therefore, certain commands & methods of execution may differ from a Windows Environment. I will be using VS Code IDE for code editing and a bash terminal while setting up project environment. Lines starting with '$' will be a command performed within a system terminal

Mnemonic Seed Phrase

This method of obtaining mnemonic seed should ONLY be used for testing purposes. For production use on a main network with actual value, a more secure method should be used to obtain an account for deployment, such as geth, parity, mew (MyEtherWallet) or mycrypto.
Any 12-word mnemonic seed phrase generated by an EVM based wallet should work. If you have one, you can skip this step to generate one

  • We are going to use 'ganache-cli' in a terminal to obtain our 12-word mnemonic seed to use as our secret to deploy on Sokol Test Network.

$ ganache-cli

NOTE
This will start a local EVM & display our mnemonic seed, copy the 12 words and paste into a new file named .secret inside our project root directory. To start 'ganache-cli' with the same accounts next time, use the command below to do so.

$ ganache-cli -m 'twelve word seed entered here within quotes'

Setting up project environment

  • Create new directory for our project & 'cd' into the newly created project directory. Project name I will be using for this tutorial will be 'HashGuideCoin', replace with desired name of your project.

$ mkdir HashGuideCoin && cd "$_"

  • Initialize our project using desired node package manager ( npm || yarn ) & initialize the truffle project at the same time. I will be using yarn in this tutorial but npm will work as well.

$ yarn init -y && truffle init
OR
$ npm init -y && truffle init

  • Add required dependencies needed for this project. This will create a folder within our project called 'node_modules' that stores all dependencies added using the package manager, to the current project.

$ yarn add @openzeppelin/contracts @truffle/hdwallet-provider
OR
$ npm install @openzeppelin/contracts @truffle/hdwallet-provider --save

  • Time to open project in desired code editor. I will be using VS Code for this tutorial. Visual Studio Code is an Open Source Code IDE that is free-to-use and top of the line. To open project folder within VSCode, enter the command below in the terminal.

$ code .
OR
$ code /path/to/project

Configuring Truffle

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.

  • open truffle-config.js in code editor

Configuration used for this tutorial
Image of truffle's configuration to deploy HashGuideCoin on POA's Sokol Test Network

Writing our smart contract

Smart Contracts in this tutorial will be written in the programming language called 'Solidity'. This being said, we need to make sure our contracts have the '.sol' file extension to be recognized.

  • Create a new file in the contracts directory within the root of our project. Name this file according the the contract type it will be, mine being HashGuideCoin.sol - Let's get started!

HashGuideCoin contract
Image of code for HashGuideCoin contract to deploy ERC20 Token to POA's Sokol Test Network

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

Creating deploy 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.

Deployment script for 'HashGuideCoin' contract Image of code for deployment scripts to deploy HashGuideCoin ERC20 token to POA's Sokol Test Network

Interacting with deployed contract

Stay tuned to @hashguide YouTube for upcoming tutorial on interacting with contracts using a few different methods. For now, head on over to truffle-console.js for a brief explanation on using 'truffle console' to interact with newly deployed ERC20 token.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published