Skip to main content

Don't have an API key yet?

Sign-up to Moralis to get your free API key and start building today.

Get Your Free API Key
Version: 2.0

How to get all the NFT collections owned by an address

Prerequisites​

Before getting started, make sure you have the following ready:

  • Node v.14+ or Python
  • NPM/Yarn or Pip

Step 1: Setup Moralis​

First register your Moralis account and get your Moralis API Key.

Once you have your Moralis API Key, install the Moralis SDK in your project.

npm install moralis @moralisweb3/common-evm-utils

Step 2: Get All NFTs Collections Owned By An Address​

In order to get all the NFTs owned by an address, Moralis provides you with a getWalletNFTCollections endpoint to do so.

Here you'll need two parameters: address and chain.

Once you've obtained both the address and chain, you can copy the following code:

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});

const address = "0x26fcbd3afebbe28d0a8684f790c48368d21665b5";

const chain = EvmChain.ETHEREUM;

const response = await Moralis.EvmApi.nft.getWalletNFTCollections({
address,
chain,
});

console.log(response.toJSON());
};

runApp();

Step 3: Run the script​

To run the script, enter the following command:

node index.js

In your terminal, you should see the following JSON response:

{
"total": 503,
"page": 1,
"page_size": 100,
"cursor": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjdXN0b21QYXJhbXMiOnsid2FsbGV0QWRkcmVzcyI6IjB4ZDhkYTZiZjI2OTY0YWY5ZDdlZWQ5ZTAzZTUzNDE1ZDM3YWE5NjA0NSJ9LCJrZXlzIjpbIjE2NTg2ODUyMDMuNzExIl0sIndoZXJlIjp7Im93bmVyX29mIjoiMHhkOGRhNmJmMjY5NjRhZjlkN2VlZDllMDNlNTM0MTVkMzdhYTk2MDQ1In0sImxpbWl0IjoxMDAsIm9mZnNldCI6MCwib3JkZXIiOltdLCJ0b3RhbCI6NTAzLCJwYWdlIjoxLCJ0YWlsT2Zmc2V0IjoxLCJpYXQiOjE2NjY4MDE3OTV9.wdLubHbqnGg36awXqwlJ7cnsdIX5DHDDnArnva72W5I",
"result": [
{
"token_address": "0xff8852a5f77c20094f0fabc7b225b417e0797907",
"contract_type": "ERC721",
"name": "VictoriasSecret",
"symbol": "VS"
},
{
"token_address": "0xff66f3c087b0e8e0d1349cadb218efd7bcf0ac99",
"contract_type": "ERC721",
"name": "Flower Shoppe",
"symbol": "FLWRSHP"
},
{
"token_address": "0xfeddc1448eb4480714a9942ba28a27b16caf9ce4",
"contract_type": "ERC721",
"name": "Impervious Registry",
"symbol": "IR"
},
{
"token_address": "0xfec64651c8b441f2526b1a54febb2122124bf041",
"contract_type": "ERC721",
"name": "Porsche",
"symbol": "Porsche"
}
],
"status": "SYNCED"
}

Congratulations πŸ₯³ you just got all the NFT collections owned by an address with just a few lines of code using the Moralis NFT API!

Youtube Video​

API Reference​

If you want to know more details on the endpoint and optional parameters, check out:

Next Steps​

Learn how to use the Moralis NFT API to build dapps:

Support​

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.