Create a Blockchain Asset Tracking System Using an ERC-721-Inspired Smart Contract

Introduction

Most asset tracking currently is done using something as basic and as insecure as a simple spreadsheet. In some cases, the most sophisticated approach may be a database with custom software as an interface.

Both are extremely insecure and can be altered by an attacker. Let us imagine a company that distributes high-end computer boards, not only sells them but leases them to different types of organizations for testing, marketing, and more. If an attacker wanted to modify the provenance or history of this leased asset, it would be as simple as accessing the database or spreadsheet and changing a simple record.

Using multi-ownable smart contracts would prevent this kind of behavior by default, and asset tracking with NFTs can give better control of where each asset is and with some extra code give a lot more information than what can be stored and managed in a simple spreadsheet.

Solving the Problem

This problem can be solved using blockchain technology:

  1. Create smart contracts that enable the company to track its assets transparently and reliably.
  2. Create a custom blockchain to solve this issue.

In this article, we are going to use the first approach, but the second one can be as, if not more, interesting and reliable.

 

Smart Contracts

For this approach, we only need one smart contract for tracking the assets.

We are going to use a similar approach to the ERC-721 token standard, but with a lot of parts removed and a quite a few modifications.

Since we don't want users to trade tokens like a normal NFT, we also want the ability to remove token access, and we want to control who can have what.

Interfaces

This interface defines the asset collection itself and is a stripped-down version of an ERC-721.

 

Picture1-Nov-16-2022-05-09-11-3891-PM

This interface determines control over the smart contract.

Picture2-Nov-16-2022-05-09-41-3630-PM

Asset Collection Smart Contract

The main smart contract is the Asset Collection smart contract. This contract is responsible for managing all the assets inside a particular collection. We (as the owners of the smart contract) can mint, burn, move and transfer tokens, where each token represents an asset.

We don't want users to trade tokens (like NFTs), but we need the basic functionality from an ERC-721.

Due to limitations on smart contract data storage, we are storing all the relevant information outside the blockchain, preferably on a persistent storage platform (like Machina or Arweave), and using the token URI metadata pattern used commonly for NFTs.

Mint

The "mint" function can only be called by the owner and is similar to the mint function found on any other NFT smart contract. It gives us the ability to create a token.

Picture3-Nov-16-2022-05-11-40-6489-PM

 

Burn

The "burn" method allows the token owner to destroy a token permanently.

 

Picture4-Nov-16-2022-05-28-37-1154-PM

Transfer

The "transfer" method returns a token and can only be called by the token owner.

Picture5-Nov-16-2022-05-29-19-9360-PM

Transfer From

The "transfer from" method allows the owner to control tokens on behalf of a user. This is useful when we want to change the holder or if we need to take ack the token and assign it to the owner.

 

Picture6-Nov-16-2022-05-30-00-3902-PM

This token allows us to track an asset securely and transparently.

Please note that this smart contract is just for demonstration purposes and is not optimized nor audited.

Full source code for the contract is available at Asset Collection smart contract deployed on the Avalanche Testnet

About Encora

Fast-growing tech companies partner with Encora to outsource product development and drive growth. Contact us to learn more about our software engineering capabilities.

 

Share this post

Table of Contents