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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipfs-sdk

v1.0.22

Published

Experience seamless file management on our IPFS host with our SDK. Utilize API keys to effortlessly pin, unpin, retrieve, and securely access files through the gateway, ensuring efficient and secure file operations. Simplify decentralized file management

Downloads

29

Readme

Web3 Ipfs

Description

Experience seamless file management on our IPFS host with our SDK. Utilize API keys to effortlessly pin, unpin, retrieve, and securely access files through the gateway, ensuring efficient and secure file operations. Simplify decentralized file management with ease and confidence.

Installation

npm install ipfs-sdk

Setup

To start, simply require the W3IPFS SDK and set up an instance with your W3IPFS API Keys or your JWT key. Don't know what your keys are? Check out your Account Page. In the example below we provided with 2 ways to call the W3IPFS SDK.

// Use the api keys by providing the strings directly 
import W3IpfsClient from 'ipfs-sdk';
const client = new W3IpfsClient("key", "secret-key")
// Use the api keys by specifying your api key and api secret
import W3IpfsClient from 'ipfs-sdk';
const client = new W3IpfsClient({pinningApiKey: "key", pinningSecretApiKey: "secret-key"})

Quickly test that you can connect to the API with the following call:

client.testAuthentication().then((result) => {
    //handle successful authentication here
    console.log(result);
}).catch((err) => {
    //handle error here
    console.log(err);
});

Usage

Once you've set up your instance, using the W3IPFS SDK is easy. Simply call your desired function and handle the results of the promise.

pinByHash

The request body when pin a file by CID will look like this:

{
    hash_to_pin: CID,
    metadata: {
        name: string,
        keyvalues: {
            key1: value1,
            key2: value2
        }
    }
}

Response

{
    "data": {
        "id": "string",
        "file_record_id": "string",
        "root_hash": "string",
        "cid": "string",
        "user_id": "string",
        "date_pinned": "2023-01-01T11:11:11.111111Z",
        "date_unpinned": "2023-11-11T11:11:11.111111Z",
        "pinned": false,
        "is_pin_by_hash": true,
        "is_dir": false,
        "metadata": {
            "name": "string"
        },
        "status": "string"
    },
    "status": "success"
}
Example Code
const options = {
    w3IpfsMetadata: {
        name: "MyCustomName",
        keyvalues: {
            customKey: 'customValue',
            customKey2: 'customValue2'
        }
    },
};
client.pinByHash('hash', options).then((result) => {
    //handle results here
    console.log(result);
}).catch((err) => {
    //handle error here
    console.log(err);
});

pinFileToIPFS

This API allows you to pin a file to IPFS using the provided pinning API key and secret key.

Example metadata:

{"name": "sample name", "keyvalues":{"key1": "value1","key2": "value2"}}

Response

{
    "data": {
        "id": "string",
        "file_record_id": "string",
        "root_hash": "string",
        "cid": "string",
        "user_id": "string",
        "date_pinned": "2023-01-01T11:11:11.111111Z",
        "date_unpinned": "2023-11-11T11:11:11.111111Z",
        "pinned": false,
        "is_pin_by_hash": false,
        "sub_hash_status": "string",
        "is_dir": false,
        "metadata": {
            "name": "string",
            "type": "string"
        },
        "status": "string"
    },
    "status": "success"
}
Example Code
const readableStreamForFile = fs.createReadStream('./test.png');
const options = {
    w3IpfsMetadata: {
        name: "MyCustomName",
        keyvalues: {
            customKey: 'customValue',
            customKey2: 'customValue2'
        }
    }
};
client.pinFileToIPFS(readableStreamForFile, options).then((result) => {
    console.log(result);
}).catch((err) => {
    console.log(err);
});

unpin

This API allows you to pin a file to IPFS using the provided pinning API key and secret key.

Example metadata:

{"name": "sample name", "keyvalues":{"key1": "value1","key2": "value2"}}

Response

{
    "data": {
        "id": "string",
        "file_record_id": "string",
        "root_hash": "string",
        "cid": "string",
        "size": number,
        "user_id": "string",
        "date_pinned": "2023-01-01T11:11:11.111111Z",
        "date_unpinned": "2023-11-11T11:11:11.111111Z",
        "pinned": true,
        "is_pin_by_hash": true,
        "is_dir": false,
        "metadata": {
            "name": "string"
        },
        "status": "string"
    },
    "status": "success"
}
Example Code
client.unpin('file-id').then((result) => {
    //handle results here
    console.log(result);
}).catch((err) => {
    //handle error here
    console.log(err);
});

pinNft

The metadata JSON file will look like this:

{
    "name": "My Awesome NFT",
    "description": "This is an NFT that represents my creativity as a digital artist!",
    "properties": [
        {
            "trait_type": "Color",
            "value": "Red"
        },
        {
            "trait_type": "Rarity",
            "value": "Medium"
        }
    ]
}

Response

{
    "data": {
        "id": "string",
        "asset_cid": "string",
        "metadata_cid": "string",
        "asset_pin_id": "string",
        "metadata_pin_id": "string",
        "size": number,
        "user_id": "string",
        "created_at": "2023-01-01T11:11:11.111111Z",
        "updated_at": "2023-11-11T11:11:11.111111Z",
        "pinned": true,
        "metadata_asset": {
            "name": "string",
            "type": "string"
        },
        "status": "string"
    },
    "status": "success"
}
Example Code
const readableStreamForMetadata = fs.createReadStream('./sample.json');
const readableStreamForFile = fs.createReadStream('./test.png');

client.pinNft(undefined, readableStreamForMetadata, readableStreamForFile, undefined).then((result) => {
    console.log(result);
}).catch((err) => {
    console.log(err);
});

unpinNft

Example Code
client.unpinNft('nft-id').then((result) => {
    //handle results here
    console.log(result);
}).catch((err) => {
    //handle error here
    console.log(err);
});

testAuthentication

Response

{
    "message": "Congratulations! You are communicating with the Web3 IPFS API!"
}
Example Code
client.testAuthentication().then((result) => {
    //handle successful authentication here
    console.log(result);
}).catch((err) => {
    //handle error here
    console.log(err);
});

pinList

The metadata JSON file will look like this:

{
    "name": "My Awesome NFT",
    "description": "This is an NFT that represents my creativity as a digital artist!",
    "properties": [
        {
            "trait_type": "Color",
            "value": "Red"
        },
        {
            "trait_type": "Rarity",
            "value": "Medium"
        }
    ]
}

Response

{
    "data": {
        "totals": {
            "files": number,
            "size": number
        },
        "pins": [
            {
                "id": "string",
                "file_record_id": "string",
                "root_hash": "string",
                "cid": "string",
                "size": number,
                "user_id": "string",
                "date_pinned": "2023-01-01T11:11:11.111111Z",
                "date_unpinned": "2023-11-11T11:11:11.111111Z",
                "pinned": true,
                "is_pin_by_hash": true,
                "sub_hash_status": "string",
                "is_dir": false,
                "metadata": {
                    "name": "string"
                },
                "status": "string"
            }
        ]
    },
    "status": "success"
}
Example Code
const filters = {
    pinned: "true",
    limit: 10,
    offset: 0,
    sortBy: "created_at",
    sortOrder: "ASC",
    metadata: undefined,
};

client.pinList(filters).then((result) => {
    //handle results here
    console.log(result);
    console.log(result.data.pins);
}).catch((err) => {
    //handle error here
    console.log(err);
});