In this tutorial, we will discuss the standard implementation of non-fungible tokens (NFTs) on the TON blockchain and walk through the development steps using the Blueprint environment and Sandbox.
Start for free and get your app to production levels immediately. No credit card required. You can sign up with your GitHub, X, Google, or Microsoft account.
To develop NFTs on the TON blockchain, it’s essential to understand the standards that define their structure and behavior. The two key standards are:
TEP-62: NFT standard describes the interface and functionality of NFT smart contracts on TON. It specifies how NFTs are created, transferred, and managed.
TEP-64: Token data standard defines how metadata associated with tokens (both fungible and non-fungible) is stored and retrieved. It ensures a consistent format for token metadata, whether stored on-chain or off-chain.
Each NFT is represented by its own smart contract, known as an NFT item contract. This contract manages ownership, metadata, and interactions specific to that NFT. An NFT collection contract manages a group of NFTs. It can deploy new NFT item contracts, assign unique indices, and associate them with the collection.
First, ensure that you have Node.js and npm installed on your system. You can verify the installation by running:
node -vnpm -v
Create a new directory for your project and navigate into it:
mkdir ton-nft-projectcd ton-nft-project
Initialize a new Blueprint project by running:
npm create ton@latest .
This command sets up a new TON project with the necessary files and dependencies. Follow the prompts to select an empty FunC project.
Next, we’ll configure the project to connect to the testnet. Create a file named blueprint.config.ts in the root of your project directory and add the following content:
We’ll use the reference implementations of the NFT standard provided by the TON core team. To your project’s contracts directory, copy the following files:
nft-item.fcis the smart contract for individual NFT items.
nft-collection.fcis the smart contract for the NFT collection.
op-codes.fc, params.fc are utility files that contain common functions and definitions used by the contracts.
Ensure that your contracts include the required imports. For example, at the top of nft-item.fc and nft-collection.fc, include:
if (op == op::mint()) { ;; deploy new nft // Mint handling}if (op == op::batch_mint()) { ;; batch deploy of new nfts // Batch mint handling}if (op == op::change_admin()) { ;; change owner// Change admin handling}
Before testing the contracts, we need to compile them. In the wrappers directory, create compile configuration files for each contract. For the NFT item contract, create NFTItem.compile.ts:
To interact with our smart contracts in tests, we’ll create TypeScript wrappers that implement the contract interfaces. In the wrappers directory, create NFTItem.ts and NFTCollection.ts.
The Blueprint framework incorporates Sandbox. The package allows developers to emulate TON smart contracts behaviour as if they were deployed on a real network. Please copy the tests from our repository.
We covered the the non-fungible token standard on the TON blockchain and its main development steps using Blueprint and Sandbox. In future tutorials, we will explore other aspects of NFT. Stay tuned!
Multiple years of software development and Web3 expertise. Creator of the open-source Compare Dashboard for RPC provider performance benchmarking. Core contributor to the DevEx team’s pump.fun trading bot. Author of technical tutorials on EVM blockchains, Solana, TON and Subgraphs.