Skip to content

StorageContext

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

new StorageContext(options): StorageContext

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

Creates a new StorageContext

ParameterTypeDescription
optionsStorageContextOptionsThe options for the StorageContext StorageContextOptions

StorageContext

readonly serviceProvider: `0x${string}`

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

get dataSetId(): bigint | undefined

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

bigint | undefined


get dataSetMetadata(): Record<string, string>

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

Record<string, string>


get provider(): PDPProvider

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

PDPProvider


get withCDN(): boolean

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

boolean

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

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

Delete a piece with given CID from this data set

ParameterTypeDescription
options{ piece: string | bigint | PieceLink; }Options for the delete operation
options.piecestring | bigint | PieceLinkThe PieceCID identifier or a piece number to delete by pieceID

Promise<`0x${string}`>

Transaction hash of the delete operation


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

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

Download data from this specific service provider

ParameterTypeDescription
optionsDownloadOptionsDownload options

Promise<Uint8Array<ArrayBufferLike>>

The downloaded data Uint8Array


getPieces(options?): AsyncGenerator<PieceRecord>

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

Get all active pieces for this data set as an async generator. This provides lazy evaluation and better memory efficiency for large data sets.

ParameterTypeDescription
options{ batchSize?: bigint; }Optional configuration object
options.batchSize?bigintThe batch size for each pagination call (default: 100)

AsyncGenerator<PieceRecord>

Object with pieceCid and pieceId - the piece ID is needed for certain operations like deletion


getProviderInfo(): Promise<PDPProvider>

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

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:1164

Get pieces scheduled for removal from this data set

Promise<readonly bigint[]>

Array of piece IDs scheduled for removal


hasPiece(options): Promise<boolean>

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

Check if a piece exists on this service provider.

ParameterTypeDescription
options{ pieceCid: string | PieceLink; }Options for the has piece operation
options.pieceCidstring | PieceLinkThe PieceCID (piece CID) to check

Promise<boolean>

True if the piece exists on this provider, false otherwise


pieceStatus(options): Promise<PieceStatus>

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

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.

ParameterTypeDescription
options{ pieceCid: string | PieceLink; }Options for the piece status
options.pieceCidstring | PieceLinkThe PieceCID (piece CID) to check

Promise<PieceStatus>

Status information including existence, data set timing, and retrieval URL


preflightUpload(options): Promise<PreflightInfo>

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

Run preflight checks for an upload

ParameterTypeDescription
options{ size: number; }Options for the preflight upload
options.sizenumberThe size of data to upload in bytes

Promise<PreflightInfo>

Preflight information including costs and allowances


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

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

Terminates the data set by sending on-chain message. This will also result in the removal of all pieces in the data set.

Promise<`0x${string}`>

Transaction response


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

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

Upload data to the service provider

Accepts Uint8Array or ReadableStream. For large files, prefer streaming to minimize memory usage.

Note: 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 in options as it cannot be calculated without consuming the stream.

ParameterType
dataUploadPieceStreamingData
options?UploadOptions

Promise<UploadResult>


static create(options): Promise<StorageContext>

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

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

ParameterType
optionsStorageContextCreateOptions

Promise<StorageContext>


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

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

Creates new storage contexts with specified options Each context corresponds to a different data set

ParameterType
optionsContextCreateContextsOptions

Promise<StorageContext[]>


static performPreflightCheck(options): Promise<PreflightInfo>

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

Static method to perform preflight checks for an upload

ParameterTypeDescription
options{ size: number; warmStorageService: WarmStorageService; withCDN: boolean; }Options for the preflight check
options.sizenumberThe size of data to upload in bytes
options.warmStorageServiceWarmStorageServiceWarmStorageService instance
options.withCDNbooleanWhether CDN is enabled

Promise<PreflightInfo>

Preflight check results without provider/dataSet specifics