2

As the question states, I'm trying to figure out how to best download all the data for an NFT collection, including images and metadata. Is there a good API to achieve this? Any resources would be appreciated.

1 Answer 1

2

i gotchu

the alchemy nft api has a getNFTsForCollection endpoint that allows you to fetch all the images, metadata, etc. for an NFT collection (based on contract address)

here's an example request:

// Github: https://github.com/alchemyplatform/alchemy-sdk-js
// Setup: npm install @alch/alchemy-sdk
import {
  Network,
  initializeAlchemy,
  getNftsForCollection,
} from "@alch/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.
  maxRetries: 10,
};

const alchemy = initializeAlchemy(settings);

// Print total NFT count returned in the response:
const nftsForCollection = await getNftsForCollection(
  alchemy,
  "0x61fce80d72363b731425c3a2a46a1a5fed9814b2"
);
console.log(nftsForCollection);

and an example response:

[
  {
    contract: { address: '0x61fce80d72363b731425c3a2a46a1a5fed9814b2' },
    tokenId: '0',
    tokenType: 'ERC1155',
    title: 'Mercenary Lafja 0',
    description: 'Cyborg Mercenaries is a collection of 8,888 unique warriors born to kill and ready to invade the Ethereum blockchain. Cyborg Mercenaries fight only for money and for their own pleasure. They all have unique fighting capabilities that make them so special in battles. Championships will be organised to win new equipment, but also to earn prizes!',
    timeLastUpdated: '2022-06-04T10:44:25.672Z',
    metadataError: undefined,
    rawMetadata: {
      name: 'Mercenary Lafja 0',
      description: 'Cyborg Mercenaries is a collection of 8,888 unique warriors born to kill and ready to invade the Ethereum blockchain. Cyborg Mercenaries fight only for money and for their own pleasure. They all have unique fighting capabilities that make them so special in battles. Championships will be organised to win new equipment, but also to earn prizes!',
      image: 'ipfs://QmTBgswvcLxHMN4wM6UmajA7mKbt3K8iECjP5RWXf5h1t1/7321.png',
      attributes: [Array],
      external_url: 'https://cyborgmercenaries.io'
    },
    tokenUri: {
      raw: 'ipfs://QmNbJSSn67JvqrzJTwajRyi3NyBuV7AcsSmPo4kBxGbd6r/0',
      gateway: 'https://ipfs.io/ipfs/QmNbJSSn67JvqrzJTwajRyi3NyBuV7AcsSmPo4kBxGbd6r/0'
    },
    media: [ [Object] ]
  },
  ...
}

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.