How to get NFTs minted by an address
In one request, fetch all ERC-721 and ERC-1155 NFTs minted by a given Ethereum address, user or contract, over any time period.
Some of the reasons why you'd want to get NFTs minted by an address include:
  • Displaying all NFTs minted by a user (created and sent to their address)
  • Displaying all NFTs minted by a contract (shows you how many have been created)
  • Understand which NFTs were "first owned" or originally minted by a given address
Surprisingly, this type of information is not easy to gather with the current Ethereum API. That's why Alchemy builds a higher level Enhanced APIs to make building in Web3 much easier.
In this tutorial, we'll be leveraging Alchemy's Transfers API (alchemy_getAssetTransfers) to fetch all NFTs minted by a particular account address.

What happens when NFTs are minted?

Under the hood, when an NFT is minted, it is transferred from the null address: 0x0000000000000000000000000000000000000000 to the user account or contract that minted it.
All token creations and destructions typically are from and to the null address respectively, so it's a good filter when looking for mint or burn events.
This on-chain minting emits a standard transfer event since the asset is being transferred from one account to another.
Since we can filter for transfer events using the Transfers API, we can easily fetch NFT mints with the right parameter specification!

How to get NFT Mint Events

In order to fetch NFTs minted by a given address we'll need to specify a few things in our alchemy_getAssetTransfers request:
  • fromAddress: where the transaction originated from, in our case that’s always 0x0000000000000000000000000000000000000000
  • toAddress: the address we want to see mints from (NFTs go to the address that minted them)
  • fromBlock: the starting time range we want to fetch NFT mints over (defaults to latest)
  • toBlock : the ending time range we want to fetch NFT mints over (defaults to latest)
  • category : the type of transfer events we care about, in our case we want to see NFTs which are ERC721 and ERC1155 events
Once we've specified these inputs we can send the request!

Example: Getting NFT Mint Events

To demonstrate how to get the NFT mint events from an address we're going to walk through an example using address 0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1 and get all NFT mint events from block 0 to latest.

No-code Example

For a no-code demonstration of this request, check out Alchemy's Composer tool!
Follow along with any of the code examples below to make the request.
Alchemy Web3.js (Recommended)
Node-Fetch
Axios
Check out the complete script at the GitHub Repo below, or follow along with the instructions to write the script from scratch.
transfers_api_javascript_scripts/nft-mints-alchemyweb3.js at main · alchemyplatform/transfers_api_javascript_scripts
GitHub
NFT Mints GitHub Repo
1. Install AlchemyWeb3.js
If you don't already have AlchemyWeb3.js installed, you can follow the instructions here.

2. Create a file for the script

In your current directory, create a new file called nft-mints-alchemyweb3.js
Use your favorite file browser, code editor, or just directly in the terminal using the touch command like this:
1
touch nft-mints-alchemyweb3.js
Copied!

3. Write script!

Copy and paste in the following code snippet into your new file: nft-mints-alchemyweb3.js
nft-mints-alchemyweb3.js
1
import { createAlchemyWeb3 } from "@alch/alchemy-web3";
2
3
// Replace with your Alchemy API key:
4
const apiKey = "demo";
5
6
// Address we want get NFT mints from
7
const toAddress = "0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1";
8
9
// Initialize an alchemy-web3 instance:
10
const web3 = createAlchemyWeb3(
11
`https://eth-mainnet.alchemyapi.io/v2/${apiKey}`,
12
);
13
14
const res = await web3.alchemy.getAssetTransfers({
15
fromBlock: "0x0",
16
fromAddress: "0x0000000000000000000000000000000000000000",
17
toAddress: toAddress,
18
excludeZeroValue:true,
19
category: ["erc721","erc1155"]
20
})
21
22
// Print contract address and tokenId for each NFT (ERC721 or ERC1155):
23
for (const events of res.transfers) {
24
if (events.erc1155Metadata == null) {
25
console.log("ERC-721 Token Minted: ID- ", events.tokenId, " Contract- ", events.rawContract.address);
26
}
27
else{
28
for (const erc1155 of events.erc1155Metadata) {
29
console.log("ERC-1155 Token Minted: ID- ", erc1155.tokenId, " Contract- ", events.rawContract.address);
30
}
31
}
32
}
Copied!

3. Run script!

Now, on your command line, you can run the script by calling:
1
node nft-mints-alchemyweb3.js
Copied!
If you're using node-fetch a lightweight, common module that brings the Fetch API to Node.js and allows us to make our HTTP requests, below is a code snippet for the request you'd make!
transfers_api_javascript_scripts/nft-mints-fetch.js at main · alchemyplatform/transfers_api_javascript_scripts
GitHub
NFT Mints GitHub Repo

1. Create a file.

In your current directory, create a new file called nft-mints-fetch.js using your favorite file browser, code editor, or just directly in the terminal using the touch command like this:
1
touch nft-mints-fetch.js
Copied!

2. Write script!

Copy and paste in the following code snippet into your new file: nft-mints-fetch.js=
nft-mints-fetch.js
1
import fetch from 'node-fetch';
2
3
// Replace with your Alchemy API key:
4
const apiKey = "demo"
5
const baseURL = `https://eth-mainnet.alchemyapi.io/v2/${apiKey}`;
6
const fetchURL = `${baseURL}`;
7
8
// Address we want get NFT mints from
9
const toAddress = "0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1";
10
11
let data = JSON.stringify({
12
"jsonrpc": "2.0",
13
"id": 0,
14
"method": "alchemy_getAssetTransfers",
15
"params": [
16
{
17
"fromBlock": "0x0",
18
"fromAddress": "0x0000000000000000000000000000000000000000",
19
"toAddress": toAddress,
20
"excludeZeroValue":true,
21
"category": ["erc721","erc1155"]
22
}
23
]
24
});
25
26
27
var requestOptions = {
28
method: 'POST',
29
headers: { 'Content-Type': 'application/json' },
30
body: data,
31
redirect: 'follow'
32
};
33
34
fetch(fetchURL, requestOptions)
35
.then((res) => {
36
return res.json()
37
})
38
.then((jsonResponse) => {
39
//Print token name / asset value
40
//console.log(jsonResponse)
41
for (const events of jsonResponse.result.transfers) {
42
if (events.erc1155Metadata == null) {
43
console.log("ERC-721 Token Minted: ID- ", events.tokenId, " Contract- ", events.rawContract.address);
44
}
45
else{
46
for (const erc1155 of events.erc1155Metadata) {
47
console.log("ERC-1155 Token Minted: ID- ", erc1155.tokenId, " Contract- ", events.rawContract.address);
48
}
49
}
50
}
51
})
52
.catch((err) => {
53
// handle error
54
console.error(err);
55
});
56
Copied!

3. Run script!

Now, on your command line, you can execute the script by calling:
1
node nft-mints-fetch.js
Copied!
If you're using Javascript axios, a promise-based HTTP client for the browser and Node.js which allows us to make a raw request to the Alchemy API, below is a code snippet for the request you'd make!
transfers_api_javascript_scripts/nft-mints-axios.js at main · alchemyplatform/transfers_api_javascript_scripts
GitHub
NFT Mints GitHub Repo

1. Create a file.

In your current directory, create a new file called nft-mints-axios.js using your favorite file browser, code editor, or just directly in the terminal using the touch command.
1
touch nft-mints-axios.js
Copied!

2. Write script!

Copy and paste in the following code snippet into your new file: nft-mints-axios.js
nft-mints-axios.js
1
import axios from 'axios';
2
3
// Replace with your Alchemy API key:
4
const apiKey = "demo"
5
const baseURL = `https://eth-mainnet.alchemyapi.io/v2/${apiKey}`;
6
const axiosURL = `${baseURL}`;
7
8
// Address we want get NFT mints from
9
const toAddress = "0x5c43B1eD97e52d009611D89b74fA829FE4ac56b1";
10
11
let data = JSON.stringify({
12
"jsonrpc": "2.0",
13
"id": 0,
14
"method": "alchemy_getAssetTransfers",
15
"params": [
16
{
17
"fromBlock": "0x0",
18
"fromAddress": "0x0000000000000000000000000000000000000000",
19
"toAddress": toAddress,
20
"excludeZeroValue":true,
21
"category": ["erc721","erc1155"]
22
}
23
]
24
});
25
26
27
var requestOptions = {
28
method: 'post',
29
headers: { 'Content-Type': 'application/json' },
30
data: data,
31
};
32
33
const res = await axios(axiosURL, requestOptions);
34
35
// Print contract address and tokenId for each NFT:
36
for (const events of res.data.result.transfers) {
37
if (events.erc1155Metadata == null) {
38
console.log("ERC-721 Token Minted: ID- ", events.tokenId, " Contract- ", events.rawContract.address);
39
}
40
else{
41
for (const erc1155 of events.erc1155Metadata) {
42
console.log("ERC-1155 Token Minted: ID- ", erc1155.tokenId, " Contract- ", events.rawContract.address);
43
}
44
}
45
}
Copied!

3. Run script!

Now, on your command line, you can execute the script by calling:
1
node nft-mints-axios.js
Copied!

How to process the API response

Now that we have made a query and can see the response, let's learn how to handle the returned data.

Raw API Response:

Without parsing the response, we have a console log that looks like this:
1
{
2
[
3
{
4
"blockNum": "0xc75329",
5
"hash": "0xd89b54cb5aca6f501d43ee3363dcc892d31d1c185c9059c22d686ca0a1b93314",
6
"from": "0x0000000000000000000000000000000000000000",
7
"to": "0x5c43b1ed97e52d009611d89b74fa829fe4ac56b1",
8
"value": null,
9
"erc721TokenId": "0x0000000000000000000000000000000000000000000000000000000000000012",
10
"erc1155Metadata": null,
11
"tokenId": "0x0000000000000000000000000000000000000000000000000000000000000012",
12
"asset": "BURN",
13
"category": "erc721",
14
"rawContract": {
15
"value": null,
16
"address": "0x18a808dd312736fc75eb967fc61990af726f04e4",
17
"decimal": null
18
}
19
},
20
...
21
{
22
"blockNum": "0xd8315a",
23
"hash": "0x270aa9026d69b0924341e0ce60b24182f1f2af8a4bcc752b8e65595bdeca565f",
24
"from": "0x0000000000000000000000000000000000000000",
25
"to": "0x5c43b1ed97e52d009611d89b74fa829fe4ac56b1",
26
"value": null,
27
"erc721TokenId": "0x00000000000000000000000000000000000000000000000000000000000000fb",
28
"erc1155Metadata": null,
29
"tokenId": "0x00000000000000000000000000000000000000000000000000000000000000fb",
30
"asset": null,
31
"category": "erc721",
32
"rawContract": {
33
"value": null,
34
"address": "0x947600ad1ad2fadf88faf7d30193d363208fc76d",
35
"decimal": null
36
}
37
}
38
]
39
}
Copied!

Understanding API Response:

Below are the components of the each transfer in our response.
  • blockNum: the block number where an NFT mint event occurred, in hex
  • hash: the transaction hash of NFT minting transaction
  • from: where the transaction originated from, in our case that’s always 0x0000000000000000000000000000000000000000
  • to: the address we want to see mints from (NFTs go to the address that minted them), should be the same address specified in our request
  • value: the amount of ETH transferred, should always be null in our case since we're only looking at NFT mints, not sales
  • erc721TokenId: the ERC721 token ID. null if not an ERC721 token transfer.
  • erc1155Metadata: a list of objects containing the ERC1155 tokenId and value. null if not an ERC1155 transfer
  • tokenId: the token ID for ERC721 tokens or other NFT token standards
  • asset: ETH or the token's symbol. null if not defined in the contract and not available from other sources.
  • rawContract
    • value: null since we're looking at ERC721 & ERC1155 transfer
    • address: NFT contract address
    • decimal: null

Printing out the token type, tokenId and contract address

There's lots of information we can pull from this response. One example you may be interested in displaying are: NFT contract standard (ERC721 or ERC1155), contractAddress, and tokenId
With our queried response saved as a JSON object, we can index through the transfers. In particular, we first access the transfers list and then iterate accross a few key parameters: erc1155Metadata , tokenId, and rawContract.
The steps we want to take are:
  1. 1.
    Loop through all transfers in the result
  2. 2.
    Check whether the returned transfer is ERC1155 or not
    1. 1.
      If so, loop through tokens within ERC1155
      1. 1.
        print tokenId and address for each
    2. 2.
      If not, assume transfer is ERC721
      1. 1.
        print tokenID of contract and address
nft-mints.js
1
for (const events of res.data.result.transfers) {
2
if (events.erc1155Metadata == null) {
3
console.log("ERC-721 Token Minted: ID- ", events.tokenId, " Contract- ", events.rawContract.address);
4
}
5
else{
6
for (const erc1155 of events.erc1155Metadata) {
7
console.log("ERC-1155 Token Minted: ID- ", erc1155.tokenId, " Contract- ", events.rawContract.address);
8
}
9
}
10
}
Copied!
If you followed along, your response should look like the following:
1
ERC-721 Token Minted: ID- 0x0000000000000000000000000000000000000000000000000000000000000012 Contract- 0x18a808dd312736fc75eb967fc61990af726f04e4
2
ERC-721 Token Minted: ID- 0x000000000000000000000000000000000000000000000000000000000000003c Contract- 0x82c7c02a52b75387db14fa375938496cbb984388
3
ERC-721 Token Minted: ID- 0x000000000000000000000000000000000000000000000000000000000000004d Contract- 0x82c7c02a52b75387db14fa375938496cbb984388
4
ERC-721 Token Minted: ID- 0x0000000000000000000000000000000000000000000000000000000000000348 Contract- 0x7ecb204fed7e386386cab46a1fcb823ec5067ad5
5
ERC-721 Token Minted: ID- 0x0000000000000000000000000000000000000000000000000000000000000349 Contract- 0x7ecb204fed7e386386cab46a1fcb823ec5067ad5
6
ERC-721 Token Minted: ID- 0x000000000000000000000000000000000000000000000000000000000000034a Contract- 0x7ecb204fed7e386386cab46a1fcb823ec5067ad5
7
ERC-1155 Token Minted: ID- 0x01 Contract- 0xc4c377565a4b9eb6e657c2422bd33b6e4859b041
8
ERC-721 Token Minted: ID- 0x0000000000000000000000000000000000000000000000000000000000000b6e Contract- 0x72d47d4d24018ec9048a9b0ae226f1c525b7e794
9
ERC-721 Token Minted: ID- 0x000000000000000000000000000000000000000000000000000000000000026d Contract- 0x947600ad1ad2fadf88faf7d30193d363208fc76d
10
ERC-721 Token Minted: ID- 0x00000000000000000000000000000000000000000000000000000000000000fb Contract- 0x947600ad1ad2fadf88faf7d30193d363208fc76d
Copied!
And that's it! You've now learned how to fetch NFT mints for an address on Ethereum! If you enjoyed this tutorial for getting NFTs minted by an address, give us a tweet @AlchemyPlatform! (Or give the author @crypt0zeke a shoutout!)
Also, join our Discord server to meet other blockchain devs, builders, and entrepreneurs!