Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconBlockchain Technologybreadcumb forward arrow iconWhat is Truffle Suite? Features, How to Install, How to Run Smart Contracts

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

Last updated:
24th Mar, 2020
Views
Read Time
8 Mins
share image icon
In this article
Chevron in toc
View All
What is Truffle Suite? Features, How to Install, How to Run Smart Contracts

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.

Ads of upGrad blog

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.

Explore our Popular Software Engineering Courses

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.

In-Demand Software Development Skills

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:

Ads of upGrad blog

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.

Explore Our Software Development Free Courses

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.

Profile

Mayank Sahu

Blog Author
Mayank Sahu is the Program Marketing Manager with upGrad for all emerging technology vertical. His past experience is in analytics industry extensively in healthcare Domain. Mayank has completed his Graduation from IIT Delhi.
Get Free Consultation

Selectcaret down icon
Select Area of interestcaret down icon
Select Work Experiencecaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Blockchain Course

Frequently Asked Questions (FAQs)

1What 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.

2What 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.

3What 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.

Explore Free Courses

Suggested Blogs

Blockchain vs Cloud Computing: Difference Between Blockchain and Cloud Computing
13266
Introduction Cloud computing and blockchain technology are the two on-demand technologies that are booming in the modern market and are being used by
Read More

by Mayank Sahu

25 Feb 2024

Top 12 Highest Paying Blockchain Jobs in India [A Complete Report]
901073
Blockchain is an emerging job skill in the IT industry. Technological advancements are gradually bringing this distributed ledger technology to the ma
Read More

by Mayank Sahu

19 Feb 2024

Skills Needed to Become a Blockchain Developer
54385
Blockchain development is one of the fastest-growing sectors. Companies are looking for blockchain developers to make new implementations, advance the
Read More

by Mayank Sahu

Prerequisites to Learn Blockchain Technology: It’s Not What You Think It Is
54703
There has been a massive development in the field of Blockchain technology in the last decade. Many people and companies came to know about Blockchain
Read More

by Mayank Sahu

16 Feb 2024

Blockchain Developer Salary in India 2024 [For Freshers & Experienced]
903159
The Blockchain Era is has arrived, and it is now. Enterprises across various sectors of the industry are warming up to the concept of the decentralize
Read More

by upGrad

11 Feb 2024

Top 10 Interesting Blockchain Project Ideas for Beginners/Students [2024]
179083
Summary: In this Article, you will learn top 10 interesting blockchain project Ideas for beginners. Trusted Crowdfunding Platform Using a Smart Cont
Read More

by upGrad

14 Jan 2024

Blockchain Applications in Supply Chain
5727
The distributed-nature technology of Blockchain has disrupted many industries, with its uses and blockchain applications in supply chain leading to in
Read More

by Radhika Maloo

28 Aug 2023

Applications of Blockchain in Healthcare Industry
6636
After taking the finance and business sector by storm, Blockchain applications in healthcare are now all set to radicalize the healthcare industry. Ev
Read More

by Shubham Chakraborty

23 Aug 2023

What is Ripple Blockchain? Everything You Need to Know in 2024
7250
Ripple is a popular name in the tech industry. And Ripple blockchain has created a lot of buzzes. We all know how blockchain is transforming the indus
Read More

by Mayank Sahu

21 Aug 2023

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon