Skip to main content

IPFS Client

The IPFSClient handles pinning policy JSON to IPFS and retrieving it. It supports multiple backends for redundancy.

Usage

Constructor

Options

IPFSBackend

Methods

pin(policy)

Pin a policy document to IPFS. The policy is serialized to JSON and pinned to all configured backends.
Returns: Promise<string> — The IPFS CID The client pins to all backends in parallel for redundancy. The CID is deterministic — the same policy always produces the same CID.

get(cid)

Retrieve and parse a policy from IPFS.
Returns: Promise<Policy> The client tries each backend in order until one succeeds. The retrieved JSON is validated against the Policy schema.

unpin(cid)

Unpin a policy from all backends.
Returns: Promise<void>
Unpinning removes the policy from your IPFS backends. If no other node has pinned the content, it may eventually be garbage collected from the IPFS network.

cidFromPolicy(policy)

Calculate the CID for a policy without pinning it. Useful for checking if a policy is already pinned.
Returns: Promise<string> — The IPFS CID

Error Handling

The client throws specific errors: