NFT API Quickstart

Go from zero to hero with the Alchemy NFT API. Learn how to query NFT data, then dive into some fun tutorials!

Don't have an API key?

Start using the NFT API in your app today. Get started for free

Getting Started Instructions

Follow along with the steps below to get started with the NFT API:

  1. Choose a package manager

  2. Set up your repo

  3. Choose a library

    1. Alchemy SDK (recommended)
    2. Node-Fetch
    3. Axios

1. Choose a package manager

For this guide, we will be using npm or yarn as our package manager to install either alchemy-sdk, fetch, or axios.

npm

To get started with npm, follow the documentation to install Node.js and npm for your operating system: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

yarn

To get started with yarn, follow these steps: https://classic.yarnpkg.com/lang/en/docs/install

2. Set up your repo

npm

Open up a terminal, and from the command line, create a new repository to hold your quickstart scripts. We’ll also initialize the repo as an npm project.

shell
$mkdir alchemy-nft-api
>cd alchemy-nft-api
>npm init --yes

yarn

shell
$mkdir alchemy-nft-api
>cd alchemy-nft-api
>yarn init --yes

Since we’ll be using import syntax to load ES6 modules, add 'type': 'module' to your package.json file:

See this discussion for more context.


3. Choose a Library

You can install the alchemy-sdk-js module to easily interact with Alchemy APIs. We highly recommend using the Alchemy SDK because you also get WebSocket support, retries, and other benefits without the complexity!

For full documentation on alchemy-sdk-js, check the GitHub repo:

View the Alchemy SDK on GitHub

Installation

Run the following command to install alchemy-web3 with npm and yarn

$npm install alchemy-sdk

Demo Script

View the demo script on GitHub

The demo script for the Alchemy SDK

In your alchemy-nft-api directory, you can create a new file called alchemy-sdk-script.js using your favorite file browser, code editor, or just directly in the terminal using the touch command like this:

shell
$touch alchemy-sdk-script.js

and then paste the following code snippet into the file:

alchemy-sdk-script.js
1// This script demonstrates access to the NFT API via the Alchemy SDK.
2import { Network, Alchemy } from "alchemy-sdk";
3
4// Optional Config object, but defaults to demo api-key and eth-mainnet.
5const settings = {
6 apiKey: "demo", // Replace with your Alchemy API Key.
7 network: Network.ETH_MAINNET, // Replace with your network.
8};
9
10const alchemy = new Alchemy(settings);
11
12// Print owner's wallet address:
13const ownerAddr = "vitalik.eth";
14console.log("fetching NFTs for address:", ownerAddr);
15console.log("...");
16
17// Print total NFT count returned in the response:
18const nftsForOwner = await alchemy.nft.getNftsForOwner("vitalik.eth");
19console.log("number of NFTs found:", nftsForOwner.totalCount);
20console.log("...");
21
22// Print contract address and tokenId for each NFT:
23for (const nft of nftsForOwner.ownedNfts) {
24 console.log("===");
25 console.log("contract address:", nft.contract.address);
26 console.log("token ID:", nft.tokenId);
27}
28console.log("===");
29
30// Fetch metadata for a particular NFT:
31console.log("fetching metadata for a Crypto Coven NFT...");
32const response = await alchemy.nft.getNftMetadata(
33 "0x5180db8F5c931aaE63c74266b211F580155ecac8",
34 "1590"
35);
36
37// Uncomment this line to see the full api response:
38// console.log(response);
39
40// Print some commonly used fields:
41console.log("NFT name: ", response.title);
42console.log("token type: ", response.tokenType);
43console.log("tokenUri: ", response.tokenUri.gateway);
44console.log("image url: ", response.rawMetadata.image);
45console.log("time last updated: ", response.timeLastUpdated);
46console.log("===");

From your command line, you can execute the script with:

shell
$node alchemy-sdk-script.js

You should see output like this:

shell
$node alchemy-sdk-script.js  ✔  4s
>fetching NFTs for address: vitalik.eth
>...
>number of NFTs found: 516
>...
>===
>contract address: 0x000386e3f7559d9b6a2f5c46b4ad1a9587d59dc3
>token ID: 29
>===
>contract address: 0x000386e3f7559d9b6a2f5c46b4ad1a9587d59dc3
>token ID: 238
>===
>...........
>===
>fetching metadata for a Crypto Coven NFT...
>NFT name: balsa vault
>token type: ERC721
>tokenUri: https://alchemy.mypinata.cloud/ipfs/QmaXzZhcYnsisuue5WRdQDH6FDvqkLQX1NckLqBYeYYEfm/1590.json
>image url: https://cryptocoven.s3.amazonaws.com/a7875f5758f85544dcaab79a8a1ca406.png
>time last updated: 2022-06-23T06:48:33.229Z
>===

For full documentation on the available endpoints for alchemy-sdk, check the github repo:

View the Alchemy SDK on GitHub

b) Node-Fetch

node-fetch is a lightweight, common module that brings the Fetch API to Node.js and allows us to make our HTTP requests.

See the documentation for more info: https://www.npmjs.com/package/node-fetch

Installation

Run the following command to install node-fetch with npm and yarn

$npm install node-fetch

Demo Script

View the demo script on GitHub

In your alchemy-nft-api directory, you can create a new file called fetch-script.js using your favorite file browser, code editor, or just directly in the terminal using the touch command like this:

fetch-script.js
$touch fetch-script.js

and then paste the following code snippet in to explore the getNFTs or getNFTMetadata methods:

1// alchemy-nft-api/fetch-script.js
2import fetch from 'node-fetch';
3
4// Setup request options:
5var requestOptions = {
6 method: 'GET',
7 redirect: 'follow'
8};
9
10// Replace with your Alchemy API key:
11const apiKey = "demo";
12const baseURL = `https://eth-mainnet.g.alchemy.com/nft/v3/${apiKey}/getNFTsForOwner/`;
13// Replace with the wallet address you want to query:
14const ownerAddr = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
15const pageSize = 2;
16const fetchURL = `${baseURL}?owner=${ownerAddr}&pageSize=${pageSize}`;
17
18// Make the request and print the formatted response:
19fetch(fetchURL, requestOptions)
20 .then(response => response.json())
21 .then(response => JSON.stringify(response, null, 2))
22 .then(result => console.log(result))
23 .catch(error => console.log('error', error));

From your command line, you can execute the script with:

shell
$node fetch-script.js

Your output should look like the following:

1{
2 "ownedNfts": [
3 {
4 "contract": {
5 "address": "0x000386E3F7559d9B6a2F5c46B4aD1A9587D59Dc3",
6 "name": "Bored Ape Nike Club",
7 "symbol": "BANC",
8 "totalSupply": null,
9 "tokenType": "ERC721",
10 "contractDeployer": "0x51D7D428041E23ef51422e110dfEfF906e821CFe",
11 "deployedBlockNumber": 14276343,
12 "openSeaMetadata": {
13 "floorPrice": null,
14 "collectionName": "BoredApeNikeClub",
15 "collectionSlug": "bored-ape-nike-club-v2",
16 "safelistRequestStatus": "not_requested",
17 "imageUrl": "https://i.seadn.io/gae/yJ9DgXqjRwgdCkrQmHj7krCbixM8fPVAyYJWJ5NHXap1L0c3QL5MPvrNT0QDINIStGOK857lOvab8MpNQS9X4pkHPktmhVmN82qoVw?w=500&auto=format",
18 "description": "COUNTDOWN OVER. MINTING LIVE.\n\n[Mint on the website.](https://nikemetaverse.xyz)\n",
19 "externalUrl": "https://nikemetaverse.xyz",
20 "twitterUsername": null,
21 "discordUrl": null,
22 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format",
23 "lastIngestedAt": "2023-10-30T07:13:52.000Z"
24 },
25 "isSpam": true,
26 "spamClassifications": [
27 "OwnedByMostHoneyPots",
28 "Erc721TooManyOwners",
29 "Erc721TooManyTokens",
30 "NoSalesActivity",
31 "HighAirdropPercent",
32 "HighHoneyPotPercent",
33 "HoneyPotsOwnMultipleTokens"
34 ]
35 },
36 "tokenId": "1",
37 "tokenType": "ERC721",
38 "name": null,
39 "description": null,
40 "tokenUri": "http://api.nikeapenft.xyz/ipfs/1",
41 "image": {
42 "cachedUrl": null,
43 "thumbnailUrl": null,
44 "pngUrl": null,
45 "contentType": null,
46 "size": null,
47 "originalUrl": null
48 },
49 "raw": {
50 "tokenUri": "http://api.nikeapenft.xyz/ipfs/1",
51 "metadata": {},
52 "error": null
53 },
54 "collection": {
55 "name": "BoredApeNikeClub",
56 "slug": "bored-ape-nike-club-v2",
57 "externalUrl": "https://nikemetaverse.xyz",
58 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format"
59 },
60 "mint": {
61 "mintAddress": null,
62 "blockNumber": null,
63 "timestamp": null,
64 "transactionHash": null
65 },
66 "owners": null,
67 "timeLastUpdated": "2023-11-06T04:34:38.880Z",
68 "balance": "26",
69 "acquiredAt": {
70 "blockTimestamp": null,
71 "blockNumber": null
72 }
73 },
74 {
75 "contract": {
76 "address": "0x000386E3F7559d9B6a2F5c46B4aD1A9587D59Dc3",
77 "name": "Bored Ape Nike Club",
78 "symbol": "BANC",
79 "totalSupply": null,
80 "tokenType": "ERC721",
81 "contractDeployer": "0x51D7D428041E23ef51422e110dfEfF906e821CFe",
82 "deployedBlockNumber": 14276343,
83 "openSeaMetadata": {
84 "floorPrice": null,
85 "collectionName": "BoredApeNikeClub",
86 "collectionSlug": "bored-ape-nike-club-v2",
87 "safelistRequestStatus": "not_requested",
88 "imageUrl": "https://i.seadn.io/gae/yJ9DgXqjRwgdCkrQmHj7krCbixM8fPVAyYJWJ5NHXap1L0c3QL5MPvrNT0QDINIStGOK857lOvab8MpNQS9X4pkHPktmhVmN82qoVw?w=500&auto=format",
89 "description": "COUNTDOWN OVER. MINTING LIVE.\n\n[Mint on the website.](https://nikemetaverse.xyz)\n",
90 "externalUrl": "https://nikemetaverse.xyz",
91 "twitterUsername": null,
92 "discordUrl": null,
93 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format",
94 "lastIngestedAt": "2023-10-30T07:13:52.000Z"
95 },
96 "isSpam": true,
97 "spamClassifications": [
98 "OwnedByMostHoneyPots",
99 "Erc721TooManyOwners",
100 "Erc721TooManyTokens",
101 "NoSalesActivity",
102 "HighAirdropPercent",
103 "HighHoneyPotPercent",
104 "HoneyPotsOwnMultipleTokens"
105 ]
106 },
107 "tokenId": "2",
108 "tokenType": "ERC721",
109 "name": null,
110 "description": null,
111 "tokenUri": "http://api.nikeapenft.xyz/ipfs/2",
112 "image": {
113 "cachedUrl": null,
114 "thumbnailUrl": null,
115 "pngUrl": null,
116 "contentType": null,
117 "size": null,
118 "originalUrl": null
119 },
120 "raw": {
121 "tokenUri": "http://api.nikeapenft.xyz/ipfs/2",
122 "metadata": {},
123 "error": null
124 },
125 "collection": {
126 "name": "BoredApeNikeClub",
127 "slug": "bored-ape-nike-club-v2",
128 "externalUrl": "https://nikemetaverse.xyz",
129 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format"
130 },
131 "mint": {
132 "mintAddress": null,
133 "blockNumber": null,
134 "timestamp": null,
135 "transactionHash": null
136 },
137 "owners": null,
138 "timeLastUpdated": "2023-11-06T11:46:38.867Z",
139 "balance": "31",
140 "acquiredAt": {
141 "blockTimestamp": null,
142 "blockNumber": null
143 }
144 }
145 ],
146 "totalCount": 26620,
147 "validAt": {
148 "blockNumber": 18513471,
149 "blockHash": "0x49376e3ea0d07b4b557521832ac2f52213b12bf912087ac1fe9f04c9899d221b",
150 "blockTimestamp": "2023-11-06T14:15:23Z"
151 },
152 "pageKey": "MHgwMDAzODZlM2Y3NTU5ZDliNmEyZjVjNDZiNGFkMWE5NTg3ZDU5ZGMzOjB4MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMjpmYWxzZQ=="
153}

c) Axios

axios is a promise-based HTTP client for the browser and Node.js, which allows us to make a raw request to the Alchemy API.

See the documentation for more info: https://www.npmjs.com/package/axios

Installation

Run the following command to install axios with npm and `yarn

$npm install axios

Demo Script

View the demo script on GitHub

In your alchemy-nft-api directory, you can create a new file called axios-script.js using your favorite file browser, code editor, or just directly in the terminal using the touch command.

shell
$touch axios-script.js

and then paste the following code snippet in to explore the getNFTs or getNFTMetadata methods:

1// alchemy-nft-api/axios-script.js
2import axios from 'axios';
3
4// Replace with your Alchemy API key:
5const apiKey = "demo";
6const baseURL = `https://eth-mainnet.g.alchemy.com/nft/v3/${apiKey}/getNFTsForOwner/`;
7// Replace with the wallet address you want to query for NFTs:
8const ownerAddr = "0xF5FFF32CF83A1A614e15F25Ce55B0c0A6b5F8F2c";
9const pageSize = 2;
10
11// Construct the axios request:
12var config = {
13 method: 'get',
14 url: `${baseURL}?owner=${ownerAddr}&pageSize=${pageSize}`
15};
16
17// Make the request and print the formatted response:
18axios(config)
19.then(response => console.log(JSON.stringify(response.data, null, 2)))
20.catch(error => console.log(error));

From your command line, you can execute the script with:

shell
$node axios-script.js

Your output should look like the following:

1alchemy-nft-api % node axios-script.js
2{
3 "ownedNfts": [
4 {
5 "contract": {
6 "address": "0x000386E3F7559d9B6a2F5c46B4aD1A9587D59Dc3",
7 "name": "Bored Ape Nike Club",
8 "symbol": "BANC",
9 "totalSupply": null,
10 "tokenType": "ERC721",
11 "contractDeployer": "0x51D7D428041E23ef51422e110dfEfF906e821CFe",
12 "deployedBlockNumber": 14276343,
13 "openSeaMetadata": {
14 "floorPrice": null,
15 "collectionName": "BoredApeNikeClub",
16 "collectionSlug": "bored-ape-nike-club-v2",
17 "safelistRequestStatus": "not_requested",
18 "imageUrl": "https://i.seadn.io/gae/yJ9DgXqjRwgdCkrQmHj7krCbixM8fPVAyYJWJ5NHXap1L0c3QL5MPvrNT0QDINIStGOK857lOvab8MpNQS9X4pkHPktmhVmN82qoVw?w=500&auto=format",
19 "description": "COUNTDOWN OVER. MINTING LIVE.\n\n[Mint on the website.](https://nikemetaverse.xyz)\n",
20 "externalUrl": "https://nikemetaverse.xyz",
21 "twitterUsername": null,
22 "discordUrl": null,
23 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format",
24 "lastIngestedAt": "2023-10-30T07:13:52.000Z"
25 },
26 "isSpam": true,
27 "spamClassifications": [
28 "OwnedByMostHoneyPots",
29 "Erc721TooManyOwners",
30 "Erc721TooManyTokens",
31 "NoSalesActivity",
32 "HighAirdropPercent",
33 "HighHoneyPotPercent",
34 "HoneyPotsOwnMultipleTokens"
35 ]
36 },
37 "tokenId": "1",
38 "tokenType": "ERC721",
39 "name": null,
40 "description": null,
41 "tokenUri": "http://api.nikeapenft.xyz/ipfs/1",
42 "image": {
43 "cachedUrl": null,
44 "thumbnailUrl": null,
45 "pngUrl": null,
46 "contentType": null,
47 "size": null,
48 "originalUrl": null
49 },
50 "raw": {
51 "tokenUri": "http://api.nikeapenft.xyz/ipfs/1",
52 "metadata": {},
53 "error": null
54 },
55 "collection": {
56 "name": "BoredApeNikeClub",
57 "slug": "bored-ape-nike-club-v2",
58 "externalUrl": "https://nikemetaverse.xyz",
59 "bannerImageUrl": "https://i.seadn.io/gae/i84LsC2dtbF5I3YiuaXzzfvSijlBI-ZJ8UEta04Ukl4V57Uoj0ZGw8tNyuPdwrF7N5pclyzdqSJjxHZ65z4G5jQrVRK_DHUMVrzTYQ?w=500&auto=format"
60 },
61 "mint": {
62 "mintAddress": null,
63 "blockNumber": null,
64 "timestamp": null,
65 "transactionHash": null
66 },
67 "owners": null,
68 "timeLastUpdated": "2023-11-06T04:34:38.880Z",
69 "balance": "26",
70 "acquiredAt": {
71 "blockTimestamp": null,
72 "blockNumber": null
73 }
74 },
75 ],
76 "totalCount": 26620,
77 "validAt": {
78 "blockNumber": 18513471,
79 "blockHash": "0x49376e3ea0d07b4b557521832ac2f52213b12bf912087ac1fe9f04c9899d221b",
80 "blockTimestamp": "2023-11-06T14:15:23Z"
81 },
82 "pageKey": "MHgwMDAzODZlM2Y3NTU5ZDliNmEyZjVjNDZiNGFkMWE5NTg3ZDU5ZGMzOjB4MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMjpmYWxzZQ=="
83}

Available Tutorials

Each tutorial includes step-by-step instructions and code examples to help you follow along and build your own app.

Thank you for using the NFT API, and happy coding!