NFTs have taken the crypto world by storm, and in the past 6 months, we’ve seen interest in Bitcoin NFTs on Stacks skyrocket:
- 7 organic marketplaces emerged
- 140,000+ NFTs minted
- >4M STX volume traded
- Top NFT series are up 10-50X
The Stacks community has embraced Bitcoin NFTs as a way to own part of Bitcoin culture, and Hiro has made it easier for Stacks developers to capitalize on that interest and build new applications around NFTs by adding new NFT endpoints to the Stacks API. Those endpoints include:
- Non-Fungible Token holdings
- Non-Fungible Token history
- Non-Fungible Token mints
Let’s dive into each endpoint and explore what you can do with them.
Non-Fungible Token holdings
This endpoint can retrieve all of the NFTs owned by a specific STX address or by a smart contract ID. For example, if you want to get all NFTs owned by the STX address SP3BK1NNSWN719Z6KDW05RBGVS940YCN6X84STYPR you would call this URL:
Once called, the API response will look something like:
As you can see in the sample response, the endpoint returns all of the NFT assets held by that address. In this case, the user owns 4 NFTs, including a BNS name, as well as NFTs from Project Indigo, Wasteland Apes, and Crashpunks.
These results can also be filtered by one or more asset identifiers (such as the name of the NFT collection) and can be configured to include metadata about each asset transaction (such as the STX price the user paid for each NFT).
Developers can use this endpoint to confirm whether a user holds a specific NFT. With that information, developers can create whitelists or gated access to specific app features, based on whether the user holds an NFT from a particular collection.
This endpoint also enables developers to build user profiles that show off the user’s NFT portfolio. For example, a NFT marketplace might create these user profiles to foster a stronger sense of community. These public profiles would allow users to display their NFT collection and select a profile picture from among the NFTs in their collection.
To learn more about the available request parameters and response fields for this endpoint, visit https://docs.hiro.so/api#operation/get_nft_holdings.
Non-Fungible Token history
Through this endpoint, you can pull all events and transactions that affected a particular NFT. This is useful for developers who want to look at the ownership history of a particular asset. For example, to get the history of The Explorer Guild NFT #2051, you would call this URL:
Note how the NFT "value" (2051 in this case) has to be encoded into its Clarity hex representation. Once called, the API response will look something like:
The endpoint then retrieves a list of all events that affected this NFT. In this example, you can see both a mint and transfer to marketplace event in the “asset_event_type”. This endpoint can also retrieve transfers to owners, as well as relevant details for each event, such as listing and purchase prices.
With this data, developers can build price charts for specific NFTs, monitor trading activity, and more.
To learn more about the available request parameters and response fields for this endpoint, visit https://docs.hiro.so/api#operation/get_nft_history.
Non-Fungible Token mints
This endpoint can help developers identify which NFTs of a particular collection have been minted, and by whom. For example, if you want to get the last 3 NFTs minted from the Megapont Ape collection, you would call this URL:
Once called, the API response will look something like:
This code retrieves the mint history from a specific NFT collection, including optional data about each event such as the price for minting and any fees incurred.
With this information, developers can figure out how many NFT mints are remaining in a new collection, get a list of all addresses that participated in the mint, find out which address minted the most of a particular collection, and more.
To learn more about the available request parameters and response fields for this endpoint, visit https://docs.hiro.so/api#operation/get_nft_mints.
Conclusion
We’re eager to see what you can build with these endpoints! If you want to learn more about NFTs on Stacks, learn more about the token standards in Stacks in our general documentation. If you're a visual learner, you can also watch Rafael break down this endpoints in a video on our YouTube channel.