You might have definitely come across the word Hyperledger if you were looking for an enterprise-grade blockchain platform. Sawtooth is one of the popular projects under the Hyperledger consortium. Proposed by Intel in the year 2014, Hyperledger Sawtooth was initially designed for imparting an application that is safer for enterprise use. Later it joined with the Linux Foundation to form its present shape, making it a perfect solution for developing networks and distributed ledger technologies. Today many enterprises are using this incredible platform as it offers exactly what businesses want. The enterprises are given the adaptability to pick their own private rules.
Hyperledger Fabric is another project in the Hyperledger consortium. Here is a quick comparison of Fabric with Sawtooth.
Components of a Sawtooth Application
Sawtooth introduces the concept of transaction families. A transaction family can be considered as a decentralized application in Sawtooth World. A transaction family includes the following components:
- Client: module that handles the client logic of the application. The client is responsible for creating and signing transactions, combining those transactions into batches, and submitting them to the validator. This client can be a web application, mobile app, or even a command-line interface.
- Transaction processor: which defines the business logic of the application. The transaction processor is responsible for registering with the validator, handling transaction requests, and getting/setting state as needed. This is a smart contract equivalent in Sawtooth. A single transaction family may have more than one transaction processor.
- Data model: to store and retrieve data, usually referred to as a state.
We already saw that a Sawtooth application or a Transaction Family consists of a client, transaction processor and state. In our example, the client-side application is used to input and view text data. Then a transaction processor to handle writing and reading from the blockchain. The input text will be stored in a state. We will be using Docker to run this application.
Let’s see how it is structured in our sample application.
HelloWorld application is built with two parts,
- Transaction Processor – The helloworldprocessor directory contains the business logic. HelloWorldProcessor.js is a generic class for communicating with a validator and routing transaction processing requests to a registered handler. HelloWorldHandler.js is the handler class that contains the business logic for the particular family of transactions.
- The data is stored at a 70 hex digit address in the state.
Now let’s see how to run the HelloWorld application.
For that, you need certain prerequisites.
This example uses Docker Compose and Docker containers. For installing Docker Engine and Docker Compose, please follow instructions in the provided links:
Docker: Install Docker
Docker Compose: Install Docker Compose
NOTE: The recommended OS environment is Ubuntu Linux 18.04 LTS x64. Although other Linux distributions which support Docker should work.
Running the HelloWorld Application
1. Download or clone the HelloWorld application from GitHub link:
git clone https://github.com/Kerala-Blockchain-Academy/HelloWorld-Sawtooth.git
2. Open a command terminal and navigate to the directory where the HelloWorld-Sawtooth code is present.
3. Run the following command to start the HelloWorld application in the Sawtooth Docker environment.
sudo docker-compose up
4. Open a browser and go to http://localhost:3000
Now the user can enter the message in the textbox and click the Write button. It will store the data in state and you can retrieve the message by clicking Read button.
When the ‘Write’ button is clicked, the corresponding transactions are reflected in the validator window.
5. For viewing the block, transaction and state details, open a new window in the browser and give the following URLs.
a. Enter http://localhost:8008/blocks to view the block details.
b. Enter http://localhost:8008/transactions to view the transaction details.
c. Enter http://localhost:8008/state to view the state details.
6. Stopping the Sawtooth Environment
- To stop the validator and destroy the containers, press CTRL+C from the terminal where we originally ran docker-compose.yaml file.
- After all the containers have shut down, run the following docker-compose command:
sudo docker-compose down
c. To clean up all the docker containers, give the command.
sudo docker container prune
To conclude, Hyperledger Sawtooth is a modular enterprise blockchain platform that makes seamless the process of building, deploying, and running distributed ledgers. The design philosophy makes it enterprise safe and highly versatile. The network follows a novel consensus algorithm, Proof of Elapsed Time (PoET), that demands minimal resource consumption, making it feasible for any business size. But in our example we followed a simple developer mode(devmode) consensus, which is only for development and testing purposes.