How Are TON-Powered NFTs Built?

How Are TON-Powered NFTs Built?

Today, the TON NFT standard has obtained the Release Candidate status.

This means that active discussions are over, and no major changes are planned. Apart from the standard itself, examples of smart contracts for NFT collections, NFT tokens, and a simple NFT-to-Toncoin swap marketplace have been published as well. The developers have also introduced JavaScript SDK and cases of interaction with NFT smart contracts.

NFT project creators and service developers may start integrating the technology into their products on the test network. It is advised to refrain from the main network launches at this time—although there are no fundamental changes in sight, you may want to wait for the standard's final release before making a full-fledged product launch.

NFT on TON: Operational Side

TON has taken an advantage of a rare opportunity to design a standard that would indeed be oriented toward providing the best product offering, rather than focusing exclusively on lower network fees (e.g., ERC721). The team has capitalized on many global crypto community lessons learned from the previous implementations on other chains.

In the majority of other blockchains, for example, Ethereum, an NFT represents a single smart contract storing all of the collection's elements.

A big and popular NFT with thousands of elements becomes the network's bottleneck as thousands of transactions turn to a single smart contract.

TON is built atop the sharding concept (splitting into parts) aimed to ensure the network's scalability. That is why a TON NFT is comprised of a single smart contract for an NFT collection as a whole and a number of individual smart contracts for each of its elements. If you issue a collection of 10,000 elements, the number of smart contracts you isssue is 10,000 + 1.

Thanks to the TON's efficiency, such an issuance will cost you around 500 times less than that of a single Ethereum smart contract.

Other tech features of the TON blockchain also signal the favorability of using such an approach. But that is a story for another time.

NFT Collection's Smart Contract

This smart contract includes 3 mandatory get methods:

  1. get_collection_data – returns the total quantity of NFTs created within a given collection in real time along with its metadata (title, description, etc.) The data format is described below.
  2. get_nft_address_by_index – returns the smart contract address of an NFT within a given collection by its order.
  3. get_nft_content – when you transmit specific NFT's metadata into this method, it returns the metadata of an entire collection.

The point is that collection's smart contract stores data that is common across all elements, while NFT element's smart contract, only its individual part. In this method, they are merged.

For example, if an NFT element links to its content, then domain "https://mynft.com" will be stored in the collection's contract, and the url slug "kind-cobra", in the NFT contract itself.

By merging them, we get the full address, which is "https://mynft.com/kind-cobra".

Once TON Storage goes live, the collection's author will be able to change the address to "ton://storage/my-nft/kind-cobra" in a single operation and move everything to a decentralized storage.

Minting

Normally, the collection's smart contract is also utilized for 'minting'—through it, the author issues new NFTs with the data they need.

NFT Element's Smart Contract

This type has just one required method, get_nft_data, which returns the given NFT's data including:

  • Order in collection
  • Smart contract address of a collection to which it belongs
  • Current owner address
  • Metadata of the NFT in question (the format is described below)

This one needs to process two messages:

transfer(new_owner_address) – changes the owner and sends a notification to its new address.

get_static_data – returns immutable data: order and collection's smart contract address.

Standard Extensions

The standard can be extended with other standards, namely NFTRoyalty, NFTEditable, and NFTUpgradable. Let us take a closer look at each of them.

NFTRoyalty Extension

This extension adds an additional required method, royalty_params, which returns the numerical value of share that the collection's author is willing to receive on each NFT sale. It also contains the address where the coins should be sent (for example, the author does not need the proceeds but wishes to donate them to a charity instead).

When sent the get_royalty_params query, the smart contract must return the royalty paramaters above in response.

NFTEditable Extension

The collection and the NFT elements store the Data Editor address, which may modify the data of a collection or its individual NFT elements.

This scenario may be used for implementing gaming mechanics where two items interact and influence each other—e.g., one sword breaks the other. In this case, the game's smart contract will act as Editor. It is also possible to re-assign the current Data Editor.

NFTUpgradable Extension

The collection and the NFT elements also store the Code Editor address, which may modify the code of a collection or its individual NFT elements.

This scenario may be used for implementing even more sophisticated gaming mechanics. It is also possible to re-assign the current Code Editor.

Content Storage Format

There are two ways to store the content.

1. Off-Chain

The smart contract only stores a link to a JSON file containing all necessary data. The JSON file is compatible with what is used by OpenSea.

It is this format that most of the Ethereum-based NFTs use.

2. On-Chain

The smart contract stores all data on the blockchain as key → value. The key represents an arbitrary string. Some strings (such as "name," "description," and "image") are standardized.

You may also opt to mix the two ways by storing one part on the blockchain and the other, outside of it.

Smart Contracts of Marketplaces, Sales, and Auctions

Although marketplaces and auctions are not part of the standard, the developers have offered their vision regarding possible implementation.

The user can create a new smart contract selling their NFT at a fixed price in Toncoin or through an auction.

When creating a smart contract, the user—or, to be precise, the markeplace interface through which the sale is arranged—sets the following parameters: NFT address, sale price, maximum duration, author's royalty & marketplace's fee.

Upon creation, the marketplace verifies the data of a smart contract, and if it is correct (matches the collection's royalty_params, the marketplace's minimum fee, etc.), a new contract is initialized.

After that, the seller transfers NFT to the auction's smart contract, and the buyer can simply send Toncoin to the smart contract address.

If the amount received is sufficient, the NFT automatically goes to the buyer, and Toncoin is distributed among the seller, collection's author, and marketplace according to the predetermined settings.

Specific marketplaces may add extra recipients into their smart contracts—for example, to reward partners.

Auctions with invalid data will simply not be shown in the marketplace's interface.

Subscribe
to our Telegram channel