Unofficial SDK for Pinata, implemented in ReasonML and compiled to Javascript.
Pinning service that improves your IPFS experience by deploying the underlying infrastructure so you don't have to!
In order to use some of the SDK's features, you'll have to sign up with Pinata to obtain your API keys. To learn more about Pinata check out the getting started guide.
Install the package - it includes both the javascript & reason versions.
npm i --save pinata-sdk
If you're using ReasonML, add this to your bsconfig.json
:
"bs-dependencies": [
"pinata-sdk"
],
Following examples demonstrates pinning an IPFS hash on Pinata, using the SDK. In order to do so, you need to authenticate yourself with Pinata API keys.
⚠️ For usage with Node.js, make sure to include thenode-fetch
polyfill.
open PinataSdk;
open PinataSdk.PinHashToIPFS;
let hash = "<your ipfs content hash>";
let apiKey = "<your api key>";
let privateApiKey = "<your private api key>";
let pinata = Pinata.configure(
~apiKey = apiKey,
~privateApiKey = privateApiKey,
()
);
pinata
->Pinata.pinHashToIPFS(~hash=hash)
|> then_(result => {
Js.log("Content pinned successfully" ++ result->ipfsHashGet)
Js.Promise.resolve(result);
})
import * as Pinata from 'pinata-sdk';
const apiKey = "<your api key>";
const privateApiKey = "<your private api key>";
const hash = "<your ipfs content hash>";
const pinata: Pinata.PinataConfig = Pinata.configure(apiKey, privateApiKey);
(async function() {
try {
const result: Pinata.PinHashToIPFSResponseJS = await Pinata.pinHashToIPFS(
pinata,
hash
);
console.log("Content pinned successfully", result.ipfsHash);
} catch (err) {
console.error("Content was not pinned", err);
}
})();
const Pinata = require('pinata-sdk');
const apiKey = "<your api key>";
const privateApiKey = "<your private api key>";
const hash = "<your ipfs content hash>";
const pinata = Pinata.configure(apiKey, privateApiKey);
(async function() {
try {
const result = await Pinata.pinHashToIPFS(
pinata,
hash
);
console.log("Content pinned successfully", result.ipfsHash);
} catch (err) {
console.error("Content was not pinned", err);
}
})();
Available methods of the SDK, for usage examples see the quick start guide or the examples section.
apiKey
your api key from pinataprivateApiKey
your private api key from pinataapiURL
optional, default valuehttps://api.pinata.cloud
config
SDK configuration created viaconfigure()
hash
IPFS content hash to be pinned
You can find the usage examples in the examples
folder.
🐳 Optionally you can start the development container described in the contributing section, in order to run the examples smoothly.
Make sure to:
npm i
before running each example.- Update your Pinata API credentials in
examples/**/credentials.js
- Update the IPFS hash you want to pin - usually a string in the example's source files.
Each example can be run using npm start
.
Some examples might contain additional README.md
to help you understand the details.
PinataSDK is developed & built trough docker, to start contributing, you'll have to setup docker for your platform first.
Editor support for ReasonML works well with VSCode's OCaml and Reason IDE
Everything you need to contribute to PinataSDK happens inside the development container
# Build an image for our dev container
make build-image
# Launch the container with an interactive bash session
make bash
List of available commands can be found in package.json
.
# Install dependencies
npm install
# Rebuild on every file change
npm run start
# Build the SDK
npm run build
# Cleans build artifacts
npm run clean
PinataSDK is available under the MIT License
Pinata SDK is created and maintained by Matej Sima.
Special thanks to the Pinata team for such an awesome service!