@uniblock/pinata v0.0.1-14
uniblock-pinata-sdk
This is a wrapper sdk for the Pinata sdk.
Before you begin, get a pinata api key using these steps.
Setup
Follow this step to add @uniblock/pinata to your repository
npm i @uniblock/pinata
or
yarn add @uniblock/pinata
General Overview
Pinata allows users to upload files, metadata and directories to IPFS. IPFS is a distributed system for storing and accessing files, websites, applications, and data. For more information about IPFS visit their documentation. After pinning a file/folder users get back a IPFS Hash which can be used with any of these gateways to access their uploaded files by appending the hash to the gateway url (eg. https://ipfs.io/ipfs/QmfZLApYD3EBZsXU1U7TwQFBpqNgXcxjkrCVYYoLtZANSM where https://ipfs.io/ipfs/ is the public gateway and QmfZLApYD3EBZsXU1U7TwQFBpqNgXcxjkrCVYYoLtZANSM is the hash).
Quick Start
Initialization
To initialize, pinata you have to provide your Uniblock API key which can be found on the dashboard. User may optionally provide their own pinata API key, this would allow them to avoid getting rate-limited from uniblock.
Note
Users have the option to either provide their own pinata key or rely on uniblock's key, although providing your own pinata key is recommended. If the key is not provided, @uniblock/pinata will default to uniblock's default key
import { initializePinata } from '@uniblock/pinata';
const pinataApiKey = 'YOUR_PINATA_API_KEY';
const pinataApiSecretKey = 'YOUR_PINATA_SECRET_KEY';
const uniblockApiKey = 'YOUR_UNIBLOCK_KEY';
const pinataWithOwnKeys = await initializePinata(
uniblockApiKey,
piniataApiKey,
pinataApiSecretKey,
);
const pinata = await initializePinata(uniblockApiKey); //pinata keys are optional
PinFile
This method allows users to pin a file to IPFS
const pin = await pinata.pinFile(FILE_TO_PIN);
//pinata is the initialized pinata instance
PinFileAndMetaData
This method allows users to pin a file and metadata regarding the file
const pin = await pinata.pinFileAndMetaData(FILE, 'METADATA');
//pinata is the initialized pinata instance
Here metadata is any valid JSON string, an example JSON is listed below
{
"application": "MyApplication",
"name": "OrdersProducts",
"description": "Model containing data for Order and Products.",
"version": "1.0",
"lastUpdated": "2018-01-02T12:00:00+08:00",
}
PinDirectory
This method allows users to pin a directory to IPFS
const pin = await pinata.pinDirectory(FILES_TO_PIN);
//pinata is the initialized pinata instance
Retrieve
This method allows users to retrieve an image from its IPFS hash
const file = await pinata.retrieve('YOUR_HASH', 'PREFERRED_GATEWAY');
If PREFERRED_GATEWAY
is not provided, @uniblock/pinata will use its default and backup gateways
10 months ago
10 months ago
10 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago