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:
- 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.
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.
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:
- In Solidity for testing token focussed functionality such as balance transfers.
- In JavaScript for testing how a user interacts with your Dapp and the underlying smart contracts.
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.
- Kauri original title: Truffle 101 - Development Tools for Smart Contracts
- Kauri original link: https://kauri.io/truffle-101-development-tools-for-smart-contracts/2b10c835fe4d463f909915bd75597d6b/a
- Kauri original author: Chris Ward (@chrischinchilla)
- Kauri original Publication date: 2018-12-04
- Kauri original tags: none
- Kauri original hash: QmR6jDx2u81TSNVjTkuTqn2UsWJYzpf5vdv4RjwPewq5Te
- Kauri original checkpoint: QmRS3wCLX2MRi62bg9NTM89qNkgm3XjpKXciLvCKAr1f1g