How Blockchain Can Revolutionize Cannabis Traceability: Part 3

From seed to sale, traceability is critical for ensuring compliance and safety in the cannabis industry. Find out how blockchain technology can make it easier.

Shivek Sachdev
Coinmonks
Published in
9 min readApr 16, 2023

--

Welcome to the third part of my blog series on integrating blockchain with Cantrak (a seed-to-sale system) for cannabis traceability. If you missed the first two parts, feel free to check it out.

In this post, I will explain the basics of blockchain technology and the process of integrating it with Cantrak, using Polygon as the blockchain of choice. Additionally, I will discuss the advantages of using blockchain technology for cannabis traceability, particularly in the case of medical-grade cannabis. So, let’s dive into the exciting world of blockchain and cannabis traceability!

As the cannabis industry continues to grow, so does the need for transparency and traceability in the cultivation process. In order to meet this demand, many companies have turned to blockchain technology as a solution. In this blog post, I’ll share my experience integrating blockchain with Cantrak, a popular seed-to-sale system used by many cannabis companies in Thailand.

First, let’s start with the basics. Blockchain technology is a decentralized, digital ledger that records transactions in a secure and transparent way. Each block in the chain contains a cryptographic hash of the previous block, creating an immutable record that cannot be altered without consensus from the network. This makes blockchain ideal for tracking and tracing the movement of goods and data across the supply chain.

Now, when it comes to integrating blockchain with Cantrak, I considered several options, including Ethereum and Polygon. While Ethereum is the most popular blockchain for smart contracts, it can be costly in terms of gas fees. After weighing the pros and cons, I ultimately decided to use Polygon, which is a cheaper alternative that still serves the purpose of traceability for cannabis products.

Comparison between Ethereum and Polygon, Credit: pixelplex

The process of integrating blockchain with Cantrak was fairly straightforward. Cantrak’s data can be ingested or retrieved in real-time via an API, which allows for all the plant lots under cultivation to be easily tracked. Alternatively, the data can be exported as a CSV file, which can be easily read in using the standard Pandas library in Python. From there, the four main integration points from Cantrak were established: cultivation (grow), harvest, production, and sales.

Here’s the algorithm for each of the integration point.

Cultivation (Grow)

Input:
// Define input variables
license_number = [string] // license number of the cultivator
lot_number = [string] // unique identifier for the lot of plants
strain = [string] // strain name or ID
planted_date = [string] // date the plants were planted
growth_stage = [string] // current growth stage of the plants (e.g. vegetative, flowering)
number_of_plants = [integer] // number of plants in the lot

// Create cultivation record in Cantrak
cultivation_record = {
"license_number": license_number,
"lot_number": lot_number,
"strain": strain,
"planted_date": planted_date,
"growth_stage": growth_stage,
"number_of_plants": number_of_plants
}

// Write cultivation record to blockchain
hash_id = blockchain.write_data(cultivation_record)

Output:
// Print hash ID for confirmation
print("Cultivation record successfully written to blockchain with hash ID:", hash_id)

End

Algorithm 1: Upload Cultivation Lot Number to Blockchain

This algorithm is designed to upload the cultivation lot number to a blockchain. The inputs for this algorithm include a license number for the cultivator, a unique identifier for the lot of plants, the strain name or ID, the date the plants were planted, the current growth stage of the plants, and the number of plants in the lot.

First, the cultivation record is created in Cantrak, which is a system used for tracking cannabis cultivation. The record includes all of the input variables provided.

Next, the cultivation record is written to the blockchain, which is a distributed database that is secure and tamper-resistant. The blockchain ensures that the cultivation record cannot be altered or deleted once it has been written. A hash ID is generated to uniquely identify the cultivation record on the blockchain.

Finally, the hash ID is printed to confirm that the cultivation record has been successfully written to the blockchain. This algorithm can be used by cultivators to securely store their cultivation lot numbers and related information on the blockchain for verification purposes.

Harvest

Input:
// Define input variables
plant_lot_number = [string] // unique identifier for the plant lot
harvested_date = [string] // date the plants were harvested
strain = [string] // the specific strain of cannabis
num_plants_harvested = [int] // number of plants harvested
weight = [float] // weight of harvested material
item_harvested = [string] // the part of the plant that was harvested

// Create harvest record in Cantrak
harvest_record = {
"plant_lot_number": plant_lot_number,
"harvested_date": harvested_date,
"strain": strain,
"num_plants_harvested": num_plants_harvested,
"weight": weight,
"item_harvested": item_harvested
}

// Write harvest record to blockchain
hash_id = blockchain.write_data(harvest_record)

Output:
// Print hash ID for confirmation
print("Harvest record successfully written to blockchain with hash ID:", hash_id)

End

Algorithm 2: Upload Harvest Lot Number to Blockchain

This algorithm is designed to upload the harvest lot number to a blockchain. The inputs for this algorithm include a unique identifier for the plant lot, the date the plants were harvested, the specific strain of cannabis, the number of plants harvested, the weight of the harvested material, and the part of the plant that was harvested.

First, the harvest record is created in Cantrak, which is a system used for tracking cannabis cultivation. The record includes all of the input variables provided.

Next, the harvest record is written to the blockchain, which is a distributed database that is secure and tamper-resistant. The blockchain ensures that the harvest record cannot be altered or deleted once it has been written. A hash ID is generated to uniquely identify the harvest record on the blockchain.

Finally, the hash ID is printed to confirm that the harvest record has been successfully written to the blockchain. This algorithm can be used by cultivators to securely store their harvest lot numbers and related information on the blockchain for verification purposes.

Production (Drying)

Input:
// Define input variables
process_name = [string] // name of the process (e.g. drying, curing, extraction)
lot_number = [string] // unique identifier for the production lot
start_date = [string] // date the production process started
end_date = [string] // date the production process ended
strain = [string] // the specific strain of cannabis being produced
product_type = [string] // the type of product being produced (e.g. dried flower, oil, concentrate)
coa_doc_reference = [string] // address of uploaded coa document containing thc% & cbd%

// Create production lot record in Cantrak
production_lot_record = {
"process_name": process_name,
"lot_number": lot_number,
"start_date": start_date,
"end_date": end_date,
"strain": strain,
"product_type": product_type
“coa_doc_reference”: coa_doc_reference

}

// Write production lot record to blockchain
hash_id = blockchain.write_data(production_lot_record)

Output:
// Print hash ID for confirmation
print("Production lot record successfully written to blockchain with hash ID:", hash_id)

End

Algorithm 3: Upload Production Lot Number to Blockchain

This algorithm is designed to upload the production lot number to a blockchain. The inputs for this algorithm include the name of the process (e.g. drying, curing, extraction), a unique identifier for the production lot, the date the production process started, the date the production process ended, the specific strain of cannabis being produced, the type of product being produced, and the address of the uploaded Certificate of Analysis (COA) document containing THC% & CBD%.

First, the production lot record is created in Cantrak, which is a system used for tracking cannabis production. The record includes all of the input variables provided, including the reference to the COA document.

Next, the production lot record is written to the blockchain, which is a distributed database that is secure and tamper-resistant. The blockchain ensures that the production lot record cannot be altered or deleted once it has been written. A hash ID is generated to uniquely identify the production lot record on the blockchain.

Finally, the hash ID is printed to confirm that the production lot record has been successfully written to the blockchain. This algorithm can be used by cannabis producers to securely store their production lot numbers and related information on the blockchain for verification purposes. The uploaded COA document can also be easily accessed and verified through the COA document reference address provided in the production lot record.

Sales

Input:
// Define input variables
seller_license_number = [string] // license number of the seller
buyer_license_number = [string] // license number of the buyer
transaction_date = [string] // date the transaction occurred
product_type = [string] // the type of product being sold (e.g. dried flower, oil, concentrate)
product_quantity = [float] // quantity of product being sold
product_price = [float] // price of the product per unit
coa_doc_reference = [string] // address of uploaded coa document containing thc% & cbd%


// Create sales record in Cantrak
sales_record = {
"seller_license_number": seller_license_number,
"buyer_license_number": buyer_license_number,
"transaction_date": transaction_date,
"product_type": product_type,
"product_quantity": product_quantity,
"product_price": product_price
“coa_doc_reference”: coa_doc_reference

}

// Write sales record to blockchain
hash_id = blockchain.write_data(sales_record)

Output:
// Print hash ID for confirmation
print("Sales record successfully written to blockchain with hash ID:", hash_id)

End

Algorithm 4 is designed to upload sales data to a blockchain.

It takes several input variables, including the seller’s and buyer’s license numbers, the date of the transaction, the type and quantity of the product being sold, the price per unit, and a reference to a certificate of analysis (COA) document containing information about the product’s THC and CBD content.

The algorithm creates a sales record in Cantrak, a software system that is used to manage data related to cannabis cultivation, production, and sales. The sales record includes all the input variables, and is then written to the blockchain, generating a hash ID that serves as a unique identifier for the record.

Finally, the algorithm prints the hash ID for confirmation, indicating that the sales record has been successfully written to the blockchain.

On the technical side, writing to the blockchain was simple since it is set up as a service, also known as Blockchain-as-a-service. Developers only have to worry about making API calls and providing the correct request parameters. Each API call is represented by the four processes mentioned above. For each of these processes, an API is also available to retrieve the data by providing the transaction ID. It will then retrieve the data from the blockchain and return it to the user, along with the path to verify it on the Polygon Testnet Explorer. There’s also a revoke function available for all of the functions, which can be useful in case of any errors.

Let’s review the architecture once again:

So, what are the advantages of using blockchain technology for cannabis traceability, especially in medicine-grade cannabis?

First, blockchain can provide an immutable record of the entire supply chain, which can be used to ensure quality control and safety for the end user. It can also help prevent fraud and counterfeiting by tracking the movement of goods and preventing unauthorized access. Additionally, blockchain can streamline the auditing process and provide transparency for regulators and consumers alike. In the case of medicine-grade cannabis, blockchain can be a crucial tool in ensuring that patients receive safe and effective products.

In conclusion, the integration of blockchain technology with Cantrak is a step towards greater transparency and traceability in the cannabis industry. By leveraging the power of blockchain, we can ensure that cannabis products are safe, regulated, and meet the needs of both consumers and regulators. I hope this blog post has been informative and inspires others to explore the possibilities of blockchain for their own industries.

Stay tuned for the 4th and final blog in which we will showcase a full working prototype of this project, including a demonstration of how it can be used for tracking and tracing medicine-grade cannabis. We believe that the future of the cannabis industry lies in building more transparent and traceable supply chains, and we are excited to be a part of this journey towards a better future.

--

--

Shivek Sachdev
Coinmonks

Based in Bangkok, Thailand | Senior Consultant at Thai Informatic Systems