How to get all the NFT collections owned by an address
Step 1: Setup Moralisβ
Read the article Setting Up Moralis: Getting Started and make sure to finish all the steps. Only after that you can go ahead to complete this guide.
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:
- index.js (JavaScript)
- index.ts (TypeScript)
- index.py (Python)
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();
import Moralis from "moralis";
import { EvmChain } from "@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();
from moralis import evm_api
api_key = "YOUR_API_KEY"
params = {
"address": "0x26fcbd3afebbe28d0a8684f790c48368d21665b5",
"chain": "eth",
"limit": 100,
"cursor": "",
}
result = evm_api.nft.get_wallet_nft_collections(
api_key=api_key,
params=params,
)
print(result)
Step 3: Run the scriptβ
To run the script, enter the following command:
- Shell (JavaScript)
- Shell (TypeScript)
- Shell (Python)
node index.js
ts-node index.ts
python index.py
In your terminal, you should see the following JSON response:
{
"status": "SYNCED",
"page": 1,
"cursor": null,
"page_size": 100,
"result": [
{
"token_address": "0xfbc6f43c1d382da5f4dda34ae542bdd460423be5",
"possible_spam": true,
"contract_type": "ERC1155",
"name": "Toy Booger NFT",
"symbol": "Toy Booger NFT",
"verified_collection": false,
"collection_logo": "https://i.seadn.io/gae/eQ_ObnigEZr8aalXL71GO_3Cs6xGrIiNKRKtbvPS9d-OAIgQeBkqGyjtKZMcu4DuVaknkuk0_E4TtIpjs0UIe3cFBJmHXV5-mitjrw?w=500&auto=format",
"collection_banner_image": "https://i.seadn.io/gae/YjIHBPaMmBU1m-CHjZwcLNGhxhgDoJrSrXZCZi3xvBaGJKM-FQISrKzsWHdFoLifl-IzEWuVZ8uJLelUSE6oOjoxaizyswbI5wmkjFg?w=500&auto=format"
},
{
"token_address": "0xedc79f027bba6cfac31e21dc8b4c2c0b20866e31",
"possible_spam": true,
"contract_type": "ERC1155",
"name": "Bulls on Block",
"symbol": "Bulls on Block",
"verified_collection": false,
"collection_logo": "https://i.seadn.io/gae/WD6FfHhFGcmBlLsXlzFgq4Za8TlC5065GRUJwXjnRgUpkMrLLr8-SMcVgRzUnuxtKZ8mXcwvG_iydceIDJ2_NGxMTil0uWnB8i4IFg?w=500&auto=format",
"collection_banner_image": "https://i.seadn.io/gae/-zlLbVdkSG_IA9p_fJxajDyBA6SyzQ1_Q4lwFkpan_NM51rk7NsEM6Drs6sMaCkZP7QEfVNRYOLl7o-GLQzd4ShDWNZiTf6BHx-m?w=500&auto=format"
},
{
"token_address": "0xe786b5596a792d7beafcf08eaf9de711c7b7b14b",
"possible_spam": true,
"contract_type": "ERC721",
"name": "Gutter Punks - Otherside",
"symbol": "GPO",
"verified_collection": false,
"collection_logo": "https://i.seadn.io/gae/gqgi2DFDHPBBjsshtyPe2cN019JZmML8gBfy1Hg5LhOEckX-BRPLqWfQf_xqGyWB9YtFefq5jh35JIp-YSadq8fN9rlZKS-N6TK8?w=500&auto=format",
"collection_banner_image": null
},
{
"token_address": "0xe7198926b9f9b4ca0c7b2cc0cfb25b36f0dc7e45",
"possible_spam": true,
"contract_type": "ERC1155",
"name": "ZED RUN",
"symbol": "ZED RUN",
"verified_collection": false,
"collection_logo": "https://i.seadn.io/gae/jLDu2mpSekG6RxJI_XgVi4Uhf3NFZ5thkJrNwVXkbL3c7fKwQoxJSGiiolCjIijUPBf8_QtoDMLPla6PyDEo4mcDIysTp1LVp5s3tlU?w=500&auto=format",
"collection_banner_image": "https://i.seadn.io/gae/zSwvUVqzZpMjyOTiAQCtkb9Uw-G3O-j4Iilmb_QfcMSMMS4V9rNUjBs4icxxDzEfk1kMiwijCiT3tDxWBXDs-gI1TFyT6I6KaG20P70?w=500&auto=format"
},
...
}
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.