Retrieving NFT contract details with Alchemy's web3 toolkit

I’ve been working with Alchemy’s getNFTs API to fetch NFTs for a specific wallet. The API gives me a contract address for each NFT, but I need more info about the contract itself. I’m looking for details like the owner and the total number of tokens.

I’ve looked through the API docs, but I can’t find an endpoint that gives me this extra contract info. Does anyone know how to get these details using Alchemy’s web3 toolkit?

Here’s a simplified example of what I’m working with:

const alchemy = new Alchemy(config);
const nfts = await alchemy.getNFTs({ owner: walletAddress });

// I can access the contract address like this:
const contractAddress = nfts[0].contract.address;

// But how do I get more info about the contract?
const contractDetails = await alchemy.getSomeContractInfo(contractAddress);

Any help would be great. Thanks!

yo PixStar54, i’ve been messing with alchemy too. for contract deets, try using etherscan’s API alongside alchemy. it’s got endpoints for contract info including owner and token count. might need to juggle APIs, but it works. something like:

const etherscanResponse = await axios.get(`https://api.etherscan.io/api?module=contract&action=getcontractinfo&address=${contractAddress}&apikey=YOUR_API_KEY`);

good luck!

I’ve faced a similar challenge and found that Alchemy’s NFT API doesn’t directly provide all contract details. However, you can use a combination of Alchemy endpoints to get the information you need.

For the contract owner, you can use the getTransactionReceipt method to find the address that deployed the contract. As for the total number of tokens, the getNFTsForContract endpoint can help. It returns metadata including the totalSupply for ERC721 contracts.

Here’s a rough outline:

const txHash = await alchemy.core.getTransactionReceipt(contractAddress);
const contractOwner = txHash.from;

const contractMetadata = await alchemy.nft.getContractMetadata(contractAddress);
const totalSupply = contractMetadata.totalSupply;

This approach isn’t perfect but should get you most of the way there. Hope this helps!

hey there PixStar54! i’ve been tinkering with alchemy’s nft stuff too and ran into similar roadblocks. have you considered using the getContractMetadata endpoint? it might give you some of that extra info you’re after.

something like this could work:

const contractMetadata = await alchemy.nft.getContractMetadata(contractAddress);
console.log(contractMetadata);

this should give you a bunch of useful details about the contract. as for the owner, that’s a bit trickier. you might need to dig into the contract’s ABI or use etherscan’s API if alchemy doesn’t have it.

btw, have you tried any other web3 libraries? curious if you’ve found any that handle this stuff better than alchemy. let me know what you end up figuring out!