As we speak’s article will present you get a consumer’s NFT tokens checklist with the Moralis NFT API. Due to the facility of this instrument, you solely want a single API name to the getWalletNFTs() endpoint to take action. Under, you will discover the code exhibiting an instance of the way it works in apply:
const Moralis = require(“moralis”).default;
const { EvmChain } = require(“@moralisweb3/common-evm-utils”);
const runApp = async () => {
await Moralis.begin({
apiKey: “YOUR_API_KEY”,
// …and some other configuration
});
const tackle = “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”;
const chain = EvmChain.ETHEREUM;
const response = await Moralis.EvmApi.nft.getWalletNFTs({
tackle,
chain,
});
console.log(response.toJSON());
};
runApp();
You merely want so as to add your Moralis API key, configure the tackle and chain parameters, and execute the code. In return, you’ll obtain a response containing an array of NFTs. And it may well look one thing like this:
{
“whole”: 1456,
“web page”: 1,
“page_size”: 100,
“cursor”: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsid2FsbGV0QWRkcmVzcyI6IjB4ZDhkYTZiZjI2OTY0YWY5ZDdlZWQ5ZTAzZTUzNDE1ZDM3YWE5NjA0NSJ9LCJrZXlzIjpbIjE2NjMyMzgxNzUuMDc3Il0sIndoZXJlIjp7Im93bmVyX29mIjoiMHhkOGRhNmJmMjY5NjRhZjlkN2VlZDllMDNlNTM0MTVkMzdhYTk2MDQ1In0sImxpbWl0IjoxMDAsIm9mZnNldCI6MCwib3JkZXIiOltdLCJ0b3RhbCI6MTQ1NiwicGFnZSI6MSwidGFpbE9mZnNldCI6MSwiaWF0IjoxNjY2NjgyNTUyfQ.E5DkWYvRTaFnVhgedRuT3IW-rb2V-ikFKwP2cg2Qf78”,
“consequence”: [
{
“token_address”: “0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85”,
“token_id”: “4765809967066625256798886812262830659450023020194524584471225959000376492819”,
“amount”: “1”,
“owner_of”: “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”,
“token_hash”: “ba6d44b5f16be94283cecffeb784b7ca”,
“block_number_minted”: “15572796”,
“block_number”: “15573017”,
“contract_type”: “ERC721”,
“name”: “Ethereum Name Service”,
“symbol”: “ENS”,
“token_uri”: null,
“metadata”: null,
“last_token_uri_sync”: null,
“last_metadata_sync”: “2022-09-20T06:06:08.153Z”,
“minter_address”: null
},
{
“token_address”: “0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85”,
“token_id”: “84453794918345416145331514647027903846664455083247396107154093349515123913389”,
“amount”: “1”,
“owner_of”: “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”,
“token_hash”: “7c0212cd3daf1b6b64f193c6dc102fb4”,
“block_number_minted”: “15572811”,
“block_number”: “15573017”,
“contract_type”: “ERC721”,
“name”: “Ethereum Name Service”,
“symbol”: “ENS”,
“token_uri”: null,
“metadata”: null,
“last_token_uri_sync”: null,
“last_metadata_sync”: “2022-09-20T06:09:09.838Z”,
“minter_address”: null
}
],
“standing”: “SYNCED”
}
To be taught extra about how this works, be part of us on this article as we break down the method in additional element. Or take a look at our official get NFTs by pockets documentation!
Additionally, earlier than we proceed, don’t neglect to enroll in free with Moralis to entry the {industry}’s main NFT API. In doing so, you can begin leveraging the complete energy of the Web3 {industry} instantly and construct your subsequent NFT undertaking in a heartbeat!
Overview
It doesn’t matter if you happen to’re constructing a Web3 pockets, NFT market, or a blockchain-based gaming platform; likelihood is you’ll have to fetch all NFT tokens owned by your customers. Nonetheless, to get a consumer NFT tokens checklist on a blockchain like Ethereum, you would need to parse the whole community, observe ERC-721 good contracts, and get the most recent possession information for every token. This requires a large quantity of engineering time and sources. Luckily, now you can bypass this by leveraging the Moralis NFT API. As an example the facility of this instrument, we’ll take right now’s article to point out you get all tokens owned by a consumer tackle!
Nonetheless, earlier than we dive into the primary subject, we’ll kick issues off by taking a look at what an NFT API is. From there, we’ll introduce the Moralis NFT API to focus on why that is the most effective instrument to get a consumer NFT tokens checklist. After that, we’ll bounce straight into the tutorial and present you get all NFT tokens owned by a consumer tackle in three steps:
Step 1: Arrange MoralisStep 2: Name the getWalletNFTs() EndpointStep 3: Run the Code
When you’re already conversant in the ins and outs of NFT APIs, be at liberty to skip straight into the ”Get an NFT Tokens Record of a Consumer in 3 Steps” part!
Lastly, we’ll high issues off by exploring some outstanding use circumstances the place you want to get all NFTs owned by a consumer tackle.
If this sounds intriguing, be part of us on this article as we start by leaping straight into the intricacies of NFT APIs!
What’s an NFT API?
An NFT API – quick for software programming interface – is a set of protocols and guidelines permitting software program programs to entry and work together with on-chain information associated to non-fungible tokens. One of many details of an NFT API is to summary the complexities of querying blockchain networks by introducing a developer-friendly interface that means that you can seamlessly purchase NFT-related information and combine it into your initiatives.
NFT APIs typically supply a variety of options, empowering builders to create modern companies and functions revolving round NFTs. Yow will discover some frequent capabilities of NFT APIs beneath:
Get NFTs Owned by Handle: Most NFT API companies help you seamlessly question the NFT stability of any tackle. Fetch NFT Metadata: NFTs normally have metadata hooked up to them. This data features a title, description, and different attributes. With an NFT API, you possibly can seamlessly get this data straight from the blockchain. Occasion Monitoring: NFT APIs usually present real-time occasion monitoring, permitting you to remain up to date relating to numerous actions throughout the NFT house. This consists of all the things from new listings to token gross sales. Get Switch Knowledge: With an NFT API, you will get the most recent NFT switch information in actual time. These interfaces additionally make it doable to question historic transaction information. Fetch Market Knowledge: Some NFT APIs help integrations with main marketplaces, permitting you to retrieve pricing information, details about trending collections, and extra.
However, now that you’ve got an summary of NFT APIs, let’s introduce you to the best solution to get all tokens owned by a consumer tackle!
How you can Get a Consumer NFT Tokens Record?
There are a number of NFT APIs to select from if you wish to get a consumer NFT tokens checklist. Nonetheless, the best choice is Moralis’ industry-leading NFT API!
The Moralis NFT API helps over three million NFT collections (and counting) throughout greater than ten EVM-compatible chains. This consists of established initiatives like CryptoPunks, Pudgy Penguins, and so on., together with NFTs that dropped just some seconds in the past!
So, what are you able to do with the NFT API?
Due to the accessibility of this instrument, you possibly can, amongst different issues, do the next with a single line of code:
Get NFTs by Assortment or Pockets: Simplify the event of your NFT initiatives by effortlessly fetching all NFTs from a given assortment or pockets. Fetch NFT Metadata: Get NFT metadata, together with a token’s identify, description, photos, traits, and extra, with a single API name. When you’d wish to be taught extra about this, take a look at our article on get ERC-721 on-chain metadata! Monitor NFT Trades by Market: Keep knowledgeable about NFT market dynamics by monitoring tokens throughout main platforms like OpenSea and Rarible. Retrieve NFT Possession Knowledge: Retrieve and verify NFT possession information on the token or assortment stage with ease.
To be taught extra about how the Moralis NFT API works and why that is the most suitable choice in the marketplace, be part of us within the subsequent part as we present you get a consumer NFT tokens checklist in three simple steps!
Get a Consumer NFT Tokens Record in 3 Steps
The Moralis NFT API is very easy to make use of, and to get a consumer NFT tokens checklist, all you want is just a few strains of code and a single API name. To spotlight this accessibility, we’ll present you get all NFTs owned by a consumer tackle in three steps:
Step 1: Arrange MoralisStep 2: Name the getWalletNFTs() EndpointStep 3: Run the Code
However earlier than we bounce into the tutorial, you will need to take care of a few conditions!
Stipulations
Earlier than you will get a consumer NFT tokens checklist, you initially have to have the next put in and prepared:
Moreover, you can too go forward and arrange a brand new undertaking and open it along with your built-in growth atmosphere (IDE). From there, open a brand new terminal and run the next command within the undertaking’s root folder to put in the Moralis SDK:
npm set up moralis @moralisweb3/common-evm-utils
That’s it for the conditions. You’re now able to proceed with the tutorial. As such, with out additional delay, let’s bounce straight into step one and present you arrange Moralis!
Step 1: Set Up Moralis
Earlier than you may make calls to the Moralis NFT API, you want entry to your Moralis API key, and to get an API key, you want a Moralis account. That stated, you possibly can arrange an account without spending a dime by clicking on the ”Begin for Free” button on the high proper of the Moralis homepage:
After establishing your account and your Moralis undertaking, you will discover your key by going to the ”Web3 APIs” tab and clicking on the ”Get your API keys” button:
This takes you to the next web page, and you’ll go forward and duplicate your API key and preserve it for the second half:
That’s it for the preliminary step. Let’s now present you implement the code for getting a consumer NFT tokens checklist!
Step 2: Name the getWalletNFTs() Endpoint
For this tutorial, we’ll be utilizing JavaScript to fetch all NFTs owned by a consumer tackle. As such, you possibly can proceed by creating an ”index.js” file in your undertaking’s root folder. From there, you possibly can copy and paste the code beneath:
const Moralis = require(“moralis”).default;
const { EvmChain } = require(“@moralisweb3/common-evm-utils”);
const runApp = async () => {
await Moralis.begin({
apiKey: “YOUR_API_KEY”,
// …and some other configuration
});
const tackle = “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”;
const chain = EvmChain.ETHEREUM;
const response = await Moralis.EvmApi.nft.getWalletNFTs({
tackle,
chain,
});
console.log(response.toJSON());
};
runApp();
Subsequent, be certain to interchange YOUR_API_KEY with the API key you copied within the earlier step:
From right here, add the pockets tackle you wish to get the NFTs from to the tackle const and configure chain if you wish to question one other blockchain community:
We then move the tackle and chain constants as parameters when calling the getWalletNFTs() endpoint:
That’s it! We solely want a single API name to the getWalletNFTs() endpoint to get a consumer NFT tokens checklist when working with Moralis!
From right here, we simply have to run the code above!
Step 3: Run the Code
Working the code is straightforward, and also you solely have to open a brand new terminal, enter the command beneath, and hit enter:
node index.js
While you run the code, you’ll be supplied with an array of NFTs wanting one thing like this:
{
“whole”: 1456,
“web page”: 1,
“page_size”: 100,
“cursor”: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsid2FsbGV0QWRkcmVzcyI6IjB4ZDhkYTZiZjI2OTY0YWY5ZDdlZWQ5ZTAzZTUzNDE1ZDM3YWE5NjA0NSJ9LCJrZXlzIjpbIjE2NjMyMzgxNzUuMDc3Il0sIndoZXJlIjp7Im93bmVyX29mIjoiMHhkOGRhNmJmMjY5NjRhZjlkN2VlZDllMDNlNTM0MTVkMzdhYTk2MDQ1In0sImxpbWl0IjoxMDAsIm9mZnNldCI6MCwib3JkZXIiOltdLCJ0b3RhbCI6MTQ1NiwicGFnZSI6MSwidGFpbE9mZnNldCI6MSwiaWF0IjoxNjY2NjgyNTUyfQ.E5DkWYvRTaFnVhgedRuT3IW-rb2V-ikFKwP2cg2Qf78”,
“consequence”: [
{
“token_address”: “0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85”,
“token_id”: “4765809967066625256798886812262830659450023020194524584471225959000376492819”,
“amount”: “1”,
“owner_of”: “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”,
“token_hash”: “ba6d44b5f16be94283cecffeb784b7ca”,
“block_number_minted”: “15572796”,
“block_number”: “15573017”,
“contract_type”: “ERC721”,
“name”: “Ethereum Name Service”,
“symbol”: “ENS”,
“token_uri”: null,
“metadata”: null,
“last_token_uri_sync”: null,
“last_metadata_sync”: “2022-09-20T06:06:08.153Z”,
“minter_address”: null
},
{
“token_address”: “0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85”,
“token_id”: “84453794918345416145331514647027903846664455083247396107154093349515123913389”,
“amount”: “1”,
“owner_of”: “0xd8da6bf26964af9d7eed9e03e53415d37aa96045”,
“token_hash”: “7c0212cd3daf1b6b64f193c6dc102fb4”,
“block_number_minted”: “15572811”,
“block_number”: “15573017”,
“contract_type”: “ERC721”,
“name”: “Ethereum Name Service”,
“symbol”: “ENS”,
“token_uri”: null,
“metadata”: null,
“last_token_uri_sync”: null,
“last_metadata_sync”: “2022-09-20T06:09:09.838Z”,
“minter_address”: null
}
],
“standing”: “SYNCED”
}
Congratulations, you now know get a consumer NFT tokens checklist with Moralis!
From right here, now you can combine this performance into your future initiatives and begin constructing extra subtle NFT-based platforms!
Consumer NFT Tokens Record – Use Instances
The non-fungible attribute of NFTs makes them excellent for representing possession of distinctive gadgets. NFTs enable folks to tokenize all the things from digital artwork to actual property. This makes these tokens extremely dynamic, and the expertise is relevant in lots of conditions. However when do you truly have to get all NFT tokens owned by a consumer tackle? To reply this query, we’ll discover three examples of outstanding use circumstances when you want to get a consumer NFT tokens checklist!
Web3 Wallets
Web3 wallets – additionally known as crypto wallets – are digital platforms for storing property like fungible and non-fungible tokens. There are a number of outstanding pockets suppliers, and a few examples embody MetaMask, Phantom Pockets, and Rainbow.
A superb pockets wants to provide customers an summary of all their property, which means that these platforms want a simple and accessible solution to fetch all tokens owned by a consumer tackle. Consequently, when constructing a Web3 pockets, an NFT API just like the one Moralis provides can are available fairly helpful.
For example, an already completely satisfied consumer of Moralis’ NFT API is the industry-leading Web3 pockets supplier MetaMask:
DeFi Platforms
Some DeFi platforms – which is an abbreviation for decentralized finance – use NFTs as collateral. On these platforms, customers have the choice to make use of their NFTs to borrow cryptocurrencies like DAI, USDC, and so on. Some DeFi initiatives additionally present further options, such because the fractionalization of NFTs.
When you’d wish to be taught extra about this, please take a look at our article on fractional NFTs!
With the intention to present this performance, DeFi platforms have to entry the NFT balances of customers, partly to show the tokens they maintain. But in addition to permit customers to truly put up their NFTs as collateral, fractionalize them, and so on. Consequently, when constructing a DeFi platform like this, you want a simple solution to get a consumer NFT tokens checklist.
NFT Marketplaces
NFT marketplaces are digital platforms that enable customers to retailer, promote, purchase, show, and even mint NFTs. Some already present marketplaces embody Rarible, SuperRare, and OpenSea.
When constructing an NFT market, you will need to be capable of fetch the NFT tokens checklist of a consumer. This may, as an illustration, help you seamlessly show all tokens of their pockets in order that they know what property they will checklist and promote.
To offer you a fair clearer instance, take a look at the next testimonial from NFTrade – a outstanding NFT market already leveraging the Moralis NFT API:
Abstract: How you can Get the NFT Tokens Record of a Consumer with Moralis
In right now’s article, we confirmed you get a consumer NFT tokens checklist with the Moralis NFT API in three steps:
Step 1: Arrange MoralisStep 2: Name the getWalletNFTs() EndpointStep 3: Run the Code
Consequently, in case you have adopted alongside this far, you now know get all NFTs owned by a pockets tackle. From right here, you possibly can combine this performance into your future initiatives and construct NFT-based functions in a heartbeat!
When you preferred this information, contemplate testing extra content material right here on the Web3 weblog. For example, find out about OpenSea fuel charges or dive into the ins and outs of a Linea Goerli faucet.
You too can discover some further instruments Moralis provides. For instance, take a look at the {industry}’s main crypto Value API and Web3 Pockets API, or discover ways to arrange Web3 webhooks with the Moralis Streams API!
Additionally, don’t neglect to enroll with Moralis to entry these wonderful growth instruments. You’ll be able to create your Moralis account without spending a dime and begin constructing your subsequent undertaking within the blink of an eye fixed!