Creating a Useful NFT

Date: 2023-05-22

Source: https://craigwright.net/blog/bitcoin-blockchain-tech/creating-a-useful-nft


Download the relevant code as a ZIP/RAR file here.

The concept of a non-fungible token (NFT) has been used to create items associated with speculation and money laundering (Wilson et al., 2022). Yet, as I hope to demonstrate in this post, the same technology can significantly simplify the deployment of many existing applications, including in accounting and trade. In today’s example, we will go through some of the steps of creating a bill of lading (BoL) that links the identities of corporations to a series of invoices and uses NFTs to reference and trade the ownership certificates associated with goods and commodities.

In this example, LDAP is utilised to search and index the corporate names and the identity keys that are associated with them through a X.509 certificate signed by a certificate authority (CA). Note that we will start going through the example section by section, and as I do so, the code will be linked in files that can be downloaded. The images of the Google co-lab environment will connect to the source code. The various areas will require updating so the code can incorporate all the changes needed for the implementation in existing systems. Where necessary, it will be left to the person downloading the files to implement any other libraries used in the local application with which this is integrated.

Note that I have made multiple assumptions concerning any existing systems this will be run with. Likewise, accessing keys from LDAP servers and converting them to BSV addresses, using TXIDs for bill of lading numbers, etc., involves detailed knowledge of existing systems and complex cryptography operations, which must be customised based on the individual needs of the business implementing the solution.

Code 1 – Initial Framework

From here, we need to consider the connection to the LDAP server. The connection can be made using a variety of authentication techniques, and may involve a username and password, as shown in the figure below (Code 2). Alternatively, a connection can be based on a digital certificate or token-based authentication methodology (Code 3).

Code 2 – LDAP Connections

Not all LDAP servers support certificate-based authentication using the Simple Authentication and Security Layer (SASL) External mechanism (Zeilenga & Melnikov, 2006), which makes the server determine the authorization identity based on the client’s presented certificate during a successful SSL/TLS handshake. Alternatively, other forms of certificate-based authentication may be utilised. For example, in a later post, I will demonstrate how to use a Bitcoin address as a tokenised form of authentication, which is beyond the scope of this post.

Code 3 – Certificate-Based LDAP Connections

Creating NFTs For Our Goods

Non-fungible token (NFT) systems do not need to represent exchange items but can be a means of creating the product marketplace and item references that were referred to in the original release of Bitcoin under the marketplace. The bill of lading example provided (Code 4) is minted to an NFT (Code 5) that can be transferred as goods are moved or even if the goods are sold while in transit.

Code 4 – Bill of Lading Class

I will get around to documenting the other aspects of the NFT referenced. But first of all, I will note that we can create a simple transferable bill of lading token using the information that we are already talking about. Also, note that I am using a single sat and haven’t accounted for mining fees or other things that must be considered in a real-world implementation. The system would be minted by the individuals creating the goods, and the certificate of the goods acts as an ownership certificate that is transferred and minted into the bill of lading contract document.

Code 5 – Bill of Lading NFT

With all of this information, we can now produce the ‘GoodNFT’ token that the manufacturer of goods will use to create a token application. It is important to note that for the from_nft method, I have used a mock utxo_from_nft function that returns a simulated unspent transaction output (UTXO). When you implement such a function in a real-world shipping application, you will replace it with your function that queries the UTXO set for a UTXO representing the NFT. In real-world coding, it will also be necessary to add error handling.

Code 6 –NFT representing an ownership certificate attached to goods

Note that the information used can be extended. I have created a simple set of definitions in data dictionaries that can go into more detail, including serial numbers, if required. The distributed hash table (DHT) link could also provide additional information that references the particular item. One area, such as marks and numbers, can be extended to include individual identifiers for each item. An example would be a value referencing a particular phone if multiple phones were sold.

Implementing Tokens in Salesforce

In this example, I’m not going into all the details of how to make a wallet. As I go through examples each week, the information I provide will gradually result in enough information to do each stage, but there is only so much one can do at once. Additionally, while I would like to see other methodologies, including key-value databases, we will now use widely accepted methods when accessing a Bitcoin (BSV) node, including libraries such as bsv or moneybutton/bsv.

There are many methodologies for getting transactions, so I will not address them in this post. I shall, in later posts, but for now, I will say it’s mainly a placeholder.

Code 7 – Load the NFT to SalesForce

Next, we will start adding code to handle the signatures from each party involved in the bill of lading.

Code 8 – The Bill of Lading Needs to Be Signed

We can then start implementing the signing code.

Code 9 – Signing the Bill of Lading

For the next part, I will assume that we have already received a raw transaction saved as a binary file, transaction.bin. This is read as a byte vector and then parses the byte vector into a Bitcoin (BSV) transaction.

Code 10 – A VISUAL STUDIO C++ File to Read the Code into Text

Overall, there are multiple steps involved in creating such a system. First, developing a system that monitors the network or engages in a simplified payment verification (SPV) exchange between individuals will be necessary. Then, over the coming weeks and months, there will be a document of a complete wallet solution that can be built using all of this. The idea here is to slowly teach you how to create a system that will mint a product from a producer and attribute an NFT ownership certificate against it. In doing so, I will start documenting how to create a proper SPV wallet application that can be used in accepting headers produced by the miners (aka nodes) on the network, and how it can be implemented with Bitcoin in creating real-world solutions.

One example we could derive from here is to take the file saved in “Code 10” and send it to an EDI application. But, like all coders, I’m lazy. Using the GoodNFT I have just designed, we will take the NFT information we have passed and send it to an EDI Ship Notice/Manifest document. For those who don’t know, the pyx12 library can be used to create an EDI 856 document. EDI has strict standards. So, it will be essential to ensure that when we create an EDI 856 document with the data from our GoodNFT, we map all the values correctly. Doing so would assume that the information from the source has been entered correctly and the manufacturer follows standards.

In the EDI 856 document example shown below, I’m assuming that the block timestamp and transaction details reference the time of the settlement in the transaction. I heard of an average settlement time of ten minutes for real-world applications. So, while individual transaction times could be linked to NTP, this is sufficient for what I’m providing for free.

Code 11 – EDI from Bitcoin

This information allows us to create invoices and purchase orders within Salesforce (Code 12).

Code 12 – Back to Salesforce

But, that is all I’m doing for tonight. So, to finish up, I will quickly explain a bill of lading and note the various requirements of such a document. Yet, as you may have guessed from the EDI section, it remains important to note that this is a complex area that requires specialist knowledge and more than just coding.

Explanations of a Bill of Lading

A bill of lading (B/L) is a legal document used in international trade to acknowledge the receipt of goods and provide details about the shipment. The standard fields commonly found in a bill of lading include the following:

These are the commonly used fields in a Bill of Lading, but the exact format and lots may vary depending on the specific requirements of the shipping company or trade practices in different countries. Note that this blog post is not a definitive solution for all possible outcomes. Moreover, some of the areas in a goods description included in our GoodNFT may be extended to include the following:

Also, note that I haven’t included any customs details, which would need to be completed in the final code.

Download the relevant code as a ZIP/RAR file here.

References

Wilson, K. B., Karg, A., & Ghaderi, H. (2022). Prospecting non-fungible tokens in the digital economy: Stakeholders and ecosystem, risk and opportunity. Business Horizons, 65(5), 657–670. Https://doi.org/10.1016/j.bushor.2021.10.007

Zeilenga, K., & Melnikov, A. (2006). Simple Authentication and Security Layer (SASL) (Request for Comments RFC 4422). Internet Engineering Task Force. https://doi.org/10.17487/RFC4422

Extracted Insights (20 total, showing top 10)

R7 The concept of a non-fungible token (NFT) has been used to create items associated with speculation and money laundering (Wilson et al., 2022). Yet, as I hope to demonstrate in this post, the same tec...
R7 With all of this information, we can now produce the ‘GoodNFT’ token that the manufacturer of goods will use to create a token application. It is important to note that for the from_nft method, I have...
R7 For the next part, I will assume that we have already received a raw transaction saved as a binary file, transaction.bin. This is read as a byte vector and then parses the byte vector into a Bitcoin (...
R6 In this example, LDAP is utilised to search and index the corporate names and the identity keys that are associated with them through a X.509 certificate signed by a certificate authority (CA). Note t...
R6 From here, we need to consider the connection to the LDAP server. The connection can be made using a variety of authentication techniques, and may involve a username and password, as shown in the figu...
R6 Not all LDAP servers support certificate-based authentication using the Simple Authentication and Security Layer (SASL) External mechanism (Zeilenga & Melnikov, 2006), which makes the server deter...
R6 Overall, there are multiple steps involved in creating such a system. First, developing a system that monitors the network or engages in a simplified payment verification (SPV) exchange between indivi...
R5 Note that I have made multiple assumptions concerning any existing systems this will be run with. Likewise, accessing keys from LDAP servers and converting them to BSV addresses, using TXIDs for bill ...
R5 Non-fungible token (NFT) systems do not need to represent exchange items but can be a means of creating the product marketplace and item references that were referred to in the original release of Bit...
R5 I will get around to documenting the other aspects of the NFT referenced. But first of all, I will note that we can create a simple transferable bill of lading token using the information that we are ...

+ 10 more insights


← Back to archive