Skip to content

StorageContext

Defined in: packages/synapse-sdk/src/storage/context.ts:111

new StorageContext(options): StorageContext

Defined in: packages/synapse-sdk/src/storage/context.ts:233

Creates a new StorageContext

Parameter Type Description
options StorageContextOptions The options for the StorageContext StorageContextOptions

StorageContext

readonly serviceProvider: `0x${string}`

Defined in: packages/synapse-sdk/src/storage/context.ts:125

get dataSetId(): bigint | undefined

Defined in: packages/synapse-sdk/src/storage/context.ts:142

bigint | undefined


get dataSetMetadata(): Record<string, string>

Defined in: packages/synapse-sdk/src/storage/context.ts:137

Record<string, string>


get provider(): PDPProvider

Defined in: packages/synapse-sdk/src/storage/context.ts:132

PDPProvider


get withCDN(): boolean

Defined in: packages/synapse-sdk/src/storage/context.ts:128

boolean

commit(options): Promise<CommitResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:808

Commit pieces on-chain by calling AddPieces (or CreateDataSetAndAddPieces).

Pieces must be stored on the provider (via store() or pull()) before committing. Creates a new data set if this context doesn’t have one yet.

Aborting options.signal after onSubmitted only stops waiting for confirmation; the transaction can still land. If it was creating the data set, this context does not learn the new data set ID, and a later commit() on it creates another data set.

Parameter Type Description
options CommitOptions Pieces to commit with optional pieceMetadata, extraData, and onSubmitted callback

Promise<CommitResult>

Transaction hash, confirmed pieceIds, dataSetId, and whether a new data set was created


deletePiece(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/storage/context.ts:1193

Delete a piece with the given CID or piece ID from this data set.

Parameter Type Description
options { piece: string | bigint | PieceCID; } Options for the delete operation
options.piece string | bigint | PieceCID The PieceCID identifier or a piece number to delete by piece ID

Promise<`0x${string}`>

Transaction hash of the delete operation


deletePieces(options): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/storage/context.ts:1163

Delete pieces with the given CIDs or piece IDs from this data set in one transaction.

Parameter Type Description
options { pieces: (string | bigint | PieceCID)[]; } Options for the delete operation
options.pieces (string | bigint | PieceCID)[] PieceCID identifiers or piece numbers to delete by piece ID

Promise<`0x${string}`>

Transaction hash of the delete operation


download(options): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/synapse-sdk/src/storage/context.ts:1040

Download data from this specific service provider

Buffers the whole piece in memory. Use downloadStream for large pieces.

Parameter Type
options DownloadOptions

Promise<Uint8Array<ArrayBufferLike>>


downloadStream(options): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

Defined in: packages/synapse-sdk/src/storage/context.ts:1057

Download data from this specific service provider as a stream, with bounded memory use.

The PieceCID is validated as the bytes flow through: if it doesn’t match, the stream errors with a DownloadPieceError after the last chunk instead of closing. Treat the bytes as untrusted until the stream closes cleanly. Pass validate: false to opt out.

Parameter Type
options DownloadStreamOptions

Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

const stream = await context.downloadStream({ pieceCid })
await stream.pipeTo(writable)

getPieces(options?): AsyncGenerator<PieceRecord>

Defined in: packages/synapse-sdk/src/storage/context.ts:1118

Get all active pieces for this data set as an async generator.

Parameter Type Description
options? { batchSize?: bigint; } Optional configuration object
options.batchSize? bigint The batch size for each pagination call (default: 100)

AsyncGenerator<PieceRecord>

Object with pieceCid and pieceId


getPieceUrl(pieceCid): string

Defined in: packages/synapse-sdk/src/storage/context.ts:916

Get the retrieval URL for a piece on this provider.

Used by pull() to construct source URLs when pulling from this context to another provider.

Parameter Type
pieceCid PieceCID

string


getProviderInfo(): Promise<PDPProvider>

Defined in: packages/synapse-sdk/src/storage/context.ts:1095

Get information about the service provider used by this service.

Promise<PDPProvider>

Provider information including pricing (currently same for all providers)


getScheduledRemovals(): Promise<readonly bigint[]>

Defined in: packages/synapse-sdk/src/storage/context.ts:1104

Get pieces scheduled for removal from this data set.

Promise<readonly bigint[]>

Array of piece IDs scheduled for removal


pieceStatus(options): Promise<PieceStatus | null>

Defined in: packages/synapse-sdk/src/storage/context.ts:1210

Check if a piece exists on this service provider and get its proof status. Also returns timing information about when the piece was last proven and when the next proof is due.

Note: Proofs are submitted for entire data sets, not individual pieces. The timing information returned reflects when the data set (containing this piece) was last proven and when the next proof is due.

Parameter Type Description
options { pieceCid: string | PieceCID; } Options for the piece status
options.pieceCid string | PieceCID The PieceCID (piece CID) to check

Promise<PieceStatus | null>

Status information including data set timing and retrieval URL


prepareCommit(pieces): Promise<Commit>

Defined in: packages/synapse-sdk/src/storage/context.ts:625

Sign a commit for the given pieces without sending it.

The commit is JSON-safe data that holds the pieces and the EIP-712 signature. Pass it to both pull and commit so the wallet signs once for a multi-copy upload, or save it with JSON.stringify and commit it later, for example after a crash. Committing the same commit twice can never add the pieces twice: FWSS rejects a reused nonce.

Parameter Type Description
pieces object[] Pieces to sign for, with optional per-piece metadata

Promise<Commit>

The signed commit to pass to pull() or commit()


presignForCommit(pieces): Promise<`0x${string}`>

Defined in: packages/synapse-sdk/src/storage/context.ts:658

Pre-sign EIP-712 extraData for the given pieces.

The returned Hex can be passed to both pull() and commit() to avoid redundant wallet signature prompts during multi-copy uploads.

Parameter Type Description
pieces object[] Pieces to sign for, with optional per-piece metadata

Promise<`0x${string}`>

Signed extraData hex to pass to pull() or commit()


pull(options): Promise<PullResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:704

Request this provider to pull pieces from another provider.

Used for multi-copy uploads: data stored once on primary, then pulled to secondaries via SP-to-SP transfer.

Parameter Type Description
options PullOptions Pull options: pieces to pull or a commit from prepareCommit(), source (URL or StorageContext), signal, timeout, and onProgress

Promise<PullResult>

Status per piece (‘complete’ or ‘failed’) and overall result


store(data, options?): Promise<StoreResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:586

Store data on the service provider without committing on-chain.

First step of the split upload flow: store -> pull -> commit. After storing, the piece is “parked” on the provider and ready for pulling to other providers via pull(), on-chain commitment via commit(), or retrieval via getPieceUrl() (not yet committed; eligible for GC).

Parameter Type Description
data UploadPieceStreamingData Raw bytes (Uint8Array), a ReadableStream, or an AsyncIterable (such as a Node.js Readable) to upload
options? StoreOptions Optional pieceCid (skip CommP), signal, and onProgress callback

Promise<StoreResult>

PieceCid and size of the stored piece


terminate(options?): Promise<TerminateServiceResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:1318

Terminate the storage service for this context’s data set.

Relays through this provider by default (immediate); pass skipProvider: true to submit the transaction directly and wind down over the lockup period. See StorageManager.terminateService for full semantics.

Parameter Type Description
options? Pick<TerminateServiceOptions, "onSubmitted" | "skipProvider"> Optional skipProvider and onSubmitted TerminateServiceOptions

Promise<TerminateServiceResult>

The termination outcome TerminateServiceResult


upload(data, options?): Promise<UploadResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:938

Upload data to the service provider and commit on-chain.

Combines store() and commit() into a single call. Accepts Uint8Array or ReadableStream; prefer streaming for large files to minimize memory.

When uploading to multiple contexts, pieceCid should be pre-calculated and passed in options to avoid redundant computation. For streaming uploads, pieceCid must be provided as it cannot be calculated without consuming the stream.

Parameter Type Description
data UploadPieceStreamingData Raw bytes (Uint8Array), a ReadableStream, or an AsyncIterable (such as a Node.js Readable) to upload
options? UploadOptions Upload options including callbacks, pieceMetadata, pieceCid, and signal

Promise<UploadResult>

Upload result with pieceCid, size, and a single-element copies array


static create(options): Promise<StorageContext>

Defined in: packages/synapse-sdk/src/storage/context.ts:343

Static factory method to create a StorageContext Handles provider selection and data set selection/creation

Parameter Type
options StorageContextCreateOptions

Promise<StorageContext>


static createContexts(options): Promise<StorageContext[]>

Defined in: packages/synapse-sdk/src/storage/context.ts:255

Creates storage contexts with specified options.

Three mutually exclusive modes:

  1. dataSetIds provided: creates contexts for exactly those data sets
  2. providerIds provided: creates contexts for exactly those providers
  3. Neither provided: uses smart selection with count (default 2)
Parameter Type
options ContextCreateContextsOptions

Promise<StorageContext[]>


static resolveByDataSetId(dataSetId, warmStorageService, spRegistry, clientAddress): Promise<ProviderSelectionResult>

Defined in: packages/synapse-sdk/src/storage/context.ts:451

Resolve using a specific data set ID. Also used by StorageManager.terminateService to locate the data set’s provider.

Parameter Type
dataSetId bigint
warmStorageService WarmStorageService
spRegistry SPRegistryService
clientAddress string

Promise<ProviderSelectionResult>