Skip to content

StorageManager

Defined in: packages/synapse-sdk/src/storage/manager.ts:126

new StorageManager(synapse, warmStorageService, pieceRetriever, withCDN): StorageManager

Defined in: packages/synapse-sdk/src/storage/manager.ts:133

ParameterType
synapseSynapse
warmStorageServiceWarmStorageService
pieceRetrieverPieceRetriever
withCDNboolean

StorageManager

createContext(options?): Promise<StorageContext>

Defined in: packages/synapse-sdk/src/storage/manager.ts:682

Create a single storage context with specified options

Uses singular providerId and dataSetId to match single-context semantics. For creating multiple contexts, use createContexts() with plural options.

ParameterType
options?CreateContextOptions

Promise<StorageContext>

// Create context for specific provider
const ctx = await storage.createContext({ providerId: 1n })
// Create context for specific data set
const ctx = await storage.createContext({ dataSetId: 5n })
// Let smart selection choose (with CDN enabled)
const ctx = await storage.createContext({ withCDN: true })

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

Defined in: packages/synapse-sdk/src/storage/manager.ts:614

Creates storage contexts for multi-provider storage deals and other operations.

By storing data with multiple independent providers, you reduce dependency on any single provider and improve overall data availability. Use contexts together as a group.

Contexts are selected by priority:

  1. Specified datasets (dataSetIds) - uses their existing providers
  2. Specified providers (providerIds or providerAddresses) - finds or creates matching datasets
  3. Automatically selected from remaining approved providers

For automatic selection, existing datasets matching the metadata are reused unless forceCreateDataSets is true. Providers are randomly chosen to distribute across the network.

ParameterTypeDescription
options?CreateContextsOptionsConfiguration options CreateContextsOptions

Promise<StorageContext[]>

Promise resolving to array of storage contexts


download(pieceCid, options?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/synapse-sdk/src/storage/manager.ts:509

Download data from storage If context is provided, routes to context.download() Otherwise performs SP-agnostic download

ParameterType
pieceCidstring | PieceLink
options?StorageManagerDownloadOptions

Promise<Uint8Array<ArrayBufferLike>>


findDataSets(clientAddress?): Promise<EnhancedDataSetInfo[]>

Defined in: packages/synapse-sdk/src/storage/manager.ts:749

Query data sets for this client

ParameterTypeDescription
clientAddress?`0x${string}`Optional client address, defaults to current signer

Promise<EnhancedDataSetInfo[]>

Array of enhanced data set information including management status


getDefaultContext(): Promise<StorageContext>

Defined in: packages/synapse-sdk/src/storage/manager.ts:740

Get or create the default context

Promise<StorageContext>


getStorageInfo(): Promise<StorageInfo>

Defined in: packages/synapse-sdk/src/storage/manager.ts:769

Get comprehensive information about the storage service including approved providers, pricing, contract addresses, and current allowances

Promise<StorageInfo>

Complete storage service information


preflightUpload(size, options?): Promise<PreflightInfo>

Defined in: packages/synapse-sdk/src/storage/manager.ts:570

Run preflight checks for an upload without creating a context

ParameterTypeDescription
sizenumberThe size of data to upload in bytes
options?{ metadata?: Record<string, string>; withCDN?: boolean; }Optional settings including withCDN flag and/or metadata
options.metadata?Record<string, string>-
options.withCDN?boolean-

Promise<PreflightInfo>

Preflight information including costs and allowances


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

Defined in: packages/synapse-sdk/src/storage/manager.ts:760

Terminate a data set with given ID that belongs to the synapse signer. This will also result in the removal of all pieces in the data set.

ParameterTypeDescription
dataSetIdbigintThe ID of the data set to terminate

Promise<`0x${string}`>

Transaction hash


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

Defined in: packages/synapse-sdk/src/storage/manager.ts:169

Upload data to Filecoin Onchain Cloud using a store→pull→commit flow across multiple providers.

By default, uploads to 2 providers (primary + secondary) for redundancy. Data is uploaded once to the primary, then secondaries pull from the primary via SP-to-SP transfer.

Important: This method only throws if zero copies succeed. Individual copy failures (including primary) are recorded in result.failures. Always check result.copies.length against your requested count. See UploadResult for details on interpreting results.

For large files, prefer streaming to minimize memory usage.

For uploading multiple files, use the split operations API directly: createContexts() → store() → presignForCommit() → pull() → commit()

ParameterTypeDescription
dataUploadDataData to upload (Uint8Array or ReadableStream)
options?StorageManagerUploadOptionsUpload options including count, provider selection, callbacks

Promise<UploadResult>

Upload result with copies array and any failures - check copies.length

StoreError if primary store fails (before any data is committed)

CommitError if all commit attempts fail (data stored but not on-chain)