PinataNET 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PinataNET --version 1.0.0                
NuGet\Install-Package PinataNET -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PinataNET" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PinataNET --version 1.0.0                
#r "nuget: PinataNET, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PinataNET as a Cake Addin
#addin nuget:?package=PinataNET&version=1.0.0

// Install PinataNET as a Cake Tool
#tool nuget:?package=PinataNET&version=1.0.0                

PinataNET Documentation

Overview

PinataClient is a class for interacting with the Pinata API, allowing you to upload, pin, retrieve, update, and delete files on IPFS (InterPlanetary File System). The client requires a JWT (JSON Web Token) for authorization.

Installation

To use the PinataClient, ensure you have the following NuGet packages installed:

  • Newtonsoft.Json
  • HeyRed.Mime

Usage

Creating an Instance

To create an instance of PinataClient, you need to provide a JWT:

var pinataClient = new PinataClient("your_jwt_here");

Methods

PinFileToIPFSAsync

public async Task<PinFileResponse> PinFileToIPFSAsync(string filePath)

Pins a file to IPFS.

Parameters
  • filePath (string): The path of the file to be pinned.
Returns
  • PinFileResponse: A response containing the details of the pinned file.
Exceptions
  • Throws JsonException if the file pinning fails.
Example
var pinFileResponse = await pinataClient.PinFileToIPFSAsync("path/to/your/file.txt");

UploadFileAsync

public async Task<FileResponse> UploadFileAsync(Stream fileStream, string fileName, string groupId = "")

Uploads a file to Pinata.

Parameters
  • fileStream (Stream): The stream of the file to be uploaded.
  • fileName (string): The name of the file (including extension).
  • groupId (string, optional): An optional group ID for the file.
Returns
  • FileResponse: A response containing the upload details.
Exceptions
  • Throws JsonException if the upload fails.
Example
using (var fileStream = File.OpenRead("path/to/your/file.txt"))
{
    var fileResponse = await pinataClient.UploadFileAsync(fileStream, "file.txt");
}

GetFilesListAsync

public async Task<GetFilesListResponse> GetFilesListAsync()

Retrieves a list of files from Pinata.

Returns
  • GetFilesListResponse: A response containing a list of files.
Exceptions
  • Throws Exception if the retrieval fails.
Example
var filesListResponse = await pinataClient.GetFilesListAsync();

GetFileById

public async Task<FileResponse> GetFileById(string id)

Gets a file by its ID.

Parameters
  • id (string): The ID of the file to retrieve.
Returns
  • FileResponse: A response containing the file details.
Exceptions
  • Throws Exception if the retrieval fails.
Example
var fileResponse = await pinataClient.GetFileById("your_file_id");

UpdateFileNameAsync

public async Task<FileResponse> UpdateFileNameAsync(string id, string newName)

Updates the name of a specified file.

Parameters
  • id (string): The ID of the file to update.
  • newName (string): The new name for the file.
Returns
  • FileResponse: A response containing the updated file details.
Exceptions
  • Throws Exception if the update fails.
Example
var updatedFileResponse = await pinataClient.UpdateFileNameAsync("your_file_id", "new_file_name.txt");

DeleteFileAsync

public async Task<FileResponse> DeleteFileAsync(string id)

Deletes a specified file.

Parameters
  • id (string): The ID of the file to delete.
Returns
  • FileResponse: A response confirming the deletion of the file.
Exceptions
  • Throws Exception if the deletion fails.
Example
var deleteFileResponse = await pinataClient.DeleteFileAsync("your_file_id");

Error Handling

The PinataClient methods throw exceptions on failure, allowing you to handle errors gracefully in your application. Ensure that you wrap calls in try-catch blocks as needed.

try
{
    var fileResponse = await pinataClient.UploadFileAsync(fileStream, "file.txt");
}
catch (JsonException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"An unexpected error occurred: {ex.Message}");
}

Conclusion

The PinataClient class provides a simple interface for interacting with the Pinata API, enabling file management on IPFS. Use the methods provided to easily pin, upload, retrieve, update, and delete files.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.