Skip to content

PinataPinning

Namespace Nfty.Core.Publish.Ipfs in assembly Nfty.Core.

public sealed class PinataPinning : IPinningService

Pinata, the hosted pinning service, reached with the author's own API key (a JWT).

Remarks

Status is GET /data/testAuthentication with the key as a bearer token: 200 means the key works, 401 means Pinata refused it.

Add is POST /pinning/pinFileToIPFS with every file as a file part named <label>/<path> and pinataOptions of {"cidVersion":1,"wrapWithDirectory":false}. Every part sharing ONE leading folder is how Pinata recognises a directory upload; its IpfsHash is then that folder, whose entries are the files - so ipfs://CID/1.png resolves, exactly as a local node's wrapper does. wrapWithDirectory stays false because the shared folder already IS the wrapper: true would add a second level and move every file to ipfs://CID/<label>/1.png.

The key is held only here, for the life of this object, and never logged or put in an exception message.

Constructors

PinataPinning(HttpClient, string, string)

public PinataPinning(HttpClient http, string jwt, string api = "https://api.pinata.cloud");

Creates the client.

Parameters

  • http (HttpClient) - The client to speak through; see KuboPinning about its timeout.
  • jwt (string) - The API key's JWT.
  • api (string) - Pinata's API root; tests point it elsewhere.

Exceptions

  • ArgumentException - The key is empty.

Fields

DefaultApi

public const string DefaultApi = "https://api.pinata.cloud";

Pinata's API root.

Properties

Provider

public string Provider { get; }

Which service this is, as a person reads it.

Methods

AddFolderAsync(string, string, IProgress<PinProgress>?, CancellationToken)

public Task<string> AddFolderAsync(string folder, string label, IProgress<PinProgress>? progress = null, CancellationToken cancellationToken = default);

Adds and pins every file under folder, returning the CID of a directory whose entries are those files.

Parameters

  • folder (string) - The folder whose contents to add.
  • label (string) - A name for the pin where the service keeps one (Pinata's dashboard).
  • progress (IProgress<PinProgress>?) - Bytes sent so far.
  • cancellationToken (CancellationToken) - Stops the upload. What the service already received may stay on it.

Returns. The root CID.

Exceptions

  • ArgumentException - The folder is missing or holds no file.
  • PinningException - The service refused, failed or answered without a CID.

StatusAsync(CancellationToken)

public Task<PinningStatus> StatusAsync(CancellationToken cancellationToken = default);

Asks whether the service can be reached and accepts the credentials. Never throws for an unreachable service: that is an answer, reported in the result.

Parameters

  • cancellationToken (CancellationToken) - Stops the check.

Returns. What was found.