Non-fungible tokens or NFTs are digital assets registered on a blockchain with unique identifiers and properties that distinguish them from each other.
This contract example implements a basic NFT collection that conforms to the SIP-009 NFT standard. Be sure to change the placeholder name of the collection and its max supply.
In Stacks Improvement Proposal 009 (SIP-009), the Stacks community proposed and approved a standard set of functions that every NFT contract is to implement to qualify as a compliant Stacks NFT. This creates uniformity and predictability in contract interactions, as well as enables a handful of built-in Clarity functions accessible only to SIP-009 contracts (such as nft-transfer?
, etc.)
Those functions are specified in the SIP and must be implemented in each contract. Trait conformance is then asserted with an impl-trait
declaration at the top of the contract pointing to the relevant trait reference published on the Stacks mainnet.
You can see this nft-trait
reference in the Hiro Stacks Explorer.
You can manually test your contract in the Clarinet console. After entering the console with clarinet console
you can make contract function calls like
(contract-call? .nft claim)
(contract-call? .nft get-last-token-id)
You can programmatically test your contracts with unit tests. See the tests/
folder where you will find a unit test that ensures the claim
function returns the proper response and that the read-only functions work as expected.
- One of the most successful NFT collections in Stacks is Megapont Ape Club. You can view the source code of their NFT contract
- The Crash Punks project had an upgrade from v1 to v2, which this NFT contract implements
- An ambitious use case for NFTs is Mechanism.io's BNSx project, where pre-SIP-009 era BNS names can be wrapped into a SIP-009 NFT. You can learn more about the BNSx project and look at the source code here.