tzNFT: Non-fungible Tokens on Tezos
Recently, we released a new version of the tzNFT command line tool and a corresponding tutorial describing how to use it. The NFT tutorial gives detailed step-by-step instructions on how to prepare your data, originate an NFT collection smart contract, and mint tokens. It also provides documentation on all tzNFT commands. In this post we will just give an overview of the minting process and discuss some tool options.
The new tzNFT CLI now fully supports the most recent Tezos metadata standards (TZIP-016 and TZIP-021).
There are plenty of resources that explain what non-fungible tokens are (like here and here). If you want a deep dive into what NFTs are and even how to build your own NFT platform on Tezos, we encourage you to read this post. tzNFT provides a high-level CLI API, which you could use right from the command line or from other scripts. Besides the tzNFT tool, we also provide a reusable high-level programmatic API to interact with FA2 contracts (fa2-interfaces). Use it to create your own applications that interact with FA2 smart contracts.
Things You Should Probably Know Before Creating Your Own NFTs
Before diving into technical details, let’s take a 10,000 foot view at all the moving parts and terminology.
Token Smart Contract
A token on the blockchain is just a record of ownership telling which Tezos address owns a token with a particular ID. Each token collection is represented by a smart contract that keeps a ledger of such records for all of its tokens and their current ownership. A collection smart contract also has some standard entry points (API) which allow one to transfer token ownership and inspect the collection. There is a Tezos standard TZIP-012 (also known as FA2) specifying a unified token contract interface and metadata. tzNFT provides the implementation of the collection smart contract that conforms to the TZIP-012.
Smart Contract Metadata
When a token contract is originated on blockchain, we also want to provide a description of that contract and token collection. We can do that by providing contract metadata at the time of the contract origination. TZIP-016 Tezos standard describes the format of the contract metadata. Here is a list of the most important attributes:
name
— name of the NFT collectiondescription
— optional description of the NFT collectionhomepage
— link to the NFT project homepageauthors
— list of the NFT collection authorsversion
— version of the smart contractlicense
— smart contract licenseinterfaces
— list of Tezos standards (interfaces) implemented by the smart contract. For our NFT collection implementation we support TZIP-016, TZIP-012, TZIP-021
tzNFT can generate a template metadata file and validate if the file format conforms to the TZIP-016 standard.
Rich Token Metadata
Besides a token ID, each NFT has associated metadata which describes what a token is. The FA2 standard requires a token to have at least the name attribute. TZIP-021 Tezos standard describes rich token metadata format. You can specify some of the standard metadata attributes and even add custom ones. Here is a list of the most important attributes:
name
— the name of the NFTdescription
— optional description of this NFTdecimals
— always set to0
for NFTsisBooleanAmount
— always set totrue
for NFTsartifactUri
— the link to a digital asset representing the NFT. If the asset is hosted on IPFS, the link should have the following formatipfs://<ipfs_hash?/<optional_path>
. Often a digital asset is an image, but it can be any media type.displayUri
— the link to the image representing this NFTthumbnailUri
— the link to the thumbnail version of the image representing this NFT
When minting (creating) a new token, we need to provide a JSON file with the token metadata. tzNFT can generate a template metadata file and validate if the file format conforms to the TZIP-021 standard.
Why TZIP?
Using NFT smart contracts that conform to the TZIP-012, TZIP-016 and TZIP-021 standards makes your tokens discoverable by various other applications and tools such as wallets and NFT marketplaces.
From Images to an NFT Collection on Tezos
There are several ways to associate media with NFTs. The approach that tzNFT takes is to store both your digital assets (images) and token metadata on IPFS using Pinata (You may use other IPFS services or even not use IPFS at all).
The general steps are:
- Install tzNFT tool by running
npm install -g @oxheadalpha/tznft
. - Create a new NFT project directory and run
tznft init
. This will create atznf.json
config file with all the settings for your project. Beware if you are using Tezos mainnet, this file will also hold your Tezos private keys. - Prepare your NFT collection metadata.
– Runtznft create-collection-meta
to generate the metadata template JSON file.
– Edit collection metadata and validate it withtznft validate-collection-meta
. - Originate a new collection smart contract using the collection metadata created in the previous step by running
tznft create-collection
. - Prepare your digital assets (images).
- Pin (upload) your digital assets on IPFS. You can either pin every file individually or pin the whole directory that contains your assets (there are
tznft pin-file
andtznft pin-dir
commands). - Use your asset’s IPFS URLs to prepare your token metadata. If you pinned your files individually your IPFS URLs should have the form
ipfs://<ipfs_hash_for_asset_file>
. If you pinned the whole directory your IPFS URL will be in the form ofipfs://<ipfs_hash_for_dir>/<path_to_file_in_dir>
.
– Generate token metadata template JSON file by runningtznft create-nft-meta
.
– Edit token metadata attributes (artifactUri
attribute should link to the NFT image on IPFS) and create a separate metadata JSON file for each token you intend to mint. - Pin (upload) your token metadata files to IPFS. You can pin metadata files individually or pin the whole directory.
- Mint tokens. Run
tznft mint
ortznft mint-from-file
. Provide a new ID and IPFS metadata URL for each token. You can mint multiple token batches into the same NFT collection contract. - Freeze your token collection by running
tznft mint-freeze
. After freezing the collection, no more new tokens can be minted. This optional step may guarantee the NFT’s scarcity and signal to other users that the collection has a limited token supply.
You can do a “dry run” first using either Tezos sandbox (default tzNFT option) or a testnet. Once you are ready, you can switch to Tezos mainnet, configure a funded Tezos address and mint your NFTs on the mainnet.
What is Next?
Now you have created your own NFT collection smart contract on Tezos. You can inspect and transfer your tokens either by using tznft show-meta
and tznft show-balance
commands; TZComet or other Tezos indexer and wallet applications.
In the tutorial we created non-fungible tokens that represent images hosted on IPFS. It is also possible to link to other media types such as documents, video, or audio by modifying the token metadata (check media formats definition in the TZIP-021 standard).
Since we followed the Tezos FA2 token standard, your contract can be used by any other contract or application which interacts with FA2 tokens.
For instance, you may onboard your contract at Objkt.com or Rarible marketplaces and list them for sale.
You can create your own scripts that automate NFT generation and use tzNFT CLI tool there. You can even create your own NFT platform from scratch with the reusable FA2 API package