Get NFT Metadata – Easy methods to Get the Metadata of an NFT

When creating an NFT venture, instruments that streamline NFT-related duties, equivalent to getting NFT metadata, are important. Because of the last word NFT API from Moralis, a developer can simply get the metadata of an NFT when utilizing the “getNFTMetadata” endpoint:

const response = await Moralis.EvmApi.nft.getNFTMetadata({

So, how you can get NFT metadata? It’s so simple as utilizing the code snippet above! Now, should you’ve labored with Moralis‘ Web3 APIs earlier than, odds are you know the way to include the above traces of code in your scripts appropriately. As such, merely use the documentation hyperlink under to get began! Nonetheless, if you’re new to Moralis, be certain that to complete this text’s tutorial. By doing so, you’ll discover ways to get NFT metadata the straightforward approach. You’ll simply want your free Moralis account and some minutes of your time to get to the end line.


Thus far, JPEGs have been the commonest recordsdata representing NFTs, however these recordsdata can are available all kinds of codecs and kinds. That stated, these recordsdata are usually not the actual worth NFTs deliver to the desk. The last word treasure of NFTs lies of their distinctive encryption, which makes them excellent for representing distinctive digital or bodily objects. Furthermore, metadata hides in tokens’ on-chain signatures; therefore, it’s vital to know how you can get NFT metadata as a developer. That’s precisely why it’s best to study to work with the Moralis “getNFTMetadata” endpoint. 

Nonetheless, earlier than we take a better have a look at this superior NFT API endpoint and how you can put it to use, we have to cowl some fundamentals. As such, we’ll first guarantee you realize what NFT metadata is and the place it’s saved. With this concept underneath your belt, you’ll be capable of admire the convenience of at the moment’s process with the above-mentioned endpoint.

NFT metadata graph.

What Precisely is NFT Metadata?

By definition, metadata is information that gives details about different information. Accordingly, NFT metadata supplies details about the info associated to a non-fungible token. That stated, you have to perceive what NFTs are to know NFT metadata correctly.

Non-fungible tokens (NFTs) are distinctive kinds of blockchain belongings that aren’t interchangeable, as “non-fungible” suggests. Every NFT has a singular token ID, even when they use the identical NFT-representing file. Moreover, each NFT’s on-chain information is exclusive, which makes them good for digital artwork, digital collectibles, possession proofs, certificates, and so forth. 

Now, we propose you check out the above picture to get an excellent higher sense of what sort of particulars NFT metadata contains. Observe that the NFT-representing recordsdata are too giant for us to retailer them straight on the blockchain, each from technical and monetary views. Thus, we use cloud storage options (decentralized ones, ideally) to retailer these recordsdata. Then, we use the recordsdata’ location hyperlinks (URLs) and embrace them contained in the NFT metadata. So, whenever you study to get the info, you additionally study to get the NFT-representing recordsdata. 

In fact, there are different items of details about NFTs of their metadata recordsdata, which usually are available JSON format. The precise particulars {that a} particular metadata file contains differ relying on the NFT sort. Nonetheless, sure NFT requirements (ERC-721, ERC-1155, SPL, and so forth.) are set in place to supply pointers. As well as, there are some obligatory items of data and a few non-compulsory ones inside NFT metadata. As an example, within the case of ERC-721 or ERC-1155 NFTs, metadata often features a description, a reputation, and an NFT-representing file vacation spot, and you’ll even add attributes to NFTs or traits.  

The place is the Metadata of an NFT Saved?

Above, we talked about that recordsdata representing NFTs are too giant to be saved on a blockchain. Whereas NFT metadata recordsdata are usually rather a lot smaller, it’s nonetheless not sensible to retailer them straight on the blockchain. As an alternative, when minting NFTs (deploying NFT sensible contracts), we save the NFT metadata hyperlinks (URIs) on the blockchain. We additionally use cloud storage options to avoid wasting the NFT metadata recordsdata.

Moreover, it’s value mentioning that everybody concerned in Web3 growth ought to purpose for the best degree of decentralization. Thus, ideally, NFT builders ought to retailer all recordsdata and NFT metadata recordsdata utilizing decentralized storage options. Nonetheless, there are specific cases the place a venture can add worth to its customers by truly utilizing a centralized NFT metadata storage choice. With that stated, the precise location of recordsdata representing NFTs and NFT metadata varies from venture to venture.

As an example, NFT tasks that take decentralization severely retailer their NFT-representing recordsdata and their NFT metadata in some kind of decentralized cloud storage resolution. A well-liked selection is the InterPlanetary File System (IPFS) resolution. However, a extra centralized NFT venture would retailer its NFT recordsdata and metadata utilizing one of many centralized cloud storage providers. Nonetheless, a kind of hybrid between centralized and decentralized NFT tasks can be potential. In such instances, NFT metadata could possibly be saved in a decentralized method, whereas NFT-representing recordsdata could be saved utilizing a centralized storage resolution or vice versa.

Moreover, it’s value mentioning that regardless of the place you retailer recordsdata and NFT metadata, the precise tokens are nonetheless minted on a blockchain. Thus, their contract addresses and IDs are immutable. Furthermore, whenever you wish to get NFT metadata, you don’t want to know the place it’s saved.

Easy methods to Get NFT Metadata

Because of the above-covered particulars about NFT metadata, you now know that to get NFT metadata, it is advisable to search for NFTs’ URI hyperlinks that time to JSON recordsdata. Moreover, you additionally know that these URIs comprise all the main points, together with the URLs of the related NFT-representing recordsdata. As such, if you’re not planning on doing any programming round NFTs, you’ll be able to merely use blockchain explorers or NFT marketplaces to get the metadata of an NFT. Nonetheless, you can even use the Moralis “getNFTMetadata” endpoint’s documentation web page. Since we’ll use that endpoint within the upcoming tutorial, let’s take a better have a look at it collectively:

Documentation page to get NFT metadata showing the getNFTMetadata endpoint.

Trying on the above screenshot, you’ll be able to see that this endpoint enables you to take a look at the script and replica the snippet of code that matches your most well-liked programmable language. Additionally, you’ll be able to see that with the intention to get the NFT metadata of an NFT, it is advisable to enter some parameters. An NFT sensible contract handle and token ID are required, whereas “chain“, “format“, and “normalizeMetadata” are non-compulsory. So, be certain that to acquire your Moralis Web3 API key (see the “Step 1: Set Up Moralis” part under) and take the “getNFTMetadata” endpoint for a spin.

Nonetheless, notice that “getNFTMetadata” is simply one of many final NFT API endpoints. Therefore, we encourage you to discover the Moralis documentation to study extra about this highly effective instrument. In any case, these endpoints are your ticket to constructing all kinds of NFT dapps the straightforward approach. Except for getting NFT metadata, you can even get possession information, NFT switch information, NFT costs, and extra. To supply your customers a neat option to authenticate themselves, be certain that to take a look at the Moralis Web3 Auth API. Additionally, with Web3 streams, customers can stream blockchain information straight to their backend!

Tutorial – Easy methods to Get the Metadata of an NFT

Now that you realize the idea behind getting NFT metadata, it’s time you get your palms soiled. So, be certain that to finish the three steps outlined within the following sections. Nonetheless, earlier than you’ll be able to sort out these steps, it is advisable to full the next conditions:

Set up your favourite package deal supervisor (npm, yarn, or pnpm).Put together your favourite IDE or code editor. We favor to make use of Visible Studio Code (VSC).Set up Node v.14 or increased.

If in case you have the entire above instruments in place, you’re prepared to make use of the “getNFTMetadata” endpoint to get the metadata of an NFT. 

Step 1: Set Up Moralis  

You want your Moralis Web3 API key to make use of the last word NFT API. Fortuitously, you get to acquire that key out of your Moralis admin space. To entry the latter, it is advisable to create a free Moralis account. Therefore, use the “free Moralis account” hyperlink said on the outset of this text or click on on the “Begin for Free” button within the top-right nook of the Moralis homepage:

Whichever path you select, you’ll land on the register web page. There, merely enter your particulars. Together with your full title, electronic mail handle, and password in place, settle for the phrases and circumstances and click on on the “Signal Up” button:

Final however not least, don’t overlook to substantiate your account by way of the affirmation hyperlink that awaits you in your electronic mail inbox.

Together with your account up and working, you get to entry your Moralis admin space. From there, you’ll be capable of copy your Web3 API key within the following two steps:

Maintain on to your API key for now. First, set up the Moralis SDK by working one of many instructions under. Select the one which matches the package deal supervisor that you’re utilizing:

npm set up moralisyarn add moralispnpm add moralis

Step 2: Utilizing an Instance Script

On this part, we’ll give you an instance script that lets you get the metadata of an NFT with only a few traces of code. As such, that is an instance “index.js” script that fetches NFT metadata:

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 tokenId = 3931;

const response = await Moralis.EvmApi.nft.getNFTMetadata({



Observe: In case you’d quite work with TypeScript, observe the “documentation web page” hyperlink above and choose “index.ts”.

Trying on the above traces of code, you’ll be able to see “EvmChain.ETHEREUM“. In case you keep in mind, that is an non-compulsory parameter that the “getNFTMetadata” endpoint takes in. Moreover, this parameter defines the chain the NFT we goal is saved on. Since we’re specializing in a CryptoPunk NFT with ID 3931, we have to concentrate on the Ethereum chain. Nonetheless, should you have been to discover NFTs on different chains, you’d merely want to exchange “ETHEREUM” with one other chain. In that case, be certain that to take a look at Moralis’ supported EVM-compatible chains.

Additionally, don’t overlook to stick your Moralis Web3 API within the “YOUR_API_KEY” parameter.

Step 3: Executing the Program to Get NFT Metadata

At this level, it’s best to have your “index.js” or “index.ts” file prepared. As such, you’ll be able to execute this system to get NFT metadata for a selected handle and NFT token ID. To take action, use your terminal and enter one in all these two instructions:

For JavaScript:

node index.js

For TypeScript: 

node index.ts

When you execute the suitable command, have a look at your terminal to see what the code returns. In case you used the “0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB” handle and 3931 token ID, it’s best to see these outcomes:

“token_address”: “0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb”,
“token_id”: “3931”,
“transfer_index”: [
“owner_of”: “0x1cf2b8c64aed32bff2ae80e701681316d3212afd”,
“block_number”: “13868997”,
“block_number_minted”: “5754322”,
“token_hash”: “3c86855c82470edd82df190019e83f16”,
“quantity”: “1”,
“contract_type”: null,
“title”: “CRYPTOPUNKS”,
“image”: “Ͼ”,
“token_uri”: “”,
“metadata”: “{“picture”:””,”title”:”CryptoPunk 3931″,”attributes”:[“Vampire Hair”,”Goat”],”description”:”Male”}”,
“last_token_uri_sync”: null,
“last_metadata_sync”: “2022-05-12T18:00:22.340Z”,
“minter_address”: “0xc352b534e8b987e036a93539fd6897f53488e56a”

Trying on the outcomes above, you’ll be able to see that because of the ability of “getNFTMetadata“, you get the NFT’s metadata URI and all the main points included within the NFT metadata. As such, now you can simply make the most of these particulars in varied NFT dapps.

Get NFT Metadata – Easy methods to Get the Metadata of an NFT – Abstract

Right this moment’s article demonstrated how you can get NFT metadata with only a few traces of code. You additionally had an opportunity to study what NFT metadata is and the place we retailer it. As such, you now know you could retailer metadata within the type of JSON recordsdata with centralized or decentralized storage options. Then, you employ the URI hyperlinks to the metadata when minting the NFTs. Therefore, NFT metadata itself just isn’t saved on the blockchain however solely its URI hyperlink. Furthermore, you additionally noticed that by utilizing the Moralis “getNFTMetadata” endpoint, you might extract all the main points from contained in the metadata. Therefore, you at the moment are able to create some killer NFT dapps.

In case you want some apply or steerage with creating your dapps, be certain that to make use of Moralis’ sources. Use the Moralis docs to discover the last word Web3 API. There, you can even discover varied beginner-friendly tutorials. Nonetheless, if you’re all in favour of studying extra about blockchain growth, the Moralis YouTube channel and the Moralis weblog are the locations to be. There we cowl numerous subjects that may allow you to develop into a Web3 developer without spending a dime. As an example, a few of our newest articles revolve round constructing a Discord bot for on-chain occasions, Solana sensible contract examples, how you can get all NFTs from a contract, crypto pockets integration, integrating Web3 infrastructure, what Ethereum webhooks are, and rather more!

It’s additionally value mentioning that the blockchain business gives numerous job alternatives, and you’ll drastically enhance your probabilities of going full-time crypto by changing into blockchain-certified. If that pursuits you, be certain that to contemplate enrolling in Moralis Academy. There, you’ll discover all kinds of blockchain growth programs, from newbie to superior. That stated, we suggest beginning with blockchain and Bitcoin fundamentals.

Source link

Stay in the Loop

Get the daily email from CryptoNews that makes reading the news actually enjoyable. Join our mailing list to stay in the loop to stay informed, for free.

Latest stories

- Advertisement - spot_img

You might also like...