Skip to content

Storage Operations

Data Set: A logical container of pieces stored with one provider. When a data set is created, a payment rail is established with that provider. All pieces in the data set share this single payment rail and are verified together via PDP proofs.

PieceCID: Content-addressed identifier for your data (format: bafkzcib...). Automatically calculated during upload and used to retrieve data from any provider.

Metadata: Optional key-value pairs for organization:

  • Data Set Metadata: Max 10 keys (e.g., project, environment)
  • Piece Metadata: Max 3 keys per piece (e.g., filename, contentType)

Copies and Durability: By default, upload() stores your data with 2 independent providers. Each provider maintains its own data set with separate PDP proofs and payment rails. If one provider goes down, your data is still available from the other.

Storage Manager: The main entry point for storage operations (synapse.storage). Handles provider selection, multi-copy orchestration, data set management, and provider-agnostic downloads.

Storage contexts represent a connection to a specific provider and data set. The SDK creates and manages contexts internally during upload(), but you can create them explicitly for data set management, retrieval, or split operations.

import {
class Synapse
Synapse
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: "my-app" })
// All options are optional
await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
StorageServiceOptions.providerId?: bigint | undefined
providerId
: 1n, // specific provider (optional)
StorageServiceOptions.dataSetId?: bigint | undefined
dataSetId
: 42n, // specific data set (optional)
BaseContextOptions.metadata?: Record<string, string> | undefined
metadata
: {
source: string
source
: "my-app" }, // data set metadata for matching/creation
BaseContextOptions.withCDN?: boolean | undefined
withCDN
: true, // enable fast-retrieval (paid, optional)
StorageServiceOptions.excludeProviderIds?: bigint[] | undefined
excludeProviderIds
: [3n], // skip specific providers (optional)
})

For multi-copy replication, use createContexts():

const
const contexts: StorageContext[]
contexts
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContexts(options?: CreateContextsOptions): Promise<StorageContext[]>
createContexts
({
CreateContextsOptions.copies?: number | undefined
copies
: 3, // number of contexts (default: 2)
CreateContextsOptions.providerIds?: bigint[] | undefined
providerIds
: [1n, 2n, 3n], // specific providers (mutually exclusive with dataSetIds)
CreateContextsOptions.dataSetIds?: bigint[] | undefined
dataSetIds
: [10n, 20n, 30n], // specific data sets (mutually exclusive with providerIds)
})
const [
const primary: StorageContext
primary
,
const secondary: StorageContext
secondary
] =
const contexts: StorageContext[]
contexts

View creation options for createContext()

View creation options for createContexts()

The SDK intelligently manages data sets to minimize on-chain transactions. The selection behavior depends on the parameters you provide:

Selection Scenarios:

  1. Explicit data set ID: If you specify dataSetId, that exact data set is used (must exist and be accessible)
  2. Specific provider: If you specify providerId, the SDK searches for matching data sets only within that provider’s existing data sets
  3. Automatic selection: Without specific parameters, the SDK searches across all your data sets with any approved provider

Exact Metadata Matching: In scenarios 2 and 3, the SDK will reuse an existing data set only if it has exactly the same metadata keys and values as requested. This ensures data sets remain organized according to your specific requirements.

Selection Priority: When multiple data sets match your criteria:

  • Data sets with existing pieces are preferred over empty ones
  • Within each group (with pieces vs. empty), the oldest data set (lowest ID) is selected

Provider Selection (when no matching data sets exist):

  • If you specify a provider (via providerId), that provider is used
  • Otherwise, the SDK selects from endorsed providers for the primary copy and any approved provider for secondaries
  • Before finalizing selection, the SDK verifies the provider is reachable via a ping test
  • If a provider fails the ping test, the SDK tries the next candidate
  • A new data set will be created automatically during the first commit

Download from any provider that has the piece. The SDK resolves the provider automatically:

import {
class Synapse
Synapse
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: 'my-app' })
// Download using PieceCID from a previous upload
const
const pieceCid: "bafkzcib..."
pieceCid
= "bafkzcib..." // from upload result
const
const bytes: Uint8Array<ArrayBufferLike>
bytes
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
})
const
const text: string
text
= new
var TextDecoder: new (label?: string, options?: TextDecoderOptions) => TextDecoder

The TextDecoder interface represents a decoder for a specific text encoding, such as UTF-8, ISO-8859-2, or GBK. A decoder takes an array of bytes as input and returns a JavaScript string.

MDN Reference

TextDecoder
().
TextDecoder.decode(input?: AllowSharedBufferSource, options?: TextDecodeOptions): string

The TextDecoder.decode() method returns a string containing text decoded from the buffer passed as a parameter.

MDN Reference

decode
(
const bytes: Uint8Array<ArrayBufferLike>
bytes
)
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Downloaded:",
const text: string
text
)
import {
class Synapse
Synapse
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
// Enable CDN globally
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: 'my-app',
SynapseOptions.withCDN?: boolean | undefined
withCDN
: true,
})
const
const bytes: Uint8Array<ArrayBufferLike>
bytes
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
: "bafkzcib..." })
// Or per-download:
const
const bytes2: Uint8Array<ArrayBufferLike>
bytes2
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
: "bafkzcib...",
withCDN?: boolean | undefined
withCDN
: true,
})

When using a StorageContext, downloads are restricted to that specific provider:

import {
class Synapse
Synapse
, type
class PieceCID
PieceCID
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: "my-app" })
const
const ctx: StorageContext
ctx
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
BaseContextOptions.metadata?: Record<string, string> | undefined
metadata
: {
source: string
source
: "my-app" },
})
const
const pieceCid: PieceCID
pieceCid
= null as unknown as
class PieceCID
PieceCID
;
// Downloads from the provider associated with this context
const
const data: Uint8Array<ArrayBufferLike>
data
= await
const ctx: StorageContext
ctx
.
StorageContext.download(options: DownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
})

The withCDN option follows a clear inheritance hierarchy:

  1. Synapse level: Default setting for all operations
  2. StorageContext level: Can override Synapse’s default
  3. Method level: Can override instance settings
await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
}) // Uses Synapse's withCDN: true
await
const ctx: StorageContext
ctx
.
StorageContext.download(options: DownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
}) // Uses context's withCDN: false
await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceCID
pieceCid
,
withCDN?: boolean | undefined
withCDN
: false }) // Method override: CDN disabled

When withCDN: true is set, it adds { withCDN: '' } to the data set’s metadata, ensuring CDN-enabled and non-CDN data sets remain separate.

Retrieve all data sets owned by your account to inspect piece counts, CDN status, and metadata:

import {
class Synapse
Synapse
} from "@filoz/synapse-sdk";
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from 'viem/accounts'
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
('0x...'),
SynapseOptions.source: string | null
source
: 'my-app' });
const
const dataSets: EnhancedDataSetInfo[]
dataSets
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.findDataSets(options?: {
address?: Address;
}): Promise<EnhancedDataSetInfo[]>
findDataSets
();
for (const
const ds: EnhancedDataSetInfo
ds
of
const dataSets: EnhancedDataSetInfo[]
dataSets
) {
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
(`Dataset ${
const ds: EnhancedDataSetInfo
ds
.
EnhancedDataSetInfo.pdpVerifierDataSetId: bigint
pdpVerifierDataSetId
}:`, {
live: boolean
live
:
const ds: EnhancedDataSetInfo
ds
.
EnhancedDataSetInfo.isLive: boolean
isLive
,
cdn: boolean
cdn
:
const ds: EnhancedDataSetInfo
ds
.
EnhancedDataSetInfo.withCDN: boolean
withCDN
,
pieces: bigint
pieces
:
const ds: EnhancedDataSetInfo
ds
.
EnhancedDataSetInfo.activePieceCount: bigint
activePieceCount
,
metadata: Record<string, string>
metadata
:
const ds: EnhancedDataSetInfo
ds
.
EnhancedDataSetInfo.metadata: Record<string, string>
metadata
});
}

List all pieces stored in a specific data set by iterating through a context:

const
const context: StorageContext
context
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
StorageServiceOptions.dataSetId?: bigint | undefined
dataSetId
});
const
const pieces: any[]
pieces
= [];
for await (const
const piece: PieceRecord
piece
of
const context: StorageContext
context
.
StorageContext.getPieces(options?: {
batchSize?: bigint;
}): AsyncGenerator<PieceRecord>
getPieces
()) {
const pieces: any[]
pieces
.
Array<any>.push(...items: any[]): number

Appends new elements to the end of an array, and returns the new length of the array.

@paramitems New elements to add to the array.

push
(
const piece: PieceRecord
piece
);
}
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
(`Found ${
const pieces: any[]
pieces
.
Array<any>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
} pieces`);

Access custom metadata attached to individual pieces:

import {
class WarmStorageService
WarmStorageService
} from "@filoz/synapse-sdk/warm-storage";
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from 'viem/accounts'
const
const warmStorage: WarmStorageService
warmStorage
=
class WarmStorageService
WarmStorageService
.
WarmStorageService.create(options: {
transport?: Transport;
chain?: Chain;
account: Account;
}): WarmStorageService
create
({
account: Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
('0x...') });
const
const metadata: MetadataObject
metadata
= await
const warmStorage: WarmStorageService
warmStorage
.
WarmStorageService.getPieceMetadata(options: {
dataSetId: bigint;
pieceId: bigint;
}): Promise<MetadataObject>
getPieceMetadata
({
dataSetId: bigint
dataSetId
,
pieceId: bigint
pieceId
:
const piece: {
pieceCid: string;
pieceId: bigint;
}
piece
.
pieceId: bigint
pieceId
});
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Piece metadata:",
const metadata: MetadataObject
metadata
);

Extract the size directly from a PieceCID using Synapse Core:

import * as
import Piece
Piece
from "@filoz/synapse-core/piece";
const
const pieceCid: "bafkzcib..."
pieceCid
= "bafkzcib...";
const
const size: number
size
=
import Piece
Piece
.
function from(input: Piece.PieceCIDInput): Piece.PieceCID
export from
from
(
const pieceCid: "bafkzcib..."
pieceCid
).
PieceCID.size: number
size
;
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
(`Piece size: ${
const size: number
size
} bytes`);

Query service-wide pricing, available providers, and network parameters:

const
const info: StorageInfo
info
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.getStorageInfo(): Promise<StorageInfo>
getStorageInfo
();
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Price/TiB/month:",
const info: StorageInfo
info
.
StorageInfo.pricing: {
noCDN: {
perTiBPerMonth: bigint;
perTiBPerDay: bigint;
perTiBPerEpoch: bigint;
};
withCDN: {
perTiBPerMonth: bigint;
perTiBPerDay: bigint;
perTiBPerEpoch: bigint;
};
tokenAddress: Address;
tokenSymbol: string;
priceList: getPriceList.OutputType;
}
pricing
.
noCDN: {
perTiBPerMonth: bigint;
perTiBPerDay: bigint;
perTiBPerEpoch: bigint;
}
noCDN
.
perTiBPerMonth: bigint
perTiBPerMonth
);
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Providers:",
const info: StorageInfo
info
.
StorageInfo.providers: PDPProvider[]
providers
.
Array<PDPProvider>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
);
const
const providerInfo: PDPProvider
providerInfo
= await
const synapse: Synapse
synapse
.
Synapse.getProviderInfo(providerAddress: Address | bigint): Promise<PDPProvider>
getProviderInfo
("0x...");
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("PDP URL:",
const providerInfo: PDPProvider
providerInfo
.
PDPProvider.pdp: PDPOffering
pdp
.
PDPOffering.serviceURL: string
serviceURL
);

Irreversible Operation

Termination cannot be undone. Once initiated:

  • The termination transaction is irreversible
  • When the service ends, the provider may delete all data
  • Payment rails associated with the data set will be terminated
  • You cannot cancel the termination

Only terminate when you’re certain you no longer need the data.

To end the storage service for a data set and discontinue its payments, call context.terminate(), or synapse.storage.terminateService({ dataSetId }) when the data set ID is known (a context is not necessary).

There are two ways to terminate, chosen with the skipProvider option. The provider-mediated path is the recommended default: you sign an authorization, the provider relays it on chain, and if your account can settle in full the service and payment terminate immediately.

The direct on-chain path is an independent fallback. It is useful if the provider-mediated request is unavailable, account doesn’t have available funds to settle in full or you need to submit the transaction yourself. It does not require provider cooperation, but it uses the standard lockup wind-down: the service and payment continues until endEpoch, typically about 30 days, while the provider settles and winds down the data set before cleanup.

Recommended default (via provider)Fallback (skipProvider: true)
Who submits the transactionThe provider relays your signed authorizationYou
EffectCan terminate immediately and allow cleanup to beginService runs to the end of the lockup period, typically ~30 days
Cost to youSmall termination fee (USDFC, drawn from your account)Transaction gas (FIL)
RequiresProvider online, your account able to settle in fullA funded wallet
Use whenPreferred path for ordinary terminationProvider-mediated termination cannot be completed, or you need independent submission

Provider-relayed termination never silently degrades: it either takes effect immediately or fails. The most common failure is an account that cannot cover full settlement; deposit funds or use skipProvider: true in that case. The result’s endEpoch reports the actual epoch at which the service stops; on the on-chain path this can be sooner than 30 days if your account stopped settling some time ago.

In both cases termination ends the service and its payments. The data set’s remaining on-chain state is cleaned up afterwards by the provider; that cleanup is not part of this call.

import {
class Synapse
Synapse
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: "my-app" })
const
const ctx: StorageContext
ctx
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
BaseContextOptions.metadata?: Record<string, string> | undefined
metadata
: {
source: string
source
: "my-app" },
})
// Via context: relayed through this context's provider, immediate
const
const result: TerminateServiceResult
result
= await
const ctx: StorageContext
ctx
.
StorageContext.terminate(options?: Pick<TerminateServiceOptions, "skipProvider" | "onSubmitted">): Promise<TerminateServiceResult>
terminate
()
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Service terminated, ends at epoch",
const result: TerminateServiceResult
result
.
TerminateServiceResult.endEpoch: bigint
endEpoch
)
// Or directly by data set ID
const
const result2: TerminateServiceResult
result2
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.terminateService(options: TerminateServiceOptions): Promise<TerminateServiceResult>
terminateService
({
TerminateServiceOptions.dataSetId: bigint
dataSetId
: 42n })
// Or submit independently on chain (winds down over the lockup period)
const
const result3: TerminateServiceResult
result3
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.terminateService(options: TerminateServiceOptions): Promise<TerminateServiceResult>
terminateService
({
TerminateServiceOptions.dataSetId: bigint
dataSetId
: 42n,
TerminateServiceOptions.skipProvider?: boolean | undefined
skipProvider
: true,
TerminateServiceOptions.onSubmitted?: ((txHash: Hex) => void) | undefined
onSubmitted
: (
txHash: `0x${string}`
txHash
) =>
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Submitted:",
txHash: `0x${string}`
txHash
),
})
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
("Service ends at epoch",
const result3: TerminateServiceResult
result3
.
TerminateServiceResult.endEpoch: bigint
endEpoch
)

To delete an individual piece from the data set, call context.deletePiece(). This method submits an on-chain transaction to initiate the deletion process.

Important: Piece deletion is irreversible and cannot be canceled once initiated.

import {
class Synapse
Synapse
} from "@filoz/synapse-sdk"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
const
const synapse: Synapse
synapse
=
class Synapse
Synapse
.
Synapse.create(options: SynapseOptions): Synapse
create
({
SynapseOptions.account: `0x${string}` | Account
account
:
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x..."),
SynapseOptions.source: string | null
source
: "my-app" })
const
const ctx: StorageContext
ctx
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.createContext(options?: StorageServiceOptions): Promise<StorageContext>
createContext
({
BaseContextOptions.metadata?: Record<string, string> | undefined
metadata
: {
source: string
source
: "my-app" },
})
// List all pieces in the data set
const
const pieces: any[]
pieces
= []
for await (const
const piece: PieceRecord
piece
of
const ctx: StorageContext
ctx
.
StorageContext.getPieces(options?: {
batchSize?: bigint;
}): AsyncGenerator<PieceRecord>
getPieces
()) {
const pieces: any[]
pieces
.
Array<any>.push(...items: any[]): number

Appends new elements to the end of an array, and returns the new length of the array.

@paramitems New elements to add to the array.

push
(
const piece: PieceRecord
piece
)
}
if (
const pieces: any[]
pieces
.
Array<any>.length: number

Gets or sets the length of the array. This is a number one higher than the highest index in the array.

length
> 0) {
await
const ctx: StorageContext
ctx
.
StorageContext.deletePiece(options: {
piece: string | PieceCID | bigint;
}): Promise<Hash>
deletePiece
({
piece: string | bigint | PieceCID
piece
:
const pieces: PieceRecord[]
pieces
[0].
PieceRecord.pieceId: bigint
pieceId
})
var console: Console
console
.
Console.log(...data: any[]): void

The console.log() static method outputs a message to the console.

MDN Reference

log
(
`Piece ${
const pieces: PieceRecord[]
pieces
[0].
PieceRecord.pieceCid: PieceCID
pieceCid
} (ID: ${
const pieces: PieceRecord[]
pieces
[0].
PieceRecord.pieceId: bigint
pieceId
}) deleted successfully`
)
}
// Delete by PieceCID
await
const ctx: StorageContext
ctx
.
StorageContext.deletePiece(options: {
piece: string | PieceCID | bigint;
}): Promise<Hash>
deletePiece
({
piece: string | bigint | PieceCID
piece
: "bafkzcib..." })
  • Upload Pipeline - Upload data with multi-copy durability, from simple one-liner to manual store/pull/commit.

  • Storage Costs - Calculate your monthly costs and understand funding requirements.

  • Payment Management - Manage deposits, approvals, and payment rails.