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:
- Ganache, for starting a personal test Ethereum blockchain on your machine.
- Truffle, for managing the lifecycle of smart contracts and the artifacts your contracts need.
- Drizzle, a collection of front-end libraries for standardizing Dapp front-ends.
Each tool has its own features and functionality summarized below, for full details read the Truffle documentation.
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.
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.
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.
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.
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.
The Truffle suite provides a testing suite for your Dapps where you can write your tests in two ways:
- In Solidity for testing token focussed functionality such as balance transfers.
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.
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.