Skip to content

LifnaJos/Install_Compile_Test_Deploy_Truffle_Project_on_Ganache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

Install, Compile, Test and Deploy Truffle Project on Ganache Network (via Truffle CLI) or Sepolia Network (via Truffle Dashboard)

1. Installation of Truffle

  • a. On Ubuntu
  • b. On Windows

2. Create or Unbox a Truffle project

  • a. Unbox an existing Truffle Project
  • b. Create a bare Truffle Project

3. Compile a Truffle Project

4. Test the Smart Contracts in Truffle Project

5. Deploy the Truffle Project

  • a. Deploy via Truffle Command Line Interface
  • b. Deploy via Truffle Dashboard

==============================================

Step - 1: Installation of Truffle

a. On Ubuntu 22.04 LTS

  • Follow the steps to install Truffle as per the tutorial

b. On Windows

  1. Install Nodejs

nodejs

  1. Install Truffle
  • On the command prompt, check the version of nodejs node -v

  • Check the version of nvm npm -v

  • Type : npm install -g truffle

truffle

  • Check the version of Truffle truffle version

  • To install Ganachenpm install -g ganache

ganache

  1. Install VS Code

vscode

  1. Add Solidity extension on VS solidity

Step - 2: Create or Unbox a Truffle project

(a). Unbox an existing Truffle Project - MetaCoin

  • On the Terminal : mkdir MetaCoin
  • Go to the folder: cd MetaCoin
  • Unbox the Truffle Project : truffle unbox metacoin

unbox

(b) To create a bare project that doesn’t come with any smart contract or boilerplate code, type: truffle init

  • The following directory structure is created :
.
├── contracts           <-- solidity contracts live here
├── migrations          <-- migration scripts live here
├── test                <-- tests (Solidity and JS) live here
└── truffle-config.js   <-- truffle configuration file

Step - 3 : Compile a Truffle Project

  • On the VS Terminal : truffle compile

compile_error

  • To resolve this issue run the following commands on the VS Terminal

set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Get-ExecutionPolicy

Get-ExecutionPolicy -list

compile_error_solution

  • This command generates .json files corresponding to each Smart Contract.

compile

Step - 4 : Test the Smart Contracts

  • The test files are saved in the folder, test with an extension .js
  • For the sample project created the file name : metacoin.js

truffle_test_files

  • Run the Command : truffle test

truffle_test

Step - 5 : Deploy Truffle Project

a: Deploying the Smart Contract via Truffle Command Line Interface

  • In the Project folder there is a configuration file : truffle-config.js.
  • In this file uncomment the development network parameters and set the port number as 7545 as shown below

config

  • Start the Ganache Environment.
  • Select a new Workspace and name: Metacoin
  • Add the Project configuration file: truffle-config.js

ganache

  • Type the command : truffle migrate --reset

migrate

migrate

  • On the Ganache Environment - Account Tab: 5 transactions are reported corresponding to the deployment

ganache

  • On the Ganache Environment - Blocks tab, 5 blocks are created in the Ganache environment

ganache

  • On the Ganache Environment - Transactions Tab: Contract creation details are listed

ganache

  • On the Ganache Environment - Contracts Tab: Contract deployment details are listed

ganache

  • On Ganache Environment - Events Tab: Contract registered event is reported ganache

b: Deploy via Truffle Dashboard

  1. Run the command truffle dashboard on the VSCode Terminal

truffle_dashboard

  • Truffle Dashboard is running on http://localhost:24012/rpc
  1. Login to the Metamask Wallet and select the Network as Sepolia Testnet

ganache

  1. Run the commnad truffle migrate --network dashboard

ganache

  • This command starts to deploy the smart contract : ConvertLib.sol
  • On the Truffle Dashboard, there will be a prompt to confirm the deployment of the smart Contract : ConvertLib.sol
  • Click the Confirm button

ganache

  • Metamask extension will popup for confirmation.
  • Click the Confirm button

ganache

  • The status of the transaction is displayed on the Metamask popup window

ganache

  • Next the migrate command starts to deploy the smart contract : MetaCoin.sol
  • On the Truffle Dashboard, there will be a prompt to confirm the deployment of the smart Contract : MetaCoin.sol
  • Click the Confirm button

ganache

  • Metamask extension will popup for confirmation.
  • Click the Confirm button

ganache

  • The status of the transaction is displayed on the Metamask popup window

ganache

  • Deployment details on the VScode Terminal as follows:

ganache

ganache

  • The transacrion details are displayed on Etherscan.io : Sepolia Testnet

ganache

Acknowledgements