Options
All
  • Public
  • Public/Protected
  • All
Menu

An NFTBundle is a collection of Metaplex NFTs that can be packaged into a single CAR for uploading to NFT.Storage.

All added NFTs require a unique ID string, which will be used to link from the root directory object to the assets and metadata directories for that NFT.

For example, if you add nfts with the ids a, b, and c, you'll end up with a root directory tree like this:

.
├── a
│   ├── assets
│   │   └── image.png
│   └── metadata
│   └── metadata.json
├── b
│   ├── assets
│   │   └── image.png
│   └── metadata
│   └── metadata.json
└── c
├── assets
│   └── image.png
└── metadata
└── metadata.json

When using addNFTFromFileSystem, the id will be derived from the metadata json filename, unless an id option is provided. This should play nice with the default candy-machine directory structure, where each json file has a unique name (e.g. 0.json, etc). If you're using a different naming convention, you should pass in explicit ids to avoid duplicate entries, which will fail.

Hierarchy

  • NFTBundle

Index

Constructors

Properties

MAX_ENTRIES: number = 2200

Maximum NFTs a bundle can support.

This is currently limited by the size of the root block, which must stay below 256 kib to be a valid "simple" (non-sharded) UnixFS directory object. May be increased in the future by switching to sharded directories for the root object.

MAX_ID_LEN: number = 64

Maximum byte length for each NFT id string (encoded as UTF-8).

Maximum length is enforced to ensure we can fit MAX_ENTRIES in a single root block. With 64 byte ids, each link in the root block takes a max of 114 bytes, which gives us 2299 max entries to stay below 256 kib.

If you change this value, make sure to recalculate and change MAX_ENTRIES to stay below the hard limit.

Methods

  • Adds a PackagedNFT to the bundle.

    Parameters

    • id: string

      an identifier for the NFT that will be used to create links from the bundle root directory object to the NFT data. Must be unique within the bundle.

    • metadata: Record<string, any>

      a JS object containing Metaplex NFT metadata

    • imageFile: <internal>.File

      a File object containing image data for the main NFT image

    • opts: { additionalAssetFiles?: <internal>.File[]; gatewayHost?: string; validateSchema?: boolean } = {}
      • Optional additionalAssetFiles?: <internal>.File[]
      • Optional gatewayHost?: string

        override the default HTTP gateway to use in metadata links. Must include scheme, e.g. "https://dweb.link" instead of just "dweb.link". Default is "https://nftstorage.link".

      • Optional validateSchema?: boolean

        if true, validate the metadata using a JSON schema before adding. off by default.

    Returns Promise<PackagedNFT>

    a Promise that resolves to the input PackagedNFT object on success.

  • addNFTFromFileSystem(metadataFilePath: string, imageFilePath?: string, opts?: { gatewayHost?: string; id?: string; validateSchema?: boolean }): Promise<PackagedNFT>
  • Loads an NFT from the local filesystem (node.js only) using loadNFTFromFilesystem.

    Note: if opts.id is not set, the basename of the metadata json file will be used as the id, which will only work if each NFT metadata file has a unique name.

    Parameters

    • metadataFilePath: string

      path to metadata json file

    • Optional imageFilePath: string

      optional path to image file. If not given, will be inferred using the logic in loadNFTFromFilesystem.

    • opts: { gatewayHost?: string; id?: string; validateSchema?: boolean } = {}
      • Optional gatewayHost?: string

        override the default HTTP gateway to use in metadata links. Must include scheme, e.g. "https://dweb.link" instead of just "dweb.link". Default is "https://nftstorage.link".

      • Optional id?: string

        an identifier for the NFT that will be used to create links from the bundle root directory object to the NFT data. Must be unique within the bundle. If not given, the name of the metadata json file (without '.json' extension) will be used.

      • Optional validateSchema?: boolean

        if true, validate the metadata using a JSON schema before adding. off by default.

    Returns Promise<PackagedNFT>

    a Promise that resolves to a PackagedNFT containing the NFT data on success.

  • "Finalizes" the bundle by creating a root block linking to all the NFTs in the bundle and generating a CAR containing all added NFT data.

    Returns Promise<EncodedCar>

    a Promise that resolves to an EncodedCar, which contains a CarReader and the root object's CID.

  • getRawSize(): Promise<number>
  • Returns Promise<number>

    the total size of all blocks in our blockstore. Will be slightly smaller than the size of the final CAR, due to the CAR header.

  • Creates a root UnixFS directory object that links to each NFT and encodes it as an IPLD block.

    Returns Promise<<internal>.Block<PBNode>>

    a Promise that resolves to an IPLD block of dab-pb / unixfs data.

Generated using TypeDoc