Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

What is Truffle Suite? Features, How to Install, How to Run Smart Contracts

Updated on 31 October, 2022

10.53K+ views
8 min read

In the early days, when Blockchain just began its journey into the mainstream tech domain, you had to develop Smart Contracts using Solidity programming language and deploy them by calling the geth or solc functions.

To make this process a tad easier, you had to write bash scripts that would first compile and then deploy the contract. Now, although the latter approach was better than the former, it was pretty rudimentary, given that bash scripting often entails a lack of standardization.

This need for creating a seamless and optimal development and testing framework for Blockchain Smart Contracts is what gave birth to Truffle Etheruem.

Learn Online Software Engineering Course from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.

What is the Truffle Suite?

According to Truffle Suite, Truffle is a “world-class development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.”

In simple words, Truffle is a development environment, testing framework, and asset pipeline all rolled into one. It is based on Ethereum Blockchain and is designed to facilitate the smooth and seamless development of DApps (Distributed Applications). With Truffle, you can compile and deploy Smart Contracts, inject them into web apps, and also develop front-end for DApps. Today, Truffle is one of the most widely used IDEs for Ethereum Blockchain.

The Truffle Suite comprises of three core elements: 

  • Truffle – The actual development environment that integrates compilation, testing, and deployment of Smart Contracts.
  • Ganache – It is a locally deployed Blockchain simulator. Ganache features a graphical user interface that can simulate Blockchain networks and live-test Smart Contracts without requiring you to set up real test networks or using to a remote network.   
  • Drizzle – It is an assortment of front-end libraries that offer useful components for developing web applications that can seamlessly connect with the Smart Contracts. 

Read: How To Become A Blockchain Developer – A Beginners Guide

What are the features of Truffle?

The features that make Truffle Etheruem one of the most widely used IDEs for Ethereum Blockchain are:

  • It has built-in support for compiling, deploying and linking Smart Contracts.
  • It allows for automated contract testing with Mocha and Chai.
  • The Truffle Console allows you to work with your compiled contracts in a hassle-free manner.
  • It has a configurable build pipeline that supports both console apps and web apps.
  • It comes with built-in support for JavaScript, CoffeeScript, SASS, ES6, and JSX.
  • It has generators that help in the creation of new contracts and tests (for example, rails generate).
  • It has a script runner that allows you to run JS/Coffee files, including your Smart Contracts.
  • It allows for the instant rebuilding of assets during the development stage.
  • It enables contract compilation and deployment using your preferred choice of RPC client.
  • It supports both network and package management.

How to install Truffle Ethereum?

You can install Truffle Ethereum using the Node Package Manager (npm). First, you need to set up NPM on your computer, and then install Truffle. To do so, you need to open the terminal and type the following:

npm install -g truffle

In Linux machines, however, you might need to add “sudo” prefix to the above statement. Once you’ve installed the Truffle framework, make sure to download and install the Ganache blockchain simulator. You can visit the official Ganache website – it contains installers for most popular platforms.

Now that you’ve successfully installed Truffle, you can start a Truffle project in two ways. To create a bare project, you can type the following statement:

truffle init

However, you can also use the Truffle unbox command to create a project with existing code. For instance, you can create a token like so:

truffle unbox metacoin

On running this command, a project will be created from a Truffle box. You can find many Truffle boxes on the official website. They contain boilerplate code and all the necessary configurations for building projects and launch them quickly.

The structure of a Truffle Project

The Truffle folder you create will look something like this:

├── contracts

│ ├── ConvertLib.sol

│ ├── MetaCoin.sol

│ └── Migrations.sol

├── migrations

│ ├── 1_initial_migration.js

│ └── 2_deploy_contracts.js

├── test

│ ├── TestMetacoin.sol

│ └── metacoin.js

├── truffle-config.js

└── truffle.js

Now, we’ll discuss in detail about the different sub-folders contained in your Truffle folder.

Contracts folder

The Contracts folder is one where all your Smart Contracts are stored. In this folder, there’s also a special file known as the Migrations.sol file. Usually, when Truffle compiles your project, it will browse through the Contracts folder to compile all the compatible files.

Migrations folder

Truffle Migration refers to a script that defines how your Smart Contracts will be deployed to the Ethereum Blockchain. Migrations are essential because as your project keeps becoming more complex, the complexity of your deployments also increases. Thanks to Truffle Migrations, you can automate the process of the deployment of Smart Contracts in a sequential manner.

If you look back at the Truffle folder structure, you will see a file called 1_initial_migration.js. This file deploys the Migrations.sol contract to the Ethereum Blockchain.

Migrations allow you to:

  • Set the maximum gas limit for deployments
  • Modify or change the from the address of deployments.
  • Call arbitrary contract functions.
  • Deploy libraries

Test folder

When it comes to Smart Contracts, testing is a must! Thankfully, Truffle has a built-in testing framework that allows you to write tests in Solidity or JavaScript. If you write your tests in Solidity, you have to import the Smart Contracts into the tests with the Solidity import directive, like so:

import “../contracts/MetaCoin.sol”;

However, if you are writing tests in JavaScript, you have to import them using the artifacts.require() helper function, like so:

var MetaCoin = artifacts.require(“./MetaCoin.sol”);

Configuration file

The configuration file, also known as, truffle.js or truffle-config.js, defines how Truffle can connect to Ethereum networks along with the following things:

  • Environments – It allows you to can define the address of the geth note, the network_id, the max gas limit for deployment, and the gas price you are willing to pay.
  • Project structure – You can change the location where the files are built and stored.
  • Compiler version and settings – You can fix the solc version and set -O (optimization) parameters.
  • Package management – Truffle is compatible with EthPM (Ethereum Package Manager). You can set up dependencies for EthPM for your Truffle projects.
  • Project description – It states who developed the project, specifies the project name, contact addresses, and so on.

Also read: Blockchain Project Ideas for Beginners

How to run Smart Contracts?

Here are the different ways to run Smart Contracts – 

  • For compiling Smart Contracts, you have to run the following code:

truffle compile

  • For running migrations, you have to use the following code:

truffle migrate

You can also do it by mentioning a specific environment:

truffle migrate –network live

  • For testing Smart Contracts, you can run the following code:

truffle test

You can also run a specific test by using the following code:

truffle test ./path/to/FileTest.sol

In this post, we’ve aimed to give you the basic idea of Truffle Etheruem and how it functions. Truffle is a powerful tool that makes the development of DApps and Smart Contracts much more convenient by bringing the standard development practices into the Blockchain picture.

Wrapping up

There is a rise in careers in blockchain technology and blockchain has tremendously changed the very face of the technology industry forever. If you’re interested to become a blockchain developer and build smart contracts and chaincodes, checkout IIIT-B & upGrad’s Advanced certificate program in blockchain technology.

Frequently Asked Questions (FAQs)

1. What is Vyper on Ethereum?

Vyper is a contract-oriented, statistically typed, pythonic programming language that targets the Ethereum Virtual World. It was designed as an improvement over Solidarity. The main principles and goals of Vyper are security, language and compiler simplicity, and auditability. Vyper is a strongly typed language and hence does not allow one data type to be used as another. It comes with many added features such as bounds and overflows checking, strong typing, small and understandable compiler sides, limited support for pure functions, support for signed integers and decimal fixed-point numbers, and decidability. It also has a simple syntax which makes it impossible for developers to code ambiguous programs.

2. What are the disadvantages of Smart Contracts?

Smart contracts, even though they have so many uses and wider popularity, suffer from many limitations. There is a weal legal regulation for the enforcement of smart contracts, which makes it more prone to cyber-attacks. Changing the smart contract process is nearly impossible as any code error is time-consuming and expensive to correct. Although the involvement of third-party is significantly reduced, it cannot be eliminated completely. For example, developers need lawyers to understand the terms to create codes for smart contracts. Smart contracts also have a high dependence on programmers and exposure to bugs, which is a significant disadvantage.

3. What are network and package management in blockchain?

A package manager helps you automate the installation, updation, configuration, and application removal. They are used in operating systems and programming environments and help avoid dependency hell. Key functions of package managers include ensuring the package's authenticity, downloading software from an online repository, updating existing software, etc. There are many types of package managers, binary packages, source code-based packages, hybrid systems, meta-package managers, applications-based managers, etc. There also exist blockchain-related package managers. One such manager is the Node Package manager. NPM is the largest software registry in the world that allows individuals to utilize shared resources via their open-source repository.

RELATED PROGRAMS