Truffle 101 - Development Tools for Smart Contracts

Truffle is a suite of tools to help Dapp developers build, deploy and manage their applications. The three tools provide a stack for managing the development lifecycle of an application similar to those you may have used with other languages and frameworks. These are:

Each tool has its own features and functionality summarized below, for full details read the Truffle documentation.

Ganache

Available as a cross-platform GUI application or command line tool (ganache-cli), Ganache starts a local and personal Ethereum blockchain on your machine useful for testing, and other aspects of the Truffle Suite. Alongside this are tabs for details on settings, accounts, blocks, transactions, and logs.

The Ganache Interface

Truffle

Truffle packs a lot of features that follow familiar patterns and paradigms. I'll highlight a couple in this guide, and you can find a full guide in the Truffle documentation.

Truffle Boxes

Similar to Vagrant machines, Docker containers, or Yeoman generators, Truffle boxes contain pre-defined smart contract and other dependencies for Dapps. Even better each box ships with specific instructions on how to get started with it.

Compiling

Truffle's truffle compile command adds to the solidity compilation process by only compiling changes to contracts located in the contracts folder and placing the resulting artifacts into a build folder ready for use in Dapps.

Migrations

Unlike migrations from other web frameworks (such as Ruby on Rails), Truffle migrations are settings to help you deploy contracts between development and production networks.

Migrations are .js files inside the migrations folder and run them with the truffle migrate command. Each migration file defines artifacts you need, contracts to deploy and the order the steps need to run in. You need an initial contracts/Migrations.sol contract that defines an interface for future migrations and this is created when you create a Truffle project.

Tests

The Truffle suite provides a testing suite for your Dapps where you can write your tests in two ways:

Whichever language(s) you use, you place all your tests inside the test folder and run them with the truffle test command. This command runs your tests and displays the success or failure results.

Debug

Debugging is an essential part of any development process, and Truffle's debug command helps you investigate what happened in the execution that lead to a transaction. The command opens an interface in your terminal that is similar to other debuggers that lets you step through the code.

Interacting with a contract

Similar to consoles provided by Ruby and Python, Truffle lets you test potential interactions with your contracts via the truffle console command and receive instant feedback.

Drizzle

Based on popular JavaScript framework, Redux, Drizzle is a collection of reactive libraries to build Dapp front-ends that stay in sync with your contract and transaction data. It borrows a lot of concepts from frameworks such as React and brings them to the Web3 word ecosystem.