M
Meshkit

Storage API

upload, retrieve, pin, and listPins — the core storage operations.

upload

upload(data: Uint8Array): Promise<string>

Upload raw bytes to IPFS. Returns the CID string. Uses failover across healthy nodes.

const bytes = new TextEncoder().encode('hello world');
const cid = await meshkit.upload(bytes);
console.log(cid); // Qm...

Upload a file:

import { readFile } from 'node:fs/promises';

const file = await readFile('./image.png');
const cid = await meshkit.upload(file); // Buffer is a Uint8Array

retrieve

retrieve(cid: string): Promise<Uint8Array>

Retrieve content by CID. Returns raw bytes. Uses failover across healthy nodes.

const bytes = await meshkit.retrieve('Qm...');
const text = new TextDecoder().decode(bytes);

Write to disk:

import { writeFile } from 'node:fs/promises';

const bytes = await meshkit.retrieve(cid);
await writeFile('./downloaded.png', bytes);

pin

pin(cid: string): Promise<void>

Pin a CID on the primary node so it is not garbage-collected. Uses failover.

await meshkit.pin(cid);

publishName does not pin content automatically. If you publish an IPNS record pointing at a CID, pin that CID separately.


listPins

listPins(): Promise<string[]>

List all pinned CIDs on the primary node. Returns an array of CID strings.

const pins = await meshkit.listPins();
console.log(pins.length); // number of pinned items

Standalone listPins (low-level)

There is also a standalone export for use in migration scripts or when you don't have a Meshkit instance:

import { listPins } from '@ipfs-meshkit/meshkit';

const pins = await listPins('http://127.0.0.1:5001');

This makes a raw HTTP call and does not require auth headers. Use the meshkit.listPins() method when auth headers are configured on your node.

On this page