Reader small image

You're reading from  Hyperledger Cookbook

Product typeBook
Published inApr 2019
Reading LevelBeginner
PublisherPackt
ISBN-139781789534887
Edition1st Edition
Languages
Concepts
Right arrow
Authors (3):
Xun (Brian) Wu
Xun (Brian) Wu
author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

Chuanfeng Zhang
Chuanfeng Zhang
author image
Chuanfeng Zhang

Chuanfeng Zhang is enthusiastic and passionate about technologies and trading and data analysis, with 20 years' experience in both the technology and finance sectors. He has worked at top investment banks and technology firms including Goldman Sachs, Credit Suisse, and IBM. He has led, designed, and successfully developed many enterprise-scale systems with diverse architectures for algorithmic trading, order management, risk management, business intelligence, and more.
Read more about Chuanfeng Zhang

Zhibin (Andrew) Zhang
Zhibin (Andrew) Zhang
author image
Zhibin (Andrew) Zhang

Andrew Zhang is an IBM Watson Cloud Advocate. He has many years of experience in cloud platforms, big data analytics, and machine learning. He works with start-ups and enterprise clients in the government, education, healthcare, and life science industries. His current interests are in embedding AI and blockchain open source technologies for consumer and enterprise applications. In his spare time, Andrew enjoys reading, traveling, and spending time with his family and friends.
Read more about Zhibin (Andrew) Zhang

View More author details
Right arrow

Working with Hyperledger Sawtooth

Hyperledger Sawtooth is an enterprise blockchain platform with which to build, deploy, and run decentralized applications (dApps) with a highly modular architecture. Hyperledger Sawtooth originated from Intel and is currently an open source project under the Linux Foundation.

The main principles behind Hyperledger Sawtooth are keeping a distributed ledger, distributed data storage, a modular architecture, and a decentralized consensus; these makes smart contracts safe, particularly for enterprise organizations.

This chapter will cover the following recipes:

  • Installing Hyperledger Sawtooth
  • Configuring Hyperledger Sawtooth
  • Designing a namespace and address
  • Implementing a transaction family
  • Building a transaction processor
  • Granting permission on the Sawtooth network
  • Developing client applications with the Sawtooth REST API and SDK
...

Introduction

Hyperledger Sawtooth is an enterprise blockchain platform for building distributed ledger applications and private and permissioned networks that do not require centralized authority or central decision-making services. It simplifies the development of blockchain applications by separating the core system from the application domain with multi-language support.

Sawtooth is open, flexible, and extensible, allowing you to build new services such as membership, ACL, Crypto assets, and data confidentiality. Sawtooth also has a modular architecture, meaning enterprises can choose and customize transaction rules, permissioning, and plug consensus algorithms based on the organization's requirements.

The features offered by Hyperledger Sawtooth are the following:

  • A truly distributed DLT: The Hyperledger Sawtooth blockchain network is made up of validator nodes. The...

Installing Hyperledger Sawtooth

This recipe will show you how to communicate with Amazon AWS using PuTTy, how to install and launch the Hyperledger Sawtooth network, and how to set up Python for developing Sawtooth applications on AWS. We will also use the Sawtooth command line to test and verify the installed Sawtooth network on AWS.

Getting ready

Configuring Hyperledger Sawtooth

This recipe will demonstrate how to configure the Hyperledger Sawtooth validator, the REST API, and much more.

How to do it...

Execute the following steps to configure Hyperledger Sawtooth

  1. The Sawtooth validator default configuration file can be found at /etc/sawtooth/validator.toml. To set the network bind port and other component bind ports, use the following command:
bind = [
"network:tcp://127.0.0.1:8800",
"component:tcp://127.0.0.1:4004"
]
  1. To set the peer discovery type and peer validator nodes, enter the following:
    peering = "static"
peers = ["tcp://127.0.0.1:8801"]
  1. You can find the Sawtooth REST API service default configurations...

Designing a namespace and address

In this recipe, we will guide you through the main steps of building a Sawtooth transaction family with a case study that implements a marketplace designed to keep track of the owner of a house. The sample application is developed with the Sawtooth Python SDK and uses the Sawtooth XO transaction family as a template. The full code is available with the source code files that come with this book.

The main focus of this case study is on demonstrating how to develop a Sawtooth application as a proof of concept. In a real production environment, state access control, data encryption, confidentiality, and security would be customized based on the different commercial requirements.

The simple business cases for this sample marketplace are creating records to keep track of the owner of a house and transferring the house from one owner to another:

...

Implementing a transaction family

After the namespace and address scheme is defined for the transaction family, the state, transaction, and payload encoding scheme can be defined.

How to do it...

To define the state, you should analyze the data requirements for your organization and follow an appropriate modeling process to define the semantic data model for the system. For example, you could use entity-relationship modeling to represent conceptual data logic in your enterprise. In our example, the state is as follows:

This can be explained as follows:

  • House APN (Key): The Assessor Parcel Number (APN) for a house is a unique number assigned to each parcel of land by a county tax assessor. The APN is based on formatting...

Building a transaction processor

Sawtooth simplifies the development of applications by separating the core system from the application domain. Application developers only need to focus on implementing their business logic for the enterprise using the transaction processor, with the language of their choice, without needing to know the underlying details of the Sawtooth core system.

Getting ready

In this recipe, we will go through a step-by-step guide to implement a transaction processor, a smart contract, in our example transaction family using the Sawtooth Python SDK.

Python Sawtooth SDK: The Python SDK is installed automatically when you install Hyperledger Sawtooth on AWS. You can import the SDK in Python to verify Python...

Granting permissions on the Sawtooth network

In this recipe, we will cover how to configure on-chain and off-chain permissions in the Hyperledger Sawtooth network.

How to do it...

To configure off-chain permissions, follow these steps:

  1. In the validator configuration file present in /etc/sawtooth/validator.toml, update it with the following lines to set the transactor permission for the marketplace example:
[permissions]
transactor = "policy.toml"
"transactor.transaction_signer" = "policy.toml"
  1. In the policy file present in /etc/sawtooth/policy/policy.toml, update the following lines:
PERMIT_KEY 021c9a9d3155d15e5c834b29e995d4f3fb7da54e6aa0b1f43ce753bc77cce36138
DENY_KEY 02b56f55681409e412fb57b91ba02e16760419d202db40690a6d841e879ec11ee7...

Developing client applications with the Sawtooth REST API and SDK

Hyperledger Sawtooth provides a pragmatic REST API for clients to interact with a validator using common HTTP standards. There are a many ways to make a REST API request, but the process to build a transaction, batch, encode a payload, and submit them to validator nodes is not easy. Hyperledger Sawtooth provides several SDKs for different languages, such as Python, Go, Java, and JavaScript, to greatly simplify the process of developing client applications to interact with the Sawtooth network.

In this recipe, we will build a client application for our example with the Sawtooth Python SDK and follow the Sawtooth XO transaction family as a template. The full source code for the example is available at GitHub. The basic flow to submit a transaction is shown in the following diagram:

Transaction submission flow
...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hyperledger Cookbook
Published in: Apr 2019Publisher: PacktISBN-13: 9781789534887
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

author image
Chuanfeng Zhang

Chuanfeng Zhang is enthusiastic and passionate about technologies and trading and data analysis, with 20 years' experience in both the technology and finance sectors. He has worked at top investment banks and technology firms including Goldman Sachs, Credit Suisse, and IBM. He has led, designed, and successfully developed many enterprise-scale systems with diverse architectures for algorithmic trading, order management, risk management, business intelligence, and more.
Read more about Chuanfeng Zhang

author image
Zhibin (Andrew) Zhang

Andrew Zhang is an IBM Watson Cloud Advocate. He has many years of experience in cloud platforms, big data analytics, and machine learning. He works with start-ups and enterprise clients in the government, education, healthcare, and life science industries. His current interests are in embedding AI and blockchain open source technologies for consumer and enterprise applications. In his spare time, Andrew enjoys reading, traveling, and spending time with his family and friends.
Read more about Zhibin (Andrew) Zhang