@bws-sdk/ipfs
v1.0.4
Published
Blockchain Web Services NodeJS IPFS library.
Downloads
8
Maintainers
Readme
BWS IPFS SDK
Official Blockchain Web Services IPFS solution NodeJS SDK.
Overview
Blockchain Web Services (BWS) is a comprehensive platform offering a suite of blockchain-based solutions, designed to simplify and enhance the integration of blockchain technology into various business and individual needs.
This SDK provides the easiest way to save data into the InterPlanetary File System (IPFS). Use it to save your NFT metadata and images.
Installation
npm install --save @bws-sdk/ipfs
How to use it
Once installed, just import the SDK, create an instance using your API Key and start using the available functions. To get your API Key go to www.bws.ninja and sign up - it's free.
import { BWSIPFS } from @bws-sdk/ipfs;
const ipfs = new BWSIPFS('<your API key>')
Operations
Use the following available operations:
- uploadJSONAsync to save JSON data (e.g. NFT Metadata),
- uploadFileAsync to upload images or PDF files, or
- uploadStreamAsync if you need to pass a stream for sending your file(s).
All the operations will return the following IPFS related information (pointing to your newly created IPFS file):
{
"cid": "QmU7avmnTb4iVbNGCHMJmdEbsx9nRtUx7dWGpKeE7zjo8T",
"uris": {
"ipfs": "ipfs://QmU7avmnTb4iVbNGCHMJmdEbsx9nRtUx7dWGpKeE7zjo8T",
"url": "https://ipfs.bws.ninja/ipfs/QmU7avmnTb4iVbNGCHMJmdEbsx9nRtUx7dWGpKeE7zjo8T"
}
}
uploadJSONAsync
Upload a JSON to IPFS. You can pass the JSON object or the string representation.
import { BWSIPFS } from @bws-sdk/ipfs;
const ipfs = new BWSIPFS('<your API key>')
await ipfs.uploadJSONAsync({ timestamp: Date.now() }).then(data => {
console.log(data);
}).catch(err => {
console.log(err);
});
uploadFileAsync
Upload a file to IPFS by indicating the file path.
import { BWSIPFS } from @bws-sdk/ipfs;
const ipfs = new BWSIPFS('<your API key>')
await ipfs.uploadFileAsync('./files/image.png').then(data => {
console.log(data);
}).catch(err => {
console.log(err);
});
uploadStreamAsync
Upload content to IPFS by passing a stream.
import fs from 'fs';
import { BWSIPFS } from @bws-sdk/ipfs;
const ipfs = new BWSIPFS('<your API key>')
await ipfs.uploadFileAsync(fs.createReadStream('./files/image.png').then(data => {
console.log(data);
}).catch(err => {
console.log(err);
});
Have a question? Found an issue?
Please feel free to file an issue or send us an email: [email protected].
Need an extended feature or some help?
Please do not hesitate to ask for help or an extended feature for your project use case, we love improving!