Install, Compile, Test and Deploy Truffle Project on Ganache Network (via Truffle CLI) or Sepolia Network (via Truffle Dashboard)
- 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
4. Test the Smart Contracts in Truffle Project
- a. Deploy via Truffle Command Line Interface
- b. Deploy via Truffle Dashboard
==============================================
a. On Ubuntu 22.04 LTS
- Follow the steps to install Truffle as per the tutorial
b. On Windows
- Install Nodejs
- Go to Nodejs website and download the stable version.
- 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
-
Check the version of Truffle
truffle version
-
To install Ganache
npm install -g ganache
- Install VS Code
- Go to the Visual Studio Code and download the Windows version
- On the Terminal :
mkdir MetaCoin
- Go to the folder:
cd MetaCoin
- Unbox the Truffle Project :
truffle unbox metacoin
(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
- On the VS Terminal :
truffle compile
- To resolve this issue run the following commands on the VS Terminal
set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Get-ExecutionPolicy
Get-ExecutionPolicy -list
- This command generates .json files corresponding to each Smart Contract.
- The test files are saved in the folder, test with an extension .js
- For the sample project created the file name : metacoin.js
- Run the Command :
truffle test
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
- Start the Ganache Environment.
- Select a new Workspace and name: Metacoin
- Add the Project configuration file: truffle-config.js
- Type the command :
truffle migrate --reset
- On the Ganache Environment - Account Tab: 5 transactions are reported corresponding to the deployment
- On the Ganache Environment - Blocks tab, 5 blocks are created in the Ganache environment
- On the Ganache Environment - Transactions Tab: Contract creation details are listed
- On the Ganache Environment - Contracts Tab: Contract deployment details are listed
b: Deploy via Truffle Dashboard
- Run the command
truffle dashboard
on the VSCode Terminal
- Truffle Dashboard is running on
http://localhost:24012/rpc
- Login to the Metamask Wallet and select the Network as Sepolia Testnet
- Run the commnad
truffle migrate --network dashboard
- 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
- Metamask extension will popup for confirmation.
- Click the Confirm button
- The status of the transaction is displayed on the Metamask popup window
- 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
- Metamask extension will popup for confirmation.
- Click the Confirm button
- The status of the transaction is displayed on the Metamask popup window
- Deployment details on the VScode Terminal as follows:
- The transacrion details are displayed on Etherscan.io : Sepolia Testnet
- NodeJS
- VS Code
- VSCode Unauthorized Error article helped to resolve the error
- Truffle Quickstart
- Installing Node JS on Windows
- Truffle Ultimate Guide explains all the ways to deploy smart contracts in Truffle.