The pinata_sdk
provides the easieset path for interacting with the Pinata API.
Add the crate as a dependency to your codebase
[dependencies]
pinata_sdk = "1.1.0"
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
}
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.
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;
}
You can unpin using the PinataApi::unpin()
function by passing in the CID hash of the already
pinned content.
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).
MIT OR Apache-2.0