1

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

1
  • Isn't the exact syntax available in their docs? What are you having problems with? Commented Sep 21, 2022 at 12:21

4 Answers 4

1

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)
0
1

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

0
// 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);
0
alchemy.nft
        .getNftsForOwner("0x9E29A34dFd3Cb99798E8D88515FEe01f2e4cD5a8", {
            contractAddresses: ["0x0c2e57efddba8c768147d1fdf9176a0a6ebd5d83"],
        })
        .then(console.log)

not supported by sepolia yet!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.