# StorageManager

Defined in: [packages/synapse-sdk/src/storage/manager.ts:150](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L150)

## Constructors

### Constructor

> **new StorageManager**(`options`): `StorageManager`

Defined in: [packages/synapse-sdk/src/storage/manager.ts:161](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L161)

Creates a new StorageManager

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`StorageManagerOptions`](/reference/filoz/synapse-sdk/storage/interfaces/storagemanageroptions/) | The options for the StorageManager [StorageManagerOptions](/reference/filoz/synapse-sdk/storage/interfaces/storagemanageroptions/) |

#### Returns

`StorageManager`

## Accessors

### source

#### Get Signature

> **get** **source**(): `string` \| `null`

Defined in: [packages/synapse-sdk/src/storage/manager.ts:173](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L173)

The application source identifier used for dataset namespace isolation.
Set via `Synapse.create({ source })`. Used by `combineMetadata` to tag
datasets so that different applications sharing a wallet don't collide.

##### Returns

`string` \| `null`

***

### withCDN

#### Get Signature

> **get** **withCDN**(): `boolean`

Defined in: [packages/synapse-sdk/src/storage/manager.ts:181](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L181)

Whether CDN rails are enabled for new datasets by default.
Set via `Synapse.create({ withCDN })`.

##### Returns

`boolean`

## Methods

### calculateMultiContextCosts()

> **calculateMultiContextCosts**(`contexts`, `options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/utils/namespaces/calculateuploadcosts/type-aliases/outputtype/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:985](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L985)

Calculate upload costs aggregated across multiple storage contexts.

Each context creates its own PDP payment rail with its own lockup. This method
resolves the on-chain state for every context, then delegates to the shared
pure cost utility. The utility sums per-context costs while applying account-level
debt, runway, available funds, and buffer only once.

Dataset leaf counts, pending one-time fees, and lifecycle reserve balances are
fetched from chain for existing datasets so rates and reserve
replenishments are accurate. Multi-piece fee and reserve estimates are
conservative because actual batch boundaries depend on runtime timing and metadata.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `contexts` | [`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)[] | Storage contexts to aggregate costs for |
| `options` | [`Pick`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys)\<[`PrepareOptions`](/reference/filoz/synapse-sdk/synapse/interfaces/prepareoptions/), `"pieceSizes"` \| `"extraRunwayEpochs"` \| `"bufferEpochs"`\> | Upload options (pieceSizes, extraRunwayEpochs, bufferEpochs) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/utils/namespaces/calculateuploadcosts/type-aliases/outputtype/)\>

Aggregated upload costs with summed rates and single deposit/approval

#### Throws

When `pieceSizes` is empty or contains a non-positive size

***

### createContext()

> **createContext**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1138](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1138)

Create a single storage context with specified options

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options?` | [`StorageServiceOptions`](/reference/filoz/synapse-sdk/synapse/interfaces/storageserviceoptions/) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)\>

***

### createContexts()

> **createContexts**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)[]\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1080](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1080)

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`) - finds or creates matching datasets
3. Automatically selected from remaining approved providers

For automatic selection, existing datasets matching the `metadata` are reused.
Providers are randomly chosen to distribute across the network.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options?` | [`CreateContextsOptions`](/reference/filoz/synapse-sdk/synapse/interfaces/createcontextsoptions/) | Configuration options [CreateContextsOptions](/reference/filoz/synapse-sdk/synapse/interfaces/createcontextsoptions/) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)[]\>

Promise resolving to array of storage contexts

***

### download()

> **download**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)\<`ArrayBufferLike`\>\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:826](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L826)

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

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`StorageManagerDownloadOptions`](/reference/filoz/synapse-sdk/storage/interfaces/storagemanagerdownloadoptions/) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)\<`ArrayBufferLike`\>\>

***

### findDataSets()

> **findDataSets**(`options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`EnhancedDataSetInfo`](/reference/filoz/synapse-sdk/synapse/interfaces/enhanceddatasetinfo/)[]\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1209](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1209)

Query data sets for this client

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | \{ `address?`: `` `0x${string}` ``; \} | The options for the find data sets |
| `options.address?` | `` `0x${string}` `` | The client address, defaults to current signer |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`EnhancedDataSetInfo`](/reference/filoz/synapse-sdk/synapse/interfaces/enhanceddatasetinfo/)[]\>

Array of enhanced data set information including management status

***

### flush()

> **flush**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:406](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L406)

Submit all piece-batch windows currently accepted by this Synapse instance.

Waits for in-progress uploads and pulls to finish parking before submitting
their pending windows. Resolving does not mean every upload was submitted or
confirmed successfully; failures are reported by the individual upload
promises, which callers must also await. This is a no-op when batching is
disabled.

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`\>

***

### getDefaultContext()

> **getDefaultContext**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1199](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1199)

Get or create the default context

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageContext`](/reference/filoz/synapse-sdk/storage/classes/storagecontext/)\>

***

### getStorageInfo()

> **getStorageInfo**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageInfo`](/reference/filoz/synapse-sdk/synapse/interfaces/storageinfo/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1265](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1265)

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

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`StorageInfo`](/reference/filoz/synapse-sdk/synapse/interfaces/storageinfo/)\>

Complete storage service information

***

### getUploadCosts()

> **getUploadCosts**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/utils/namespaces/calculateuploadcosts/type-aliases/outputtype/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:904](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L904)

Get upload costs including rate, deposit needed, and approval state.

Wraps the synapse-core `getUploadCosts()` function, automatically injecting
the client address. No StorageContext is needed. For an existing data set,
pass its current PDP leaf count, lifecycle reserve balance, and any pending one-time
payments. [prepare](/reference/filoz/synapse-sdk/storage/classes/storagemanager/#prepare) reads that state automatically from its contexts.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)\<[`GetUploadCostsOptions`](/reference/filoz/synapse-sdk/synapse/type-aliases/getuploadcostsoptions/), `"clientAddress"`\> | Upload cost options (clientAddress auto-injected) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/utils/namespaces/calculateuploadcosts/type-aliases/outputtype/)\>

Upload costs including rate, deposit needed, and readiness

***

### prepare()

> **prepare**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`PrepareResult`](/reference/filoz/synapse-sdk/synapse/interfaces/prepareresult/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:932](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L932)

Prepare the account for upload by computing costs and returning a transaction to execute.

Can accept costs precomputed for the exact upload contexts and piece sizes to skip
redundant RPC, or computes them internally. Use [calculateMultiContextCosts](/reference/filoz/synapse-sdk/storage/classes/storagemanager/#calculatemulticontextcosts)
when precomputing costs for multiple contexts; [getUploadCosts](/reference/filoz/synapse-sdk/storage/classes/storagemanager/#getuploadcosts) covers one context.
When neither costs nor a context are provided, creates default contexts, mirroring
the upload flow.

Aggregates per-context lockup correctly for any number of contexts:
- Fetches each existing dataset's aggregate PDP leaf count from chain
- Fetches each existing dataset's lifecycle reserve and pending fees
- Sums lockup across all contexts
- Computes debt, runway, and buffer once at the account level
- Prices the known `pieceSizes` committed to each context
- Conservatively treats every piece as a separate add-pieces operation

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`PrepareOptions`](/reference/filoz/synapse-sdk/synapse/interfaces/prepareoptions/) | [PrepareOptions](/reference/filoz/synapse-sdk/synapse/interfaces/prepareoptions/) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`PrepareResult`](/reference/filoz/synapse-sdk/synapse/interfaces/prepareresult/)\>

PrepareResult with costs and an optional transaction

#### Throws

When `pieceSizes` is empty or contains a non-positive size

***

### terminateService()

> **terminateService**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`TerminateServiceResult`](/reference/filoz/synapse-sdk/synapse/interfaces/terminateserviceresult/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:1236](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L1236)

Terminate the storage service for a data set belonging to the synapse signer.

By default the request is relayed through the data set's service provider:
the client signs an EIP-712 authorization and the provider submits the
transaction (paying the gas), in exchange for a small fee drawn from the
payer's account. Provider-relayed termination takes effect immediately;
it requires the payer's account to cover settlement in full and fails
otherwise, rather than falling back to a lockup wind-down.

With `skipProvider: true` the transaction is submitted directly from the
signer's wallet. No provider cooperation is needed, but the service and
its payments run to the end of the lockup period (typically ~30 days;
the actual end is `endEpoch` in the result).

Either way, termination ends the service and its payments; the data set's
remaining on-chain state is cleaned up later by the provider, not by this
call.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`TerminateServiceOptions`](/reference/filoz/synapse-sdk/synapse/interfaces/terminateserviceoptions/) | [TerminateServiceOptions](/reference/filoz/synapse-sdk/synapse/interfaces/terminateserviceoptions/) |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`TerminateServiceResult`](/reference/filoz/synapse-sdk/synapse/interfaces/terminateserviceresult/)\>

The termination outcome [TerminateServiceResult](/reference/filoz/synapse-sdk/synapse/interfaces/terminateserviceresult/)

***

### upload()

> **upload**(`data`, `options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`UploadResult`](/reference/filoz/synapse-sdk/synapse/interfaces/uploadresult/)\>

Defined in: [packages/synapse-sdk/src/storage/manager.ts:214](https://github.com/FilOzone/synapse-sdk/blob/e66c35ddb1749f0e55bae2e4f430d1449cca89bd/packages/synapse-sdk/src/storage/manager.ts#L214)

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.

This method only throws if zero copies succeed. Partial success (some but
not all copies) is indicated by `result.complete === false`. Check `complete`
to determine overall success. Don't use `failedAttempts.length` as a failure
signal as `failedAttempts` exists as a diagnostic for intermediate failures.

Batching is enabled by default. Compatible concurrent calls can share
on-chain transactions, while sequentially awaiting each call prevents those
uploads from joining the same batch.

For large files, prefer streaming to minimize memory usage.

For manual control over providers, signing, or individual phases, use the
split operations API directly:
createContexts() -> store() -> presignForCommit() -> pull() -> commit()

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `data` | [`UploadPieceStreamingData`](/reference/filoz/synapse-core/sp/type-aliases/uploadpiecestreamingdata/) | Raw bytes (Uint8Array) or ReadableStream to upload |
| `options?` | [`StorageManagerUploadOptions`](/reference/filoz/synapse-sdk/storage/interfaces/storagemanageruploadoptions/) | Upload options including contexts, callbacks, and abort signal |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`UploadResult`](/reference/filoz/synapse-sdk/synapse/interfaces/uploadresult/)\>

Upload result with pieceCid, copies, and completion status

#### Throws

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

#### Throws

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