npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nosana/ipfs

v0.1.2

Published

Nosana IPFS module

Downloads

1,146

Readme

@nosana/ipfs

A TypeScript IPFS client for pinning and retrieving data from IPFS, with built-in support for Pinata and Solana hash conversion.

Installation

npm install @nosana/ipfs

Usage

Basic Setup

import { createIpfsClient } from '@nosana/ipfs';

// Create client with default Pinata configuration
const ipfs = createIpfsClient();

// Or with custom configuration
const ipfs = createIpfsClient({
  api: 'https://api.pinata.cloud',
  gateway: 'https://gateway.pinata.cloud/ipfs/',
  jwt: 'your-jwt-token',
});

Pin JSON Data

Pin a JSON object to IPFS:

const data = {
  name: 'example.txt',
  content: 'Hello, IPFS!',
};

const ipfsHash = await ipfs.pin(data);
console.log('Pinned to:', ipfsHash);
// Output: QmR9F9tMJWdhSCvqjPiTnthG4aEKz8DgJK35ko96YgbpXY

Pin Files

Pin a file from the filesystem:

const ipfsHash = await ipfs.pinFile('./path/to/file.txt');
console.log('File pinned to:', ipfsHash);

Retrieve Data

Retrieve data from IPFS using a hash:

// Retrieve with IPFS hash (string)
const data = await ipfs.retrieve<MyDataType>('QmR9F9tMJWdhSCvqjPiTnthG4aEKz8DgJK35ko96YgbpXY');

// Retrieve with Solana byte array (number[])
const solanaHash = [41, 167, 9, 157, ...]; // 32-byte array
const data = await ipfs.retrieve<MyDataType>(solanaHash);

API Reference

createIpfsClient(config?: Partial<IPFSConfig>)

Creates an IPFS client instance.

Parameters:

  • config (optional): Configuration object
    • api: IPFS API endpoint (default: Pinata API)
    • gateway: IPFS gateway URL (default: Pinata gateway)
    • jwt: JWT authentication token (optional)

Returns: Object with methods:

  • pin(data: object): Promise<string> - Pin JSON data to IPFS
  • pinFile(path: string): Promise<string> - Pin a file to IPFS
  • retrieve<T>(hash: string | number[]): Promise<T> - Retrieve data from IPFS

Configuration

Default Configuration

The client uses Pinata by default:

{
  api: 'https://api.pinata.cloud',
  gateway: 'https://nosana.mypinata.cloud/ipfs/',
  jwt: '<default-jwt-token>'
}

Custom Configuration

Override any or all configuration options:

const ipfs = createIpfsClient({
  api: 'https://custom-ipfs-api.com',
  gateway: 'https://custom-gateway.com/ipfs/',
  jwt: 'your-custom-jwt-token',
});

Solana Integration

The library includes utilities for converting between Solana hash arrays and IPFS CIDs:

import { solHashToIpfsHash, ipfsHashToByteArray } from '@nosana/ipfs';

// Convert Solana 32-byte array to IPFS hash
const solanaHash = [41, 167, 9, 157, ...]; // 32 bytes
const ipfsHash = solHashToIpfsHash(solanaHash);

// Convert IPFS hash back to 32-byte array
const byteArray = ipfsHashToByteArray('QmR9F9tMJWdhSCvqjPiTnthG4aEKz8DgJK35ko96YgbpXY');

Examples

Pin and Retrieve an Object

import { createIpfsClient } from '@nosana/ipfs';

const ipfs = createIpfsClient();

const data = { message: 'Hello IPFS!' };
const hash = await ipfs.pin(data);

const retrieved = await ipfs.retrieve<typeof data>(hash);
console.log(retrieved.message); // "Hello IPFS!"

Pin and Retrieve a File

import { createIpfsClient } from '@nosana/ipfs';
import fs from 'fs';

const ipfs = createIpfsClient();

// Pin file
const hash = await ipfs.pinFile('./document.pdf');

// Retrieve file content
const content = await ipfs.retrieve<string>(hash);
fs.writeFileSync('./downloaded.pdf', content);

Error Handling

All methods throw errors on failure:

try {
  const hash = await ipfs.pin(data);
} catch (error) {
  console.error('Failed to pin data:', error.message);
}

License

MIT

Author

Nosana