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 5 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 | PieceLink
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, KOI8-R, GBK, etc.

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 | PieceLink
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 | PieceLink
pieceCid
: "bafkzcib...",
withCDN?: boolean | undefined
withCDN
: true,
})

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

import {
class Synapse
Synapse
, type
type PieceCID = Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, 1>
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: PieceLink
pieceCid
= null as unknown as
type PieceCID = Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, 1>
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 | PieceLink
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 | PieceLink
pieceCid
}) // Uses Synapse's withCDN: true
await
const ctx: StorageContext
ctx
.
StorageContext.download(options: DownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceLink
pieceCid
}) // Uses context's withCDN: false
await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.download(options: StorageManagerDownloadOptions): Promise<Uint8Array>
download
({
pieceCid: string | PieceLink
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 {
function getSizeFromPieceCID(pieceCidInput: PieceCID | CID | string): number
getSizeFromPieceCID
} from "@filoz/synapse-core/piece";
const
const pieceCid: "bafkzcib..."
pieceCid
= "bafkzcib...";
const
const size: number
size
=
function getSizeFromPieceCID(pieceCidInput: PieceCID | CID | string): number
getSizeFromPieceCID
(
const pieceCid: "bafkzcib..."
pieceCid
);
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;
}
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

Data set termination cannot be undone. Once initiated:

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

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

To delete an entire data set and discontinue payments for the service, call context.terminate(). This method submits an on-chain transaction to initiate the termination process. Following a defined termination period, payments will cease, and the service provider will be able to delete the data set.

You can also terminate a data set using synapse.storage.terminateDataSet({ dataSetId }), when the data set ID is known and creating a context is not necessary.

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
const
const hash: `0x${string}`
hash
= await
const ctx: StorageContext
ctx
.
StorageContext.terminate(): Promise<Hash>
terminate
()
await
const synapse: Synapse
synapse
.
Synapse.client: Client<Transport, Chain, Account, PublicRpcSchema, PublicActions<Transport, Chain>>
client
.
waitForTransactionReceipt: (args: WaitForTransactionReceiptParameters<Chain>) => Promise<TransactionReceipt>

Waits for the Transaction to be included on a Block (one confirmation), and then returns the Transaction Receipt. If the Transaction reverts, then the action will throw an error.

@remarks

The waitForTransactionReceipt action additionally supports Replacement detection (e.g. sped up Transactions).

Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel). Transactions are replaced when they are sent from the same nonce.

There are 3 types of Transaction Replacement reasons:

  • repriced: The gas price has been modified (e.g. different maxFeePerGas)
  • cancelled: The Transaction has been cancelled (e.g. value === 0n)
  • replaced: The Transaction has been replaced (e.g. different value or data)

@paramargs - WaitForTransactionReceiptParameters

@returnsThe transaction receipt. WaitForTransactionReceiptReturnType

@example

import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains'

const client = createPublicClient({ chain: mainnet, transport: http(), }) const transactionReceipt = await client.waitForTransactionReceipt({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })

waitForTransactionReceipt
({
hash: `0x${string}`

The hash of the transaction.

hash
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Dataset terminated successfully")
// Or directly by data set ID
const
const hash2: `0x${string}`
hash2
= await
const synapse: Synapse
synapse
.
Synapse.storage: StorageManager
storage
.
StorageManager.terminateDataSet(options: {
dataSetId: bigint;
}): Promise<Hash>
terminateDataSet
({
dataSetId: bigint
dataSetId
: 42n })
await
const synapse: Synapse
synapse
.
Synapse.client: Client<Transport, Chain, Account, PublicRpcSchema, PublicActions<Transport, Chain>>
client
.
waitForTransactionReceipt: (args: WaitForTransactionReceiptParameters<Chain>) => Promise<TransactionReceipt>

Waits for the Transaction to be included on a Block (one confirmation), and then returns the Transaction Receipt. If the Transaction reverts, then the action will throw an error.

@remarks

The waitForTransactionReceipt action additionally supports Replacement detection (e.g. sped up Transactions).

Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel). Transactions are replaced when they are sent from the same nonce.

There are 3 types of Transaction Replacement reasons:

  • repriced: The gas price has been modified (e.g. different maxFeePerGas)
  • cancelled: The Transaction has been cancelled (e.g. value === 0n)
  • replaced: The Transaction has been replaced (e.g. different value or data)

@paramargs - WaitForTransactionReceiptParameters

@returnsThe transaction receipt. WaitForTransactionReceiptReturnType

@example

import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains'

const client = createPublicClient({ chain: mainnet, transport: http(), }) const transactionReceipt = await client.waitForTransactionReceipt({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })

waitForTransactionReceipt
({
hash: `0x${string}`

The hash of the transaction.

hash
:
const hash2: `0x${string}`
hash2
})

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 | PieceLink
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: PieceLink
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 | PieceLink
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.