0.1.7 • Published 5 years ago

pinata-sdk v0.1.7

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

Pinata SDK

Unofficial SDK for Pinata, implemented in ReasonML and compiled to Javascript.

What is Pinata?

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.

Installing

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"  
],

Quick start 👩‍💻

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 the node-fetch polyfill.

ReasonML

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);
    })

TypeScript

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);
    }
})();

Javascript

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);
    }
})();

API 🕹

Available methods of the SDK, for usage examples see the quick start guide or the examples section.

configure (~apiKey: string, ~privateApiKey: string, ~apiURL: string = apiURL): pinataConfig
  • apiKey your api key from pinata
  • privateApiKey your private api key from pinata
  • apiURL optional, default value https://api.pinata.cloud
pinHashToIPFS (config: pinataConfig, ~hash: ipfsHash): Promise.t(pinHashToIPFSResponseJS)
  • config SDK configuration created via configure()
  • hash IPFS content hash to be pinned

Examples 🤓

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: 1. npm i before running each example. 2. Update your Pinata API credentials in examples/**/credentials.js 3. 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.

Contributing 🔧

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

Development container

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

Available commands

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

License 📃

PinataSDK is available under the MIT License

Powered by

Credits 😎

Pinata SDK is created and maintained by Matej Sima.

Special thanks to the Pinata team for such an awesome service!

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago