Vana SDK - v0.1.0
    Preparing search index...

    Connects to any standard IPFS node or service provider

    This provider implements the standard IPFS HTTP API (/api/v0/add) and works with any IPFS-compatible service. It provides the essential IPFS operations (upload/download) while maintaining the immutable, content-addressed nature of IPFS. Use static factory methods for common providers like Infura or local nodes.

    // Use with Infura (recommended for production)
    const ipfsStorage = IpfsStorage.forInfura({
    projectId: "your-project-id",
    projectSecret: "your-project-secret"
    });

    // Use with local IPFS node
    const localStorage = IpfsStorage.forLocalNode();

    // Upload file and get CID
    const result = await ipfsStorage.upload(fileBlob, "document.pdf");
    console.log("Uploaded to IPFS:", result.url);

    Implements

    Index

    Methods

    • Creates an IPFS storage instance configured for Infura

      Parameters

      • credentials: { projectId: string; projectSecret: string }

        Infura project credentials

        • projectId: string

          Your Infura project ID

        • projectSecret: string

          Your Infura project secret

      Returns IpfsStorage

      Configured IpfsStorage instance for Infura

      Infura provides reliable, scalable IPFS infrastructure with global availability. This factory method automatically configures the correct endpoints and authentication for Infura's IPFS service.

      const ipfsStorage = IpfsStorage.forInfura({
      projectId: "2FVGj8UJP5v8ZcnX9K5L7M8c",
      projectSecret: "a7f2c1e5b8d9f3a6e4c8b2d7f9e1a4c3"
      });

      const result = await ipfsStorage.upload(fileBlob);
    • Creates an IPFS storage instance configured for a local IPFS node

      Parameters

      • Optionaloptions: { url?: string }

        Local node configuration options

      Returns IpfsStorage

      Configured IpfsStorage instance for local node

      This factory method configures the storage provider to connect to a local IPFS node, typically running on your development machine or server. Assumes standard ports (5001 for API, 8080 for gateway) unless otherwise specified.

      // Use default localhost configuration
      const localStorage = IpfsStorage.forLocalNode();

      // Use custom local node URL
      const customStorage = IpfsStorage.forLocalNode({
      url: "http://192.168.1.100:5001"
      });

      const result = await localStorage.upload(fileBlob, "local-file.txt");
    • Uploads a file to IPFS and returns the content identifier (CID)

      Parameters

      • file: Blob

        The file to upload to IPFS

      • Optionalfilename: string

        Optional filename (for metadata purposes only)

      Returns Promise<StorageUploadResult>

      Promise that resolves to StorageUploadResult with IPFS gateway URL

      This method uploads the file to the configured IPFS endpoint using the standard /api/v0/add API. The file is content-addressed, meaning the same file will always produce the same CID regardless of when or where it's uploaded.

      When the upload fails or no CID is returned

      const result = await ipfsStorage.upload(fileBlob, "report.pdf");
      console.log("File uploaded to IPFS:", result.url);
      // Example URL: "https://gateway.pinata.cloud/ipfs/QmTzQ1JRkWErjk39mryYw2WVrgBMe2B36gRq8GCL8qCACj"
    • Downloads a file from IPFS using its content identifier (CID)

      Parameters

      • cid: string

        The IPFS content identifier, ipfs:// URL, or gateway URL

      Returns Promise<Blob>

      Promise that resolves to the downloaded file content

      This method retrieves the file from IPFS using the configured gateway. It accepts various formats including raw CIDs, ipfs:// URLs, and gateway URLs. The file is downloaded from the globally distributed IPFS network.

      When the download fails or CID format is invalid

      // Download using raw CID
      const file = await ipfsStorage.download("QmTzQ1JRkWErjk39mryYw2WVrgBMe2B36gRq8GCL8qCACj");

      // Download using ipfs:// URL
      const file2 = await ipfsStorage.download("ipfs://QmTzQ1JRkWErjk39mryYw2WVrgBMe2B36gRq8GCL8qCACj");

      // Create download link
      const url = URL.createObjectURL(file);