Deploying a NFT Contract
If you want to deploy your own NFT contract, you can create one using our reference implementation.- 🖥️ CLI
Lantstool
Global Contract
You can deploy a new Non-Fungible Token using our global NFT contract - a pre-deployed standard NFT contract that you can reuse. Global contracts are deployed once and can be reused by any account without incurring high storage costs.- By Account
- By Hash
Deploying by hash creates an immutable contract that never changes. Deploying by account ID creates an updatable contract that changes when the referenced account’s contract is updated. Choose based on whether you want your FT contract to be updatable or permanent.
Minting a NFT
To create a new NFT (a.k.a. minting it) you will call thenft_mint method passing as arguments the metadata that defines the NFT.
Manual Interaction
Manual Interaction
Here is how to directly interact with the factory contract through your application:Learn more about adding Near Connect to your application
- 🌐 WebApp
- 🖥️ CLI
Lantstool
- 📄 Contract
See the metadata standard for the full list of
TokenMetadata parameters.Minting Collections
Many times people want to create multiple 100 copies of an NFT (this is called a collection). In such cases, what you actually need to do is to mint 100 different NFTs with the same metadata (but differenttoken-id).
Royalties
You might have noticed that one of the parameters is a structure called royalties. Royalties enable you to create a list of users that should get paid when the token is sell in a marketplace. For example, ifanna has 5% of royalties, each time the NFT is sell, anna should get a 5% of the selling price.
Querying NFT data
You can query the NFT’s information and metadata by calling thenft_token.
- 🌐 WebApp
- 🖥️ CLI
Lantstool
- 📄 Contract
Transferring a NFT
Transferring an NFT can happen in two scenarios: (1) you ask to transfer an NFT, and (2) an authorized account asks to transfer the NFT. In both cases, it is necessary to invoke thenft_transfer method, indicating the token id, the receiver, and an (optionally) an approval_id.
- 🌐 WebApp
- 🖥️ CLI
Lantstool
- 📄 Contract
Attaching NFTs to a Call
Natively, only NEAR tokens (Ⓝ) can be attached to a function calls. However, the NFT standard enables to attach a non-fungible tokens in a call by using the NFT-contract as intermediary. This means that, instead of you attaching tokens directly to the call, you ask the NFT-contract to do both a transfer and a function call in your name.- 🖥️ CLI
Lantstool
Optionally, a
memo parameter can be passed to provide more information to your contract.How Does it Work?
Assume you want to attach an NFT (🎫) to a call on the receiver contract. The workflow is as follows:- You call
nft_transfer_callin the NFT-contract passing: the receiver, a message, and the token-id of 🎫. - The NFT contract transfers the NFT 🎫 to the receiver.
- The NFT contract calls
receiver.nft_on_transfer(sender, token-owner, token-id, msg). - The NFT contract handles errors in the
nft_resolve_transfercallback. - The NFT contract returns
trueif it succeeded.
The nft_on_transfer method
From the workflow above it follows that the receiver we want to call needs to implement thenft_on_transfer method. When executed, such method will know:
- Who is sending the NFT, since it is a parameter
- Who is the current owner, since it is a parameter
- Which NFT was transferred, since it is a parameter.
- If there are any parameters encoded as a message
nft_on_transfer must return true if the NFT has to be returned to the sender.
Approving Users
You can authorize other users to transfer an NFT you own. This is useful, for example, to enable listing your NFT in a marketplace. In such scenario, you trust that the marketplace will only transfer the NFT upon receiving a certain amount of money in exchange.- 🖥️ CLI
Lantstool
If the
msg parameter is included, then a cross-contract call will be made to <authorized_account>.nft_on_approve(msg). Which in turn will make a callback to nft_resolve_transfer in your NFT contract.Burn Tokens
While the NFT standard does not define aburn method, you can simply transfer tokens to an account that no one controls, such as 0000000000000000000000000000000000000000000000000000000000000000 (64 zeros).
- 🌐 WebApp
- 🖥️ CLI
Tutorials
- NFT Tutorial Zero to Hero (JavaScript SDK) - a set of tutorials that cover how to create a NFT contract using JavaScript.
- NFT Tutorial Zero to Hero (Rust SDK) - a set of tutorials that cover how to create a NFT contract using Rust.