Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NFTStorage

implements

API.Service

Hierarchy

  • NFTStorage

Index

Constructors

constructor

  • new NFTStorage(__namedParameters: { endpoint?: URL; token: string }): NFTStorage
  • Constructs a client bound to the given options.token and options.endpoint.

    example
    import { NFTStorage, File, Blob } from "nft.storage"
    const client = new NFTStorage({ token: API_TOKEN })
    
    const cid = await client.storeBlob(new Blob(['hello world']))
    

    Optionally you could pass an alternative API endpoint (e.g. for testing)

    example
    import { NFTStorage } from "nft.storage"
    const client = new NFTStorage({
      token: API_TOKEN
      endpoint: new URL('http://localhost:8080/')
    })
    

    Parameters

    • __namedParameters: { endpoint?: URL; token: string }
      • Optional endpoint?: URL
      • token: string

    Returns NFTStorage

Properties

endpoint

endpoint: URL

token

token: string

Methods

delete

  • delete(cid: string): Promise<void>
  • Removes stored content by its CID from the service.

    Please note that even if content is removed from the service other nodes that have replicated it might still continue providing it.

    example
    await client.delete('Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD')
    

    Parameters

    • cid: string

    Returns Promise<void>

status

  • Returns current status of the stored content by its CID.

    example
    const status = await client.status('Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD')
    

    Parameters

    • cid: string

    Returns Promise<StatusResult>

storeBlob

  • Stores a single file and returns the corresponding Content Identifier (CID). Takes a Blob or a File. Note that no file name or file metadata is retained.

    example
    const content = new Blob(['hello world'])
    const cid = await client.storeBlob(content)
    cid //> 'Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD'
    

    Parameters

    • blob: Blob

    Returns Promise<CIDString>

storeDirectory

  • storeDirectory(files: Iterable<File>): Promise<CIDString>
  • Stores a directory of files and returns a CID for the directory.

    example
    const cid = await client.storeDirectory([
      new File(['hello world'], 'hello.txt'),
      new File([JSON.stringify({'from': 'incognito'}, null, 2)], 'metadata.json')
    ])
    cid //>
    

    Argument can be a FileList instance as well, in which case directory structure will be retained.

    Parameters

    • files: Iterable<File>

    Returns Promise<CIDString>

Static delete

  • delete(__namedParameters: Service, cid: string): Promise<void>

Static status

Static storeBlob

Static storeDirectory

  • storeDirectory(__namedParameters: Service, files: Iterable<File>): Promise<CIDString>

Generated using TypeDoc