• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

perfectmak/pinata-sdk: Rust SDK for the Pinata IPFS platform

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

perfectmak/pinata-sdk

开源软件地址:

https://github.com/perfectmak/pinata-sdk

开源编程语言:

Rust 100.0%

开源软件介绍:

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.1.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.

Also, this README is generated using the cargo-readme crate from the README.tpl file, so update that file and run cargo readme > README.md to update the README's content. (This process can definitely be improved by running this step in a build script).

License

MIT OR Apache-2.0




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap