Luxury Goods Receipt Tracker

Overview

It is common for sellers to show receipts when selling used luxury goods as it proves the authenticity of the product. On the other hand, it is more difficult to make fake receipts than find imitations. As such, the original receipt must be kept for selling used products in the future. However, holding or storing these receipts may be difficult because they are small, thin, and fragile. Moreover, the content on the receipt’s thermal paper can be easily damaged by heat or light.

If the receipt of a luxury item is kept in the blockchain, it will be kept safe permanently for future use. This tutorial describes the blockchain application (BApp) for maintaining and sending receipts on the Ground X blockchain platform, Klaytn. This allows users to issue electronic receipts using the platform Non-fungible Token (Non-fungible Token, NFT), KIP-17 so that they can be used to sell used products. The receipt is deployed to Klaytn for prolonged storage as long as the receipt owner keeps the private key. Therefore, the receipt can be safely and efficiently delivered to the new owner of the used luxury item, and, in turn, the new owner can also give the receipt when he sells the product.

One luxury item means one NFT (KIP-17) smart contract, and one receipt equals one NFT token. The management function can be added to each premium brand or store that sells the brand, but this tutorial assumes that there is only one store.

Here are the key functions of this application.

  1. Deployment of a new NFT smart contract = The prestige store registers a new luxury item (on the blockchain).

  2. Issuance of a new NFT token = The store sells a luxury item and issues an electronic receipt to the customer (on the blockchain).

  3. NFT token transmission = The receipt is sent (on the blockchain) when the customer sells his used product to another person.

The following system has been configured to implement the above functions.

  • Frontend: React

  • Backend: Node.js, caver-js

    • caver-js: KIP-17 Token Contract Deployment, Issuing Tokens, Sending Tokens

  • DB: MySQL

    • Save goods and receipts information for premium shops

  • KAS: Node API, Token History API

    • Use Klaytn Endpoint Node by Node API

    • Get Token Issuing History by Token History API

For inquires about this document or KAS, please visit KAS Developers Forum.

Getting Started

Installation

  • MySQL

    • In the code, both the ID and the password should be "root."

    • There are tables in the "test" DB. As such, create a "test" database if there is no existing DB.

For inquires about this document or KAS, please visit KAS Developers Forum.

Setting up Database

  • Two (2) tables (product and receipt) are required.

  • The "product" is a table for managing registered luxury goods.

  • The "receipt" is a table for managing issued receipts.

For inquires about this document or KAS, please visit KAS Developers Forum.

Copy Github Repository

  • Acquire the clone code from http://github.com/ground-x/kas-bapp-luxurytracker.

For inquires about this document or KAS, please visit KAS Developers Forum.

NPM Install

  • The "server.js" file on the root directory is for the back-end server function, while the "client" directory is for the reaction-based front-end function. This tutorial uses a JavaScript-based package manager for both front and back ends. As such, the "npm install" is required twice for the "root" and "client" directories, respectively.

For inquires about this document or KAS, please visit KAS Developers Forum.

Setting up KAS

  • Enter accessKeyId and secretAccessKey issued by KAS Console to client/src/Config.js.

Loading Your Account for the Tutorial

  • Since the transactions are directly submitted by the buyer and seller accounts, not having sufficient KLAY balance required for the transaction may result in an error on node.js as shown below. If you are running this tutorial on the Baobab testnet, you can obtain test KLAY at Faucet. If you are using the Cypress network, make sure that the seller and buyer accounts have sufficient KLAY.

Run

  • Execute the following commands in the root directory to carry out the back-end and front-end servers simultaneously. Executed programs can be checked at http://localhost:3000 (use another port number if the port is already in use).

Demo

For inquires about this document or KAS, please visit KAS Developers Forum.

Application Workflow

As described above, the key functions of BApp (example) are as follows.

  1. Deployment of a new NFT smart contract = The prestige store registers a new luxury item (on the blockchain).

  2. Issuance of a new NFT token = The store sells a luxury item and issues an electronic receipt to the customer (on the blockchain).

  3. NFT token transmission = The receipt is sent (on the blockchain) when the customer sells his used product to another person.

The front end sends the requests of application users (owners of premium stores and customers buying luxury goods) to the back-end server and shows the responses of the back-end server. For the front-end code, refer to code in Repository.

For inquires about this document or KAS, please visit KAS Developers Forum.

Register new luxury goods to a store’s product list

This code is used for registering new luxury goods (or deploying new contracts). In this tutorial, the owner of the prestige store registers new luxury goods directly to the blockchain. The owner of a prestige store needs his/her private key to deploy new smart contracts Deploy KIP-17 Contract with caver-js. In this example, the store owner’s private key is in the "req" object sent from a client to a server for simple implementation. In actual service development, it is recommended to keep the private key in the server.

The "./server.js" receives the request when "./client/src/components/ProductAdd.js" sends a request for sending a KIP-17 contract to Klaytn.

  1. Deploys (registers) a new KIP-17 contract (=new luxury item to sell)

  2. Stores the information of the deployed KIP-17 contract on the "product" table

This is the overall workflow.

  1. Register the store owner’s private key to the caver wallet (skip if already registered). - Front end

  2. Enter the information of the luxury item to register, and send the information to a back-end server. - Front end

  3. With the premium product’s information from the front end, deploy the KIP-17 contract. - Back end

  4. Store the information of the deployed KIP-17 contract (=new luxury item information) on the "product" table. - Back end

For inquires about this document or KAS, please visit KAS Developers Forum.

Issue a receipt to a customer when a luxury item is sold.

The owner of a prestige store starts to sell the luxury item if a new luxury item is registered to the blockchain by deploying a new smart contract. Once a customer buys a luxury item at the prestige store, a receipt will be issued to him/her. In this section, an electronic receipt will be issued to the customer on the blockchain.

Issuing the receipt to a customer on the blockchain means issuing a new token to the EOA of the customer in the KIP-17 smart contract created above. The store owner’s private key is required to Issue KIP-17 Token with caver-js. In this example, the store owner’s private key is in the "req" object sent from a client to a server for simple implementation. In the actual service development, it is recommended to keep the private key in the server.

The "./client/src/components/ReceiptAdd.js" sends a request, while "./server.js" receives the request.

  1. Issues a new KIP-17 token (=electronic receipt) to the customer

  2. Stores the information of the issued KIP-17 token on the "receipt" table

Here is the overall flow.

  1. Register the store owner’s private key to the caver wallet (skip if already registered). - Front end

  2. Enter the information of receipt to issue, and send the information of this receipt to the back-end server. - Front end

  3. Deploy the new KIP-17 token with the receipt information from the front end. - Back end

  4. Store the information of the issued KIP-17 token on the "receipt" table. - Back end

For inquires about this document or KAS, please visit KAS Developers Forum.

The seller of the used product sends a receipt that was issued by the store to the buyer.

The customer has used a purchased luxury item for a while and wants to sell it as a secondhand good this time. In this case, he also wants to send the receipt of the used product that was issued by the prestige store to the buyer. In this example of BApp, the seller of the used luxury item sends the original receipt to the buyer by sending the KIP-17 token to him.

In this example, the private key of the seller of the used luxury item is in the "req" object sent from a client to a server for simple implementation. In actual service development, it is recommended to keep the private key in the server.

The "./client/src/components/ReceiptSend.js" sends a request, while "./server.js" receives the request.

  1. The seller of a used luxury item sends a KIP-17 token (=receipt) to the buyer of the luxury item.

  2. The seller updates the information of the sent KIP-17 token on the "receipt" table.

This is the overall workflow.

  1. Register the private key of the seller of the luxury item to the caver wallet (skip if already registered). - Front end

  2. Send the buyer’s EOA to the back-end server when the seller of the used luxury item selects the receipt, and then enter the buyer’s EOA address. - Front end

  3. Send the KIP-17 token (receipt) to EOA of the buyer with the information from the front end. - Back end

  4. Update the information of the sent KIP-17 token on the "receipt" table. - Back end

Here is a detailed description of the receipt transmission process.

  • The seller of the used luxury item selects the Klaytn account address (=EOA) of the buyer and clicks the "Sell" button in BApp.

  • The "ReceiptSend.js" requests the back-end server to transfer the receipt from the seller to the buyer.

  • The back-end server (server.js) receives the request and updates the changed receipt ownership in the DB.

  • After updating the DB, the "server.js" requests a transaction from KAS to transfer the receipt from the seller to the buyer.

  • KAS executes this transaction, and the buyer receives a message for the receipt in his BApp.

  • The buyer can check if the receipt was successfully transferred (if receipt ownership was successfully updated on the blockchain) in Klaytnscope.

  • The buyer can check the transferred receipt and the ownership information anytime via the BApp.

For inquires about this document or KAS, please visit KAS Developers Forum.

The prestige store owner can load a list of issued receipts for one luxury item that he/she has sold, similar to loading a list of tokens issued by one KIP-17 contract. The list of receipts can be loaded using NFT Search Function of KAS Token History API using "contractAddr" in the "product" table. Only the REST API is used instead of "caver-js" following other sample codes above.

This is the overall workflow.

  1. Send the information of a luxury item to search for the list of receipts to a back-end server. - Front end

  2. Search for a corresponding contract address in the "product" table using the information of the luxury item (=luxury item ID) from the front end. - Back end

  3. Use NFT Search Function of the KAS Token History API with the searched contract address. - Back end

  4. Return the searched NFT token list to the front end. - Back end

For inquires about this document or KAS, please visit KAS Developers Forum.

Last updated

Was this helpful?