Digital twin tokens: functions

Living Roots
4 min readJun 4, 2022

--

In this article we will describe the operation a user can run with the blockchain to interact with the tokens and create stock of products and documents. We will describe different API, libraries and websites in open access applied. The Blockfrost API will help us to perform query functions to retrieve information. The Cardano serialisation library aka Wallet connector will allow us to retrieve information included in the wallet but also to perform transactions. Finally an external minting platform Minterr.io will help us to mint products and documents.

1. Store a product stock and document on the blockchain

Inputs: Form with product information including, but not limited to: name, product, quantity, description, owner, document(s) and picture.

Outputs: Product with a unique name (concatenation of the hex policyID and hex asset ID) and unique minting transaction.

Product tokenization is a way to save product data directly on the blockchain. Once the form is filled by using standardised information and can refer to another token of any type of document. During this step, product information is saved in a JSON structure then a digital signature (policyID) is applied to sign the token on the blockchain and preserve it from any modification.This form is sent to a minting platform that will submit the minting transaction to the node and mint tokens.The quantity of token minted will represent the maximum stock of a product to follow the availability of a token along the supply chain.

2. Search for a product saved on the blockchain and the traceability information

Inputs: Product PolicyID, product name (concatenation of the hex policyID and hex asset ID) or one of the product transaction

Outputs: Product information and documents associated, product owner and traceability information ( Receiver Address, Sender Address, Metadata label and content ).

Blockchain node queries are used to retrieve information about Cardano tokens. By using this query we can return the whole product information integrity from the production site to the consumer. To find a product the user needs to input the product using the asset set of functions. (https://cardano-mainnet.blockfrost.io/api/v0/assets/). Blockfrost will return the asset associated with the product information and picture associated. By reading the metadata bound to a document, blockfrost will return the information associated.

Given the token or transaction hash Blockfrost can retrieve all the transactions associated with a product.

The blocktime gives the information about when the transaction was to proceed. If the transaction follow the exchange of the physical product in a timely manner them the this blocktime will give the information about when the product was exchanged ( by using the function new Date(blockTime*1000).

The function txs/ {transaction_hash}/utxos will return a result x that contains the product/documents names and amount that was sent.

The number of tokens exchanged is stored in outputs[0].amount then we can separate if the token is ADA, products or documents and look for the information using the 2) function.

Using x.inputs[0].address and x.ouputs[0].address will return the sender and receiver address. To identify this address we return the staking address using the addresses/{address} API call.

We will txs/tx/metadata we will parse the label with the function with x.label and x.json_metadata.msg

With this information we can order all the transactions of a digital twin then retrieve the traceability of this product. This traceability will give the position of any product in the supply chain in function of the time,

This transaction information can also be used to verify which products have transited in a stakeholder’s stock.

3. Search a wallet content

Inputs: Cardano Wallet (Nami, CCVault, Flint)

Outputs: Currencies, Products, Certification

From the wallet utxos this.API.getUtxos() the wallet connector library will return ADA amount, product name, policy,amount and document name, policy and amount that belong to the wallet.

From this information we can call blockfrost to display the product/ document picture and information and all the information previously mentioned

4. Submit transaction on the blockchain

Stock transfer

Inputs: Address receiver and address sender. Product/Document/Currencies name, quantity, Metadata Label and content.

Outputs: Transaction fee and transaction id

The Wallet connector can be used to submit transactions directly to the node. The transaction includes Wallet address of the emitter and receiver(s), list of token names and quantities and the metadata label and content.

For that we create an instance of GeneralTransactionMetadata, then use the function insert() to add a label (BigNum) and a TransactionMetadatum (text).

Stakeholders can use this function to send stock of products directly to resellers. This transaction will conserve the quantity, information of the original token and add metadata associated to the transaction.

--

--

Living Roots

Join us to build an open source system for traceability, certification, asset trading for smallholders farmers.