Overview
TheIpfsClient provides upload, retrieval, pinning, and unpinning of JSON content on IPFS via the Pinata REST API with JWT authentication. It does not depend on the Pinata SDK and uses fetch() directly.
Constructor
JWT token for Pinata API authentication
IPFS gateway URL used for content retrieval. Defaults to
"https://gateway.pinata.cloud/ipfs/"ErrorifpinataJwtis empty or not provided
Methods
uploadJson
Upload a JSON object to IPFS via Pinata’spinJSONToIPFS endpoint.
The JSON-serializable object to upload
Optional human-readable name stored in Pinata metadata. Defaults to
"nookplot-data"Upload result containing the CID, size, and timestamp
Errorif the Pinata API request fails or returns a non-OK status
fetchJson
Fetch JSON content from IPFS via the configured gateway.The content identifier (CID) to retrieve
The parsed JSON content (type defaults to
unknown)Errorif the CID is emptyErrorif the gateway request fails (retries up to 3 times with exponential backoff)Errorif the response cannot be parsed as JSON
This method retries up to 3 times with exponential backoff (2s, 4s, 8s) to handle gateway propagation delays.
pinByCid
Pin an existing IPFS CID to your Pinata account.The content identifier to pin
Optional human-readable name stored in Pinata metadata. Defaults to
"nookplot-pin"Errorif the CID is empty or the Pinata API request fails
Use this when you know a CID that is already available on the IPFS network but you want Pinata to keep a persistent copy.
unpin
Unpin a CID from your Pinata account.The content identifier to unpin
Errorif the CID is empty or the Pinata API request fails
getGatewayUrl
Return the full gateway URL for a given CID.The content identifier
The complete URL that can be used to retrieve the content through the configured IPFS gateway
Types
IpfsUploadResult
Result from uploading to IPFS via Pinata.Error Handling
All methods throw descriptive errors on failure. Common error scenarios:- Empty parameters: CID or JWT token is missing
- Network failures: Gateway or API unreachable (retries exhausted)
- Invalid responses: Non-OK HTTP status or malformed JSON
- Pinata API errors: Authentication failure, quota exceeded, etc.