I’m working on a project where I need to fetch NFT images programmatically. I’ve been searching for a way to get the actual image file of a specific NFT using just the contract address and token ID through an HTTP API call.
So far I’ve tested several approaches but haven’t found a working solution. The main issue is that I can’t locate an API that gives me the metadata URI for the token. Without access to the token’s metadata URI, I can’t retrieve the image from IPFS or other storage services.
Has anyone found a reliable HTTP API or service that can help with this? I’m looking for something that accepts the contract address and token ID as parameters and either returns the image directly or at least provides the metadata URI so I can fetch the image myself.
Any suggestions or alternative approaches would be really helpful.
This is a pretty interesting challenge! I’ve been down this rabbit hole before and it’s definitely not straightforward.
Are you looking to work with NFTs on Ethereum mainnet specifically, or are you open to other chains? That could affect which APIs would work best.
Have you considered Alchemy or Moralis? Moralis has some NFT endpoints that might do what you need, though I haven’t tested them extensively. What chains are you targeting and have you tried any of the major web3 infrastructure providers yet?
One thing that might help is knowing whether you’re dealing with ERC-721 or ERC-1155 tokens (or both) since the metadata handling can be slightly different. When you say you tested several approaches, what specific services or methods did you try? Might help others avoid the same dead ends.
The metadata URI issue is definitely the key bottleneck here since most NFT contracts store that differently. Some use IPFS, some use centralized servers, some do weird custom stuff. Are you looking for a solution that works universally across all NFT contracts or would something that works for most popular collections be sufficient?
moralis definitely has nft endpoints for this. their /nft/{address}/{token_id} endpoint returns metadata with image URLs. quicknode’s nft api is another solid option - works well on mainnet and testnets. just watch out for rate limits since these services will throttle you.
OpenSea’s API works great for this. Hit /api/v1/asset/{contract_address}/{token_id}/ and you’ll get all the metadata plus image URLs - both original and different resolutions. You could also use Etherscan’s API to call the contract’s tokenURI function directly, then parse the JSON yourself. This gives you more control since you’re hitting the blockchain instead of relying on third-party indexing. Infura’s NFT API is solid too, though you need authentication. They’ve got better uptime than newer services and handle both ERC-721 and ERC-1155 tokens without issues. Just heads up - newly minted NFTs can take a few minutes to show up in their indexed data.