Alchemy: Using The Alchemy SDK with NFTs Minted Through thirdweb
Learn how to use the Alchemy SDK with NFTs minted through thirdweb.
Alchemy SDK is a Javascript SDK that supports the syntax and functionality of the Ethers.js AlchemyProvider and WebSocketProvider packages. It adds additional functionality including access to Alchemy’s enhanced API and NFT API, and offers features such as automated retries.
Read below to learn how to use the Alchemy SDK with NFTs minted through thirdweb.



For this tutorial, we’ll be using the Göerli testnet, so we are using a Rinkeby wallet.

To do this, navigate to console.filebase.com. If you don’t have an account already, sign up, then log in.
Select ‘Create Bucket’ in the top right corner to create a new bucket for your NFTs.

Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.

These files need to be named in sequential order, such as 0.png, 1.png, 2.png, etc.


https://ipfs.filebase.io/ipfs/IPFS_CID
Take note of this URL.
Select the ‘Code’ tab. This code showcases different code snippets to use to mint your NFTs using scripts, with your contract address and crypto wallet address inputted automatically for easy copy and paste. This tutorial will showcase the JavaScript code examples, but you can use any of the snippets provided in this tab.
npm install @thirdweb-dev/sdk
15. Open an IDE such as VSCode and insert the following code, replacing CONTRACT with your contract address, WALLET_ADDRESS with your crypto wallet address, each IPFS_CID with your IPFS folder CID you took note of earlier, and replacing the name and description of each NFT with your desired information.
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("goerli");
const contract = sdk.getNFTCollection("CONTRACT");
// Address of the wallet you want to mint the NFT to
const walletAddress = "WALLET_ADDRESS";
// Custom metadata of the NFTs you want to mint.
const metadatas = [{
name: "My NFT #1",
description: "This is a cool NFT",
image: fs.readFileSync("https://ipfs.filebase.io/ipfs/IPFS_CID/0.png"),
}, {
name: "My NFT #2",
description: "This is a cool NFT",
image: fs.readFileSync("https://ipfs.filebase.io/ipfs/IPFS_CID/1.png"),
}];
const tx = await contract.mintBatchTo(walletAddress, metadatas);
const receipt = tx[0].receipt; // same transaction receipt for all minted NFTs
const firstTokenId = tx[0].id; // token id of the first minted NFT
You can edit this script to include as many NFTs as you’d like to mint at one time.
node mint.js


npm install alchemy-sdk
mkdir alchemy-sdk
cd alchemy-sdk
const alchemy = new Alchemy();
// Get how many NFTs an address owns.
alchemy.nft.getNftsForOwner('ADDRESS').then(nfts => {
console.log(nfts.totalCount);
});
// Get all the image urls for all the NFTs an address owns.
async function main() {
for await (const nft of alchemy.nft.getNftsForOwnerIterator('ADDRESS')) {
console.log(nft.media);
}
}
main();
// Filter out spam NFTs.
alchemy.nft.getNftsForOwner('ADDRESS', {
excludeFilters: [NftExcludeFilters.SPAM]
}).then(console.log);
Replace
ADDRESS
with your crypto wallet address.Run this file with the command
node get-nfts.js
.This piece of code returns all the NFTs and associated images that are owned by the specified crypto wallet address.
import {
Alchemy
} from 'alchemy-sdk';
const alchemy = new Alchemy();
const nftAddress = 'CONTRACT_ADDRESS';
async function main() {
for await (const nft of alchemy.nft.getNftsForContractIterator(nftAddress, {
// Omit the NFT metadata for smaller payloads.
omitMetadata: true,
})) {
await alchemy.nft
.getOwnersForNft(nft.contract.address, nft.tokenId)
.then((response) =>
console.log("owners:", response.owners, "tokenId:", nft.tokenId)
);
}
}
main();
Replace
CONTRACT_ADDRESS
with the contract address of your NFT collection on thirdweb.Run this file with the command
node get-addresses.js
.This piece of code returns the addresses of every wallet that owns an NFT from your collection.
import { Alchemy } from “alchemy-sdk”;
const alchemy = new Alchemy();
const nftAddress = “CONTRACT_ADDRESS”;
const allTransfers = await alchemy.core.getAssetTransfers({
fromBlock: “0x0,
contractAddresses: [nftAddress],
category: [“erc721”],
order : “desc”,
});
Replace
CONTRACT_ADDRESS
with the contract address of your NFT collection on thirdweb.Run this file with the command
node get-transactions.js
.This piece of code returns all transactions including NFTs in your collection.
If you have any questions, please join our Discord server, or send us an email at [email protected]
Last modified 7mo ago