#ipfs #api #pinata

pinata-sdk

Rust SDK for the Pinata IPFS platform

4 releases (2 stable)

1.1.0 Mar 22, 2022
1.0.0 Apr 27, 2020
0.1.1 Apr 5, 2020
0.1.0 Apr 5, 2020

#238 in HTTP client

Download history 60/week @ 2023-10-20 58/week @ 2023-10-27 32/week @ 2023-11-03 101/week @ 2023-11-10 78/week @ 2023-11-17 69/week @ 2023-11-24 53/week @ 2023-12-01 54/week @ 2023-12-08 50/week @ 2023-12-15 33/week @ 2023-12-22 41/week @ 2023-12-29 52/week @ 2024-01-05 58/week @ 2024-01-12 56/week @ 2024-01-19 89/week @ 2024-01-26 176/week @ 2024-02-02

386 downloads per month

MIT/Apache

44KB
774 lines

pinata-sdk

Rust pinata-sdk

The pinata_sdk provides the easieset path for interacting with the Pinata API.

Setup

Add the crate as a dependency to your codebase

[dependencies]
pinata_sdk = "1.0.0"

Initializing the API

use pinata_sdk::PinataApi;

let api = PinataApi::new("api_key", "secret_api_key").unwrap();

// test that you can connect to the API:
let result = api.test_authentication().await;
if let Ok(_) = result {
  // credentials are correct and other api calls can be made
}

Usage

1. Pinning a file

Send a file to pinata for direct pinning to IPFS.

use pinata_sdk::{ApiError, PinataApi, PinByFile};

let api = PinataApi::new("api_key", "secret_api_key").unwrap();

let result = api.pin_file(PinByFile::new("file_or_dir_path")).await;

if let Ok(pinned_object) = result {
  let hash = pinned_object.ipfs_hash;
}

If a directory path is used to construct PinByFile, then pin_file() will upload all the contents of the file to be pinned on pinata.

2. Pinning a JSON object

You can send a JSON serializable to pinata for direct pinning to IPFS.

use pinata_sdk::{ApiError, PinataApi, PinByJson};
use std::collections::HashMap;

let api = PinataApi::new("api_key", "secret_api_key").unwrap();

// HashMap derives serde::Serialize
let mut json_data = HashMap::new();
json_data.insert("name", "user");

let result = api.pin_json(PinByJson::new(json_data)).await;

if let Ok(pinned_object) = result {
  let hash = pinned_object.ipfs_hash;
}

3. Unpinning

You can unpin using the PinataApi::unpin() function by passing in the CID hash of the already pinned content.

Contribution Guide

Feel free to contribute. Please ensure that an issue is exists that describes the feature or bugfix you are planning to contribute.

License

MIT OR Apache-2.0

Dependencies

~7–20MB
~307K SLoC