Kubo RPC Client

6.1.0 · active · verified Tue Apr 21

The `kubo-rpc-client` package provides a JavaScript client library for interacting with the Kubo RPC API, allowing developers to programmatically control and query an IPFS Kubo node. It enables functionalities such as adding and retrieving data, managing pins, and interacting with the IPFS swarm. Currently at version 6.1.0, the library maintains a regular release cadence, incorporating new features like `provide.stat` and `pin.update`, and ensuring interoperability with recent Kubo versions (e.g., Kubo 0.38). It differentiates itself as the official client for Kubo's HTTP RPC API, offering a direct interface to the underlying IPFS daemon's capabilities, contrasting with higher-level IPFS client libraries that might embed or abstract away the RPC communication. It supports both Node.js (Current and Active LTS versions) and browser environments, providing a consistent API across platforms.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the Kubo RPC client, retrieve the IPFS node ID, add a string to IPFS, and then retrieve it by its Content ID (CID).

import { create } from 'kubo-rpc-client'

async function run() {
  try {
    // Connect to the local Kubo RPC API (default: http://localhost:5001)
    const client = create({
      url: process.env.IPFS_API_URL ?? 'http://localhost:5001/api/v0'
    })

    // Get the IPFS node ID
    const { id, agentVersion, protocolVersion } = await client.id()
    console.log('Connected to IPFS node:')
    console.log(`  ID: ${id}`)
    console.log(`  Agent Version: ${agentVersion}`)
    console.log(`  Protocol Version: ${protocolVersion}`)

    // Add a simple string to IPFS
    const data = 'Hello from kubo-rpc-client!'
    const result = await client.add(data)
    console.log(`Added data to IPFS: ${result.path}`)
    console.log(`Content ID (CID): ${result.cid}`)

    // Retrieve the data by its CID
    const retrievedBytes = client.cat(result.path)
    let retrievedData = ''
    for await (const chunk of retrievedBytes) {
      retrievedData += new TextDecoder().decode(chunk)
    }
    console.log(`Retrieved data: "${retrievedData}" (CID: ${result.cid})`)

  } catch (error) {
    console.error('Error interacting with IPFS:', error)
  }
}

run()

view raw JSON →