Deep dive into Hyperledger Sawtooth transaction families

Dushan Devinda
Chain Analytica
Published in
3 min readApr 7, 2020

Transaction families play a major role in the Sawtooth framework. It acts as a validator in between blockchain client and blockchain. It has the liberty of selecting which transaction goes to the blockchain and which transaction does not go into the blockchain. Instructions to select the relevant transactions are defined in the transaction family. Unlike some other blockchain frameworks, Sawtooth has given the freedom to developers to define their own transaction families according to their own set of rules. But by default, the Sawtooth has given some transaction families that can be added to any blockchain network.

Default transaction families

  • block_info
  • sawtooth_identity
  • intkey
  • sawtooth_validator_registry
  • settings-tp
  • smallbank
  • xo

Each transaction family fulfills different purposes. As an example, if we take the “xo” transaction family, it was developed to play the simple board game tic-tac-toe. All the rules for the tic tac toe game are defined in the app. Every approved move will be added to the blockchain while illegal moves will not be added to the blockchain.

source: https://developer.ibm.com/

Like I mentioned previously, if you want to build your own transaction family with your rules set, then you can do it by simply creating a transaction processor. Mainly a transaction processor has two components. A processor class and a handler class. First, we must provide an entry point for the transaction processor. At the entry point, you have to create a transactionprocessor instance. When creating an instance, you must provide an address that you need to register your transaction. Remember that at this point you cant give HTTP address. You have to provide TCP address. So if you are running you Sawtooth using default docker-compose file, then your TCP port will be 4004.

As you can see, you need to create a handler first to run the transaction processor. One of the main and easiest ways to create a handler is using the apply the method in TransactionHandler from Sawtooth-SDK. TransactionHandler is a class defined in sawtooth SDK with an apply abstract method. The default constructor of the TransactionHandler class accepts three arguments. Those are ‘transactionFamilyName’ — name of the transaction family that this handler can process, ‘version’ — the versions of the transaction family that this handler can process and ‘namespaces’ — a list containing all of the handler’s namespaces.

For the namespace you must provide three-byte address prefix and that must be calculated in the same way within a particular transaction family. One of the main way to create a namespace is hash the family name and slice the first six hex characters. In javascript, you can create your namespace like given below.

Just like that you can simply create your own transaction processor and play with it.

--

--