Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
ltnfue-w3ipfs-sdk
Advanced tools
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
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.
npm install aioz-w3ipfs-sdk
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 'aioz-w3ipfs-sdk'
const client = new W3IpfsClient('key', 'secret-key')
// Use the api keys by specifying your api key and api secret
import W3IpfsClient from 'aioz-w3ipfs-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)
})
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.
Pinning
Nft
Data
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
}
}
}
{
"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"
}
client
.pinByHash({
hashToPin: 'bafyb...2goq',
options: {
metadata: {
name: 'bafyb...2goq',
keyvalues: {
description1: 'this is description1',
description2: 'this is description2',
},
},
},
})
.then((res) => console.log({ res }))
.catch((err) => 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"}}
{
"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"
}
import NodeFormData from 'form-data'
import * as fs from 'fs'
import path from 'path'
const filePath = path.join(__dirname, './file.txt')
const readableStreamForFile = fs.createReadStream(filePath)
const form = new NodeFormData()
form.append('file', readableStreamForFile)
client
.pinFileToIPFS({
file: readableStreamForFile,
options: {
metadata: {
name: 'file.txt',
keyvalues: {
description: 'This is a file',
author: 'AIOZ',
},
},
},
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
pinFilesToIPFS
This API allows you to pin a files to IPFS using the provided pinning API key and secret key.
Example metadata:
{"name": "sample name", "keyvalues":{"key1": "value1","key2": "value2"}}
{
"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"
}
import NodeFormData from 'form-data'
import * as fs from 'fs'
import path from 'path'
const filePath = path.join(__dirname, '../assets/file.txt')
const metadataPath = path.join(__dirname, '../assets/sample.json')
const readableStreamForFile = fs.createReadStream(filePath)
const readableStreamForFile2 = fs.createReadStream(metadataPath)
export const w3IpfsOptions: PinOptions = {}
client
.pinFilesToIPFS({
files: [readableStreamForFile2, readableStreamForFile],
options: {
metadata: {
name: 'folder abc',
keyvalues: {
description: 'This is a folder abc',
},
},
},
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
pinFolderToIPFS
This API allows you to pin a folder to IPFS using the provided pinning API key and secret key.
{
"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": true,
"metadata": {
"name": "string",
"type": "string"
},
"status": "string"
},
"status": "success"
}
import path from 'path'
const folderPath = path.join(__dirname, '../assets/')
client
.pinFolderToIPFS({
recursive: 0,
sourcePath: folderPath,
options: {
metadata: {
name: 'folder',
keyvalues: {
description: 'This is a folder',
},
},
},
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
unpin
{
"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"
}
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"
}
]
}
{
"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"
}
import * as fs from 'fs'
import path from 'path'
const imagePath = path.join(__dirname, './file.txt')
const metadataPath = path.join(__dirname, './sample.json')
const readableStreamForFile = fs.createReadStream(imagePath)
const readableStreamMetadataFile = fs.createReadStream(metadataPath)
// pin Nft by metadata object
client.pinNft({
fileStream: readableStreamForFile,
metadata: {
name: 'test',
description: 'test',
properties: [
{
trait_type: 'Color',
value: 'Red',
},
{
trait_type: 'Size',
value: 'M',
},
],
},
})
// pin Nft by file.json
client
.pinNftByStreamMetadata({
fileStream: readableStreamForFile,
metadataStream: readableStreamMetadataFile,
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
pinNftByHash
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"
}
]
}
{
"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"
}
import * as fs from 'fs'
import path from 'path'
const metadataPath = path.join(__dirname, './sample.json')
const readableStreamMetadataFile = fs.createReadStream(metadataPath)
client
.pinNftByHash({
hashToPin: 'bafkr...w7m',
metadata: {
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',
},
],
},
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
// pin nft by hash with metadata stream
client
.pinNftByHashAndMetadataStream({
hashToPin: 'bafk...f73u',
metadataStream: readableStreamMetadataFile,
})
.then((res) => console.log({ res }))
.catch((err) => console.log({ err }))
unpinNft
client
.unpinNft('nft-id')
.then((result) => {
//handle results here
console.log(result)
})
.catch((err) => {
//handle error here
console.log(err)
})
testAuthentication
{
"message": "Congratulations! You are communicating with the Web3 IPFS API!"
}
client
.testAuthentication()
.then((result) => {
//handle successful authentication here
console.log(result)
})
.catch((err) => {
//handle error here
console.log(err)
})
getPinList
{
"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"
}
client
.getPinList({
offset: 0,
limit: 10,
pinned: 'true',
sortBy: 'size',
sortOrder: 'DESC',
metadata: {
keyvalues: {
bbbn: '',
},
},
})
.then((result: PinListResponse) => {
console.log({ result: result.data })
})
.catch((error) => {
console.log(error)
})
getPinByID
{
"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,
"sub_hash_status": "string",
"is_dir": false,
"metadata": {
"name": "string"
},
"status": "string"
},
"status": "success"
}
client
.getPinByID('pin id')
.then((result) => {
console.log({ result })
})
.catch((error) => {
console.log(error)
})
getPinByCID
{
"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,
"sub_hash_status": "string",
"is_dir": false,
"metadata": {
"name": "string"
},
"status": "string"
},
"status": "success"
}
client
.getPinByCID('bafy...')
.then((result) => {
//handle results here
console.log(result)
})
.catch((err) => {
//handle error here
console.log(err)
})
FAQs
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
The npm package ltnfue-w3ipfs-sdk receives a total of 0 weekly downloads. As such, ltnfue-w3ipfs-sdk popularity was classified as not popular.
We found that ltnfue-w3ipfs-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.