I am using alchemy sdk , can u please tell me how I can use getNftsForOwner() to get all the nfts owned by a wallet of a particular contract adddress? I need the exact syntax. Thank u
4 Answers
getNftsForOwner() accepts two parameters: owner and options (optional). Try passing any extra params as an object for options
Getting only nfts of a certain contract for an owner would look something like:
alchemy.nft
.getNftsForOwner("0x9E29A34dFd3Cb99798E8D88515FEe01f2e4cD5a8", {
contractAddresses: ["0x0c2e57efddba8c768147d1fdf9176a0a6ebd5d83"],
})
.then(console.log)
alchemy sdk changed something and so if you need, you can add pageKey to your sdk parameter.
...
alchemy.nft.getNftsForOwner("0xshah.eth", {pageKey: '88434286-7eaa-472d-8739-32a0497c2a18'}).then(console.log);
I refer this link: https://docs.alchemy.com/reference/getnfts
// Setup: npm install alchemy-sdk
// Github: https://github.com/alchemyplatform/alchemy-sdk-js
import { Network, Alchemy } from "alchemy-sdk";
// Optional Config object, but defaults to demo api-key and eth-mainnet.
const settings = {
apiKey: demo, // Replace with your Alchemy API Key.
network: Network.ETH_MAINNET, // Replace with your network.
};
const alchemy = new Alchemy(settings);
// Print all NFTs returned in the response:
alchemy.nft.getNftsForOwner("0xshah.eth").then(console.log);
alchemy.nft
.getNftsForOwner("0x9E29A34dFd3Cb99798E8D88515FEe01f2e4cD5a8", {
contractAddresses: ["0x0c2e57efddba8c768147d1fdf9176a0a6ebd5d83"],
})
.then(console.log)
not supported by sepolia yet!