To support this growing interest, we’ve shipped a new developer learning experience focused on the creation of non-fungible tokens (NFTs) using Clarity smart contracts on Stacks. This experience consists of a new NFT tutorial and additional documentation about tokens and Proof of Transfer (PoX).
Our NFT tutorial is a beginner-intermediate Clarity tutorial that features Clarinet as a local development environment, and demonstrates several features of Clarity and Clarinet. While there are many ways to implement an NFT contract, the contract in the Stacks documentation is a simple example of an NFT using Clarity.
On Stacks, the NFT standard is defined by SIP-009, which outlines the set of standard traits an NFT contract must implement to be supported by Stacks wallets. As NFTs are a common project for developers, it is important for the Stacks documentation to provide a working example of a simple NFT contract.
The example contract uses the impl-trait Clarity function to declare that it implements the SIP-009 standard for NFTs. The tutorial demonstrates the 4 traits necessary to comply with SIP-009:
- get-last-token-id: Takes no arguments and returns the identifier for the last NFT registered using the contract.
- get-token-uri: Takes an NFT identifier and returns a response containing a valid URI which resolves to the NFT's metadata.
- get-owner: Takes an NFT identifier and returns a response containing the principal owning the NFT with the given identifier.
- transfer: The function changes the ownership of the NFT for the given identifier from the sender principal to the recipient principal.
Additionally, the tutorial contains a full unit test using Clarinet to show an easy way to programmatically test your smart contracts and verify their function.
You can take this example contract and use it to build your own NFT by modifying the token name and the metadata URI of the contract. Try creating your own and deploying it to testnet! If you’re interested in some of the great NFT projects on Stacks, check out the following:
- This is Number One
- Risidio
- Boom wallet
- Layer
- Momento
- Open Art Source
- All NFT contracts on mainnet according to search-clarity.dev
📖 Additional Docs content
In addition to the NFT tutorial, we’ve also added some general documentation discussing the difference between fungible and non-fungible tokens. The PoX section of the documentation has been greatly expanded with more figures and discussion about why implementing PoX against Bitcoin is important. These improvements were identified as pain points by members of the Stacks community.
As always, we rely on you to tell us the types of content you are looking for in the Stacks documentation. You can always submit your own content, or add an issues to the Stacks docs repo to get a piece of content developed.
📺 Learn more about the history of NFTs on Bitcoin
In a recent Stacker Chat, Muneeb talked with Gina Abrams about the history of non-fungible tokens on Bitcoin. For as long as Bitcoin has existed, Bitcoin users have experimented with creating and trading NFTs on it. From Namecoin to the Counterparty platform, there have been many attempts at creating a lasting NFT solution on Bitcoin. Limitations of previous NFT solutions on Bitcoin have included transaction fees and the lack of full smart contract support. With Stacks and Clarity, NFTs are easy to create; with PoX, NFT ownership is settled on the Bitcoin blockchain. Provenance and ownership are important aspect of NFTs, and encoding that ownership on a network that has shown incredible durability and longevity lends confidence to the permanence of the NFT.
🏁 Summary
NFTs are a unique use of blockchain technology, and have captured the imaginations of the public. Recently, interest in NFTs has seen explosive growth, and developers are looking for ways to implement NFTs that settle against Bitcoin. Try out the new NFT tutorial, and see how easy it is to build your own!
Looking for a home for your NFT project? Download our free guide to Web3 ecosystems in 2022.