Due to Moralis’ final NFT API, any dev can get all NFTs from a set. Set up the Moralis SDK and use the “getContractNFTs“ NFT API endpoint; it’s so simple as that! Primarily, with the next code snippet, you’ll be able to cowl the core of fetching non-fungible tokens from a set:
const response = await Moralis.EvmApi.nft.getContractNFTs({ handle, chain, });
In case you might be already aware of Moralis and the way it lets you bridge the event hole between Web2 and Web3, you in all probability have a number of concepts for using the above strains of code. Nevertheless, in case you are new to Web3 improvement, be sure to finish right this moment’s tutorial. By doing so, you’ll discover ways to get all of the NFTs from a set simply. Simply create your free Moralis account and observe our lead.

Overview
The bear market is the perfect time to construct dapps (decentralized functions). Contemplating that NFTs proceed to be one of the in style blockchain use circumstances, now’s the suitable time to discover ways to work with the final word NFT API.

As identified earlier, the “getContractNFTs” API endpoint would be the focus of right this moment’s article. The upcoming tutorial will revolve round correctly incorporating the above-presented snippet of code. Finally, we’ll train you use JavaScript (JS) or TypeScript (TS) to get all NFTs from a set with out breaking a sweat. Fortuitously, it is a three-step course of that shouldn’t take you greater than a few minutes. Particularly because you’ll be capable to merely copy and paste our strains of cod, and when you get NFTs from a set, you’ll get to make use of your terminal to discover the outcomes.
As well as, we determined that can assist you take issues to the following stage. As such, you’ll additionally be capable to observe our lead and create a easy NFT explorer dapp. That approach, you’ll see neatly make the most of the outcomes supplied by the “getContractNFTs” endpoint.
Nevertheless, earlier than we invite you to roll up your sleeves and observe our directions, we have to guarantee you already know the fundamentals. Therefore, we’ll first clarify what NFTs and NFT collections are. We’ll additionally take a more in-depth take a look at the final word improvement instrument for NFT collections – the Moralis NFT API.
NFTs and Collections – What are They?
NFTs (non-fungible tokens) are particular sorts of crypto property. According to the that means of “non-fungible”, these kind of tokens should not interchangeable. Because of this every NFT has its distinctive token ID (an on-chain signature). Therefore, NFTs are designed to signify distinctive digital or bodily objects. As such, it is smart that digital artwork and digital collectibles are usually the commonest utility examples of non-fungible tokens. Nevertheless, NFTs are already revolutionizing many different industries that require any sort of possession proofing or certification issuing. Nonetheless, these crypto property are additionally poised to vary the gaming business. In any case, we’re already seeing varied Web3 gaming initiatives that empower gamers to really personal their in-game property.
Moreover, NFTs are sometimes assigned to collections. This isn’t important, as an NFT may be fully impartial. Nevertheless, most of the time, the creators of non-fungible tokens are likely to assign a bigger quantity of tokens to a single assortment. In fact, the sizes of collections additionally differ significantly from challenge to challenge. In digital artwork, collections have a tendency to incorporate fewer NFTs. Alternatively, in terms of digital collectibles, a single assortment can usually embrace a number of thousand NFTs. As an example, the CryptoPunks assortment contains almost 10,000 NFTs.
Furthermore, it’s value mentioning that devs create (mint) NFTs utilizing good contracts. These on-chain items of software program embrace all the small print concerning the NFT they deal with. Plus, contracts embrace predefined actions that might be executed when particular predefined situations are met. Therefore, additionally they govern transactions associated to their NFTs. Additionally, be aware that there’s the identical good contract behind all of the NFTs in a single assortment. Thus, we get NFTs from a set by specializing in the suitable good contract.
Final Improvement Device for NFT Collections
Now that you already know what NFTs and NFT collections are, it’s time we take a more in-depth take a look at the instrument that allows you to get all NFTs from a set. By this level, you already know that if you wish to study what number of NFTs in a set there are, you should use the Moralis “getContractNFTs” endpoint. In fact, there are much more particulars that this glorious instrument can give you for a selected assortment.
You possibly can even increase your toolset by using different NFT API endpoints in Moralis’ arsenal. Moreover, when constructing dapps, you’ll possible wish to use different Moralis’ Web3 APIs, beginning with its Web3 Auth API. Furthermore, when working with NFT collections, the “getWalletNFTCollections” and “getNFTContractMetadata” endpoints may be notably helpful.
Nevertheless, on this article, we wish to present you get all of the NFTs from a set utilizing “getContractNFTs“. Thus, we have to take a more in-depth take a look at this endpoint, which basically lets you get all NFTs from a contract. Additionally, “getContractNFTs” gives you with metadata for all NFTs belonging to a selected good contract. That mentioned, it is best to remember that the endpoint is restricted to presenting 100 outcomes per web page. As such, it’s worthwhile to work with the cursor parameter for collections with greater than 100 NFTs.
Get NFTs by Contract Docs
Following is a screenshot of the “Get NFTs by Contract” documentation web page:
The latter gives all the small print concerning the endpoint. This web page additionally lets you take a look at this endpoint and replica the code that matches your programming language. Moreover, listed below are the parameters that this endpoint takes in:
- “handle“ – You utilize this parameter to supply an NFT good contract handle. Furthermore, this parameter is important (all different parameters are non-obligatory).
- “chain“ – This parameter permits you to decide which programmable chain to deal with (Moralis helps all main Web3 networks).
- “format“ – You utilize this parameter to find out what kind of token ID format you wish to work with – decimal or HEX.
- “restrict“ – This parameter permits you to set the specified web page dimension of the outcome.
- “totalRange“ – You utilize this parameter to find out the variety of subranges to separate the outcomes into.
- “vary“ – This parameter permits you to set the specified subrange to question.
- “cursor“ – You utilize this parameter to get to the following web page when you’ve greater than 100 NFTs or wish to show even fewer NFTs per web page.
- “normalizeMetadata” – This parameter permits you to resolve whether or not normalized metadata must be returned (true) or not (false). If you happen to select “true”, the endpoint returns metadata in a standardized construction in a brand new object known as “normalized_metadata”.
Now that you already know the speculation and the capabilities of the “getContractNFTs” endpoint, you might be able to get your palms soiled. As such, be sure to observe our tutorial that covers the steps it’s worthwhile to full to get NFTs from a set.
How you can Get All NFTs from a Assortment
Figuring out get all NFTs from a set may be extraordinarily helpful. As identified earlier, NFTs play necessary roles in lots of dapps, and you should use these kind of tokens to signify possession of a singular merchandise on the blockchain. Accordingly, you’ll be able to construct NFT portfolio trackers, NFT-gated web sites, DAOs, social graphs, and lots of different kinds of NFT dapps.
Earlier than transferring on, ensure you have these three conditions accomplished:
- Set up Node v.14 or increased.
- Put together your favourite code editor or IDE. We have a tendency to make use of Visible Studio Code (VSC).
- Set up your favourite bundle supervisor (”npm”, ”yarn”, or ”pnpm”).
Step 1: Set Up Moralis
To finish this tutorial and get all NFTs from a set, you could entry your Moralis admin space. As such, ensure you create your free Moralis account. You are able to do so by utilizing the hyperlink within the intro or by visiting the Moralis homepage:
In both case, you’ll land on the register web page. Merely enter your full identify and e mail handle, create your password, and settle for the phrases and situations. With these particulars in place, you’ll be capable to click on on the “Signal Up” button:
Lastly, verify your account by clicking on the affirmation hyperlink in your e mail inbox.
Whether or not you wish to use “getContractNFTs” to get NFTs from a set or another Moralis Web3 API endpoint, you want your Web3 API key. Fortuitously, now that you’ve got your Moralis account prepared and might entry your admin space, you get to acquire it in two easy clicks:
You’ll see the place to stick your API key within the subsequent part. Nevertheless, earlier than transferring on, set up the Moralis SDK in your challenge. Relying on the bundle supervisor that you’re utilizing, it’s worthwhile to run one of many following instructions:
npm set up moralis
yarn add moralis
pnpm add moralis
Step 2: Use an Instance Script to Get All NFTs from a Assortment
With the preliminary setup beneath your belt, you might be able to deal with an instance script that lets you get all of the NFTs from a set effortlessly. Right here is an “index.js” script that does the trick:
const Moralis = require("moralis").default; const { EvmChain } = require("@moralisweb3/evm-utils"); const runApp = async () => { await Moralis.begin({ apiKey: "YOUR_API_KEY", // ...and another configuration }); const handle = "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"; const chain = EvmChain.ETHEREUM; const response = await Moralis.EvmApi.nft.getContractNFTs({ handle, chain, }); console.log(response); } runApp();
Notice: In case you favor working with TypeScript, be sure to make use of the “documentation web page” hyperlink above. There, you’ll get to decide on between “index.js” and “index.ts”.
Furthermore, should you take a look at the strains of code above, you’ll be able to see “EvmChain.ETHEREUM“. The latter defines the chain the script focuses on. So, should you’d wish to get all of the NFTs from a set on different main EVM-compatible chains, you’d want to switch “ETHEREUM” accordingly.
Nonetheless, whether or not you resolve to make use of JS or TS, it’s worthwhile to exchange the “YOUR_API_KEY” placeholder with the above-obtained Web3 API key.
Step 3: Execute the Program to Get All NFTs from a Assortment
Now that you’ve got the “index” file prepared, you get to execute this system and see the small print for a given handle, together with what number of NFTs in a set there are. Therefore, enter one of many following instructions in your terminal:
For JavaScript:
node index.js
For TypeScript:
node index.ts
After operating the suitable command, test your terminal for the outcomes. If you happen to didn’t change the handle within the code above, it is best to see the next outcomes:
{ "complete": 9991, "web page": 0, "page_size": 100, "cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3aGVyZSI6eyJ0b2tlbl9hZGRyZXNzIjoiMHhiNDdlM2NkODM3ZGRmOGU0YzU3ZjA1ZDcwYWI4NjVkZTZlMTkzYmJiIn0sInRva2VuX2FkZHJlc3MiOiIweGI0N2UzY2Q4MzdkZGY4ZTRjNTdmMDVkNzBhYjg2NWRlNmUxOTNiYmIiLCJsaW1pdCI6MTAwLCJvZmZzZXQiOjAsIm9yZGVyIjpbXSwicGFnZSI6MSwia2V5IjoiZmQ5MmE0ODg3MmE4NjIwZTFlNmU0NTk3ODZkMTExYWYiLCJ0b3RhbCI6OTk5MSwiaWF0IjoxNjY3ODA4NzcxfQ.9qXwHyyUKJkzrub-ze-q2gm8dC0dy-jvgF0CJrm5piY", "outcome": [ { "token_address": "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb", "token_id": "9082", "amount": "1", "token_hash": "fffdaced3ddfb220d9124289a518bb97", "block_number_minted": "12021693", "updated_at": null, "contract_type": null, "name": "CRYPTOPUNKS", "symbol": "Ͼ", "token_uri": "https://www.larvalabs.com/cryptopunks/details/9082", "metadata": "{"image":"https://www.larvalabs.com/cryptopunks/cryptopunk9082.png","name":"CryptoPunk 9082","attributes":["Bandana","Big Shades","Shadow Beard"],"description":"Male"}", "last_token_uri_sync": null, "last_metadata_sync": "2022-10-05T17:55:52.262Z", "minter_address": "0xc352b534e8b987e036a93539fd6897f53488e56a" }, { "token_address": "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb", "token_id": "4799", "quantity": "1", "token_hash": "fff8ff007820e85a75c545389d5a88d4", "block_number_minted": "11637283", "updated_at": null, "contract_type": null, "identify": "CRYPTOPUNKS", "image": "Ͼ", "token_uri": "https://www.larvalabs.com/cryptopunks/particulars/4799", "metadata": "{"picture":"https://www.larvalabs.com/cryptopunks/cryptopunk4799.png","identify":"CryptoPunk 4799","attributes":["Blue Eye Shadow","Black Lipstick","Straight Hair Blonde","Earring"],"description":"Feminine"}", "last_token_uri_sync": null, "last_metadata_sync": "2022-07-17T17:25:24.644Z", "minter_address": "0xc352b534e8b987e036a93539fd6897f53488e56a" }, { "token_address": "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb", "token_id": "47", "quantity": "1", "token_hash": "fff3657368693f145d0ad29453f6cd4d", "block_number_minted": "3918216", "updated_at": null, "contract_type": null, "identify": "CRYPTOPUNKS", "image": "Ͼ", "token_uri": "https://www.larvalabs.com/cryptopunks/particulars/47", "metadata": "{"picture":"https://www.larvalabs.com/cryptopunks/cryptopunk047.png","identify":"CryptoPunk 047","attributes":["Knitted Cap"],"description":"Male"}", "last_token_uri_sync": null, "last_metadata_sync": "2022-07-24T12:12:11.930Z", "minter_address": "0xc352b534e8b987e036a93539fd6897f53488e56a" } ], "standing": "SYNCED" }
So, what number of NFTs in a set are there when specializing in the “0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB” handle on the Ethereum chain? If you happen to’re pondering 9,991, you’re proper. Now, strive utilizing the “index” script to get NFTs from a set on different EMV-compatible chains.
Bonus: Get All NFTs from a Assortment Utilizing an Explorer Dapp
The above tutorial taught you get all of the NFTs from a set. As such, you are actually able to construct a correct dapp using the “getContractNFTs” endpoint. If that sounds fascinating, be sure to make use of the video beneath and observe our in-house professional’s lead. As a substitute of specializing in what number of NFTs in a set there are, you’ll construct a neat NFT explorer dapp. The latter will allow you to enter a contract handle and choose the chain you wish to deal with. With these two parameters in place, you’ll be capable to hit the “Get NFTs” button, which can get NFTs from a set and neatly current the primary twenty NFTs:
Lastly, that is the video tutorial that may present you create a NodeJS backend app and ReactJS frontend app and tie all of it collectively to create a cool NFT explorer dapp with Moralis:
How you can Get All NFTs from a Assortment in 3 Steps – Abstract
In right this moment’s article, you had a possibility to discover ways to get all NFTs from a set utilizing the final word NFT API. In case you have been new to Moralis, you additionally realized that this enterprise-grade Web3 API supplier lets you create killer dapps the straightforward approach. We additionally defined what NFTs and NTF collections are. Nevertheless, the core of the article was our three-step tutorial that targeted on utilizing the “getContracNFTs” endpoint. Moreover, by finishing this tutorial, you realized simply learn how many NFTs in a set there are, amongst a number of different particulars. Final however not least, you additionally had an opportunity to observe a brief video tutorial and construct an instance NFT explorer dapp. Therefore, you now know get all NFTs from a set utilizing our instance dapp.
If you happen to loved right this moment’s tutorial and wish to proceed exploring NFT improvement, be sure to take a look at our different NFT API how-to guides that await you in Moralis’ docs. Alternatively, it’s possible you’ll be serious about exploring different blockchain improvement matters. In that case, it is best to go to the Moralis YouTube channel and our blockchain weblog. A few of the newest articles there embrace crypto pockets integration, Web3 supplier, Web3 for enterprise, and lots of different fascinating matters.
Final however not least, you is likely to be serious about going full-time crypto sooner moderately than later. If that’s the case, you should enroll in Moralis Academy. There, you’ll be capable to select amongst many alternative programs and turn into blockchain-certified. Nevertheless, we advocate beginning with blockchain and Bitcoin fundamentals.