Ever tried to use blockchain to tokenise your supply chain? Find out here, how to use blockchain features, map them to a business data layer – and ultimately, operate more cost efficiently!
Following topics will be discussed in this article:

Table of contents

Blockchain data models

Using blockchain and Bitcoin does not always mean that operational costs are being cut, and that data is being stored efficiently. In order to avoid doing mistakes on how to use blockchain to tokenise your supply chain, I will use the anecdote of a project that we developed for showcase purposes. It also included features that were intentionally made unscalable in order to be able to showcase various integrations of blockchain for business logic.
In fact, an example bad use of blockchain data models includes the High Score implementation that we have done in PacNEM. This implementation was intentionally using a less responsive dataset (NIS Transactions, with 2 Minutes completion time) in order to showcase the need for well-thought data models when using blockchain.
This implementation made use of Transactions on the NIS blockchain network to reflect high score entries of the game. This didn’t scale well. In fact, it only worked for about one month, period after which the high score was not queryable anymore, because there were too many transactions that were created on top and the network became too large for PacNEM to keep track of its’ own high score data.
When you make use of blockchain, it is important to model your data carefully. If you are going to use any blockchain datasets to store data related to your software, it is recommended that you know about scaling characteristics of the underlying dataset, that you understand its’ representation on the network and also that you understand its’ availability characteristics.
Common characteristics of scalability can be questioned with the following:

  • Is a record of this dataset persisted across all network nodes?
  • Is a record of this dataset available for retrieval by API?
  • How many requests to the API does it need to retrieve a collection of this dataset?
  • How many requests to the API does it need to retrieve a singular entity of this dataset?
  • What is the response time (e.g.: in milliseconds) for one API request on the network?
  • Is this record related to sensitive information? Never send those over a network of any type.

Ask yourself these questions before any of your business layer data gets stored on a blockchain network. It will save you a lot of time.

How to use blockchain in your supply chain?

In terms of finding an implementation of a blockchain that will fit for how to use blockchain to tokenise your supply chain, I propose to consider Symbol from NEM.
As to what exactly needs to be done to map supply chain business logic to a blockchain project, it will defer from one distributed ledger technology to the other. As such, illustrating how this can be done with Symbol from NEM is my personal opinion, other contributors and participants may advise or require to do this differently.

Mapping your business logic

One of the important steps in integrating blockchain in your supply chain will be to define mappings for your business logic that will be represented by one or more entities on said blockchain implementation.
As an example, let us look at how accounts on Symbol from NEM can be mapped to Identities for your business. It is in fact quite simple, as we will be using the symbol-hd-wallets library available at NPM.

In the above source code, we represent two identities in the form of address on the network. These addresses are unlocked using a 24-words mnemonic passphrase, which should be treated with care and stored carefully.
The idea is that each identity actually owns a multitude of addresses through just one pass phrase.
Another interesting example would be to have a look at how mosaics on Symbol from NEM can be mapped to Products for your business. We will be using the symbol-sdk, which is available at NPM.
Mosaics on Symbol are digital assets for which ownership is managed by the blockchain network. Restrictions and metadata can be attached to mosaics such as to apply more precise representations of your products.
Following source code snippet creates a new account for Alice and signs a contract with this account’s private key. The resulting transaction bytes can be sent to any Symbol network node of the chosen network.
Note: The following source code mentions a networkHash of 57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6. This value is an example value and identifies a specific network running the Symbol from NEM software.

Event streaming with blockchain

The term “streaming” is defined as continuous, never-ending data streams with no specific beginning or end, which offer a constant feed of data that can be used/acted upon without needing to be downloaded first.
A simple analogy is how water flows through a river or creek. The streams come from various sources, in varying speed and volumes and flow into a single, continuous, combined stream.
Similarly, data streams are created by multiple types of sources, in various formats and volumes. From software, networking devices, and server log files, to website activity, location data, and app activity they can all be aggregated to seamlessly gather real-time information and analytics from one source of truth.
How does this combine with blockchain, you are asking? – Blockchain technology uses cryptography to sign data and publish proofs on a peers network. Events that are generated from a blockchain network can be of multiple formats: most blockchain network, as tells the name, will produce blocks of data – but also validate transactions and/or change account states and/or change token states.
An example? Yes, it is time. Let us take a look at Symbol from NEM which publishes Merkle Proofs about account state changes – basically, anytime anything would happen to the account of Alice, a new merkle hash will be created that is verifiable to make sure about the integrity of the retrieved data.
Explaining the technical principles of Merkle Trees is done very well in this article and in the Whitepaper for Symbol from NEM. What we can take as granted in order to keep this article clear and concise is that merkle trees permit to verify the presence of entities without actually querying the collection [of all entities].
With that said, Symbol from NEM makes use of merkle trees and cryptographic hashes thereof to publish proofs about said state and/or state changes – be it relative to an account, a collection of tokens (mosaics), a namespace and/or a transaction on the network.
In our business logic mapping, we defined entity mappings for identities and for products. As such, we will be interested only in state changes related to those mappings: Accounts and Mosaics.
The following source code snippet illustrates how to connect to websocket channels related to Symbol from NEM entities such as blocks, accounts or tokens (mosaics). As an example, we will be reading incoming blocks from a testnet node. You can replace the endpoint URL with one that you own.

It is quite simple isn’t it? This small snippet of source code let’s your software know about new blocks that are added to the blockchain network. This is where you would start to find out about potential state changes for your event mappings.
Obviously, the above snippets are not enough to tokenise your supply chain, but should give you a hint at how supply chains can be combined with blockchain to operate more cost-efficiently – an in-depth integration of supply chain tokenization can be found in UsingBlockchain/BlockSnippets with the MiniSupplyChain command.

Wrapping it all into digital contracts

To digitalise your complete supply chain, you will need much more than these few source code snippets, that is for sure. Nevertheless, in UsingBlockchain/BlockSnippets, we published a MiniSupplyChain command that is our minimum viable product for the digitalisation of your company products using blockchain.
Following the above statements, we implemented a MiniSupplyChain.tokenize() method which takes products information as arguments and registers new digital assets on a Symbol network:

                    
/**
* Tokenize a list of products.
*
* @param Product[] products The products that will be mapped with mosaics.
* @return AggregateTransaction The broadcastable signed transaction.
*/
public tokenize(
products: Product[],
): AggregateTransaction {

// – All transactions will be bundled in one contract
let transactions: Transaction[] = []

// – Iterate all products to be tokenized
for (let i = 0, m = products.length; i < m; i++) {

// – Create one mosaic per product
const innerTransactions = getMosaicCreationTransactions(
getAddress(this.identities.get(‘owner’)),
products[i].count
);
transactions = transactions.concat(innerTransactions)
}

// – Setup our supply chain tokenization digital contract.
// A digital contract consists in one or many transactions
// that are all executed together (atomically).

return getContract(transactions);
}

What is special about our source code above is that it defines a digital contract that can be signed right a way, or later when offline – which provides with maximum security when it comes to digital signature creation.
Also, transactions will all be executed in one contract such that if any of the inner transactions fails, the contract would fail altogether and leave no trace of execution on the blockchain.
Now that you have tokenized your products and backed up all sensitive information such as the mnemonic phrase of your identities and the mosaic ID of the created digital assets, we can continue by implementing a Sales operation which is one step ahead in the supply chain of our products.

                    
/**
* Sell a tokenized product to a *random* buyer.
*
* @param string sku The product SKU.
* @return SignedTransaction
*/
public sell(
sku: string
): AggregateTransaction {
// – Find product by SKU
const product = this.products.find((p, ix) => {
return p.sku === sku
})

// – Supply Chain Step #1: Send product to Transporter
const transport = getTransferTransaction(
getAddress(this.identities.get(‘transporter’)),
product.tokenId,
1
)

// – Supply Chain Step #2: Transport product to *random* customer
const delivery = getTransferTransaction(
getAddress(MnemonicPassPhrase.createRandom()),
product.tokenId,
1
)

// – Setup our supply chain sales tracking digital contract
// A digital contract consists in one or many transactions
// that are all executed together (atomically).

return getContract([

// – Sign off #1: The company owner is whom signs off for step #1
transport.toAggregate(getSigner(this.identities.get(‘owner’)).publicAccount),

// – Sign off #2: The logistics transporter is whom signs off for step #2
delivery.toAggregate(getSigner(this.identities.get(‘transporter’)).publicAccount)

]);
}

That one is a bit harder to grasp at first glance, I would give you that. The reason is that multiple participants must sign the digital contract this time.
In fact, doing a complete sales operation in our hypothetical supply chain digitalisation means that we have to ship the product from our Manufacture all the way to the customer. But our company does not actually execute on the delivery.
In our showcase, the delivery is executed by a transporter [company]. So what this means, is that when we sell one product, we first send it to the transporter, then only will the transporter send it to the customer, as a second step.
For the contract to be valid means that the company owner and the transporter agree to the terms of delivery, as they both effectively have to provide with a digital signature of the digital contract.
The full source code for this supply chain tokenization showcase can be found in: UsingBlockchain/BlockSnippets MiniSupplyChain Command.

Book a call with a UBC blockchain expert for assistance or guidance on integrating the technology in your business.

We hope that this article was insightful for you and are looking forward to any feedback and messages. Please share your thoughts in the comments section below!

Disclaimer

This website may contain information about financial firms, employees of such firms, and/or their products and services such as real estate, stocks, bonds, and other types of investments. While this website may intend - as the author deem necessary - to provide information on financial matters and investments, such information or references should not be construed or interpreted as investment advice or viewed as an endorsement.