Skip to content

Synapse Core

Synapse Core (@filoz/synapse-core) is the low-level foundation that both the Synapse SDK and Synapse React build on. Use Synapse Core when you need:

  • Direct control over individual contract calls without the Synapse class abstraction
  • Custom integrations that combine only the modules you need

Install dependencies:

Terminal window
npm install @filoz/synapse-core viem

Synapse Core requires viem 2.x as a peer dependency.

Client setup:

All Synapse Core functions accept a viem Client as their first argument. Create one using viem’s standard client factories:

import {
function createPublicClient<transport extends Transport, chain extends Chain | undefined = undefined, accountOrAddress extends Account | Address | undefined = undefined, rpcSchema extends RpcSchema | undefined = undefined>(parameters: PublicClientConfig<transport, chain, accountOrAddress, rpcSchema>): PublicClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema>

Creates a Public Client with a given Transport configured for a Chain.

A Public Client is an interface to "public" JSON-RPC API methods such as retrieving block numbers, transactions, reading from smart contracts, etc through Public Actions.

@paramconfig - PublicClientConfig

@returnsA Public Client. PublicClient

@example

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

const client = createPublicClient({ chain: mainnet, transport: http(), })

createPublicClient
,
function createWalletClient<transport extends Transport, chain extends Chain | undefined = undefined, accountOrAddress extends Account | Address | undefined = undefined, rpcSchema extends RpcSchema | undefined = undefined>(parameters: WalletClientConfig<transport, chain, accountOrAddress, rpcSchema>): WalletClient<transport, chain, ParseAccount<accountOrAddress>, rpcSchema>

Creates a Wallet Client with a given Transport configured for a Chain.

A Wallet Client is an interface to interact with Ethereum Account(s) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through Wallet Actions.

The Wallet Client supports signing over:

@paramconfig - WalletClientConfig

@returnsA Wallet Client. WalletClient

@example

// JSON-RPC Account import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains'

const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), })

@example

// Local Account import { createWalletClient, custom } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains'

const client = createWalletClient({ account: privateKeyToAccount('0x…') chain: mainnet, transport: http(), })

createWalletClient
,
function http<rpcSchema extends RpcSchema | undefined = undefined, raw extends boolean = false>(url?: string | undefined, config?: HttpTransportConfig<rpcSchema, raw>): HttpTransport<rpcSchema, raw>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
} from "viem"
import {
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
} from "viem/accounts"
import {
const calibration: Chain
calibration
,
const mainnet: Chain
mainnet
} from "@filoz/synapse-core/chains"
// Read-only client for queries
const
const publicClient: {
account: undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime: number;
ccipRead?: false | {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | undefined;
chain: Chain;
dataSuffix?: DataSuffix | undefined;
experimental_blockTag?: BlockTag | undefined;
key: string;
... 63 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
publicClient
=
createPublicClient<HttpTransport<undefined, false>, Chain, undefined, undefined>(parameters: {
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined | undefined;
cacheTime?: number | undefined | undefined;
ccipRead?: {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | false | undefined | undefined;
... 6 more ...;
transport: HttpTransport<...>;
}): {
...;
}

Creates a Public Client with a given Transport configured for a Chain.

A Public Client is an interface to "public" JSON-RPC API methods such as retrieving block numbers, transactions, reading from smart contracts, etc through Public Actions.

@paramconfig - PublicClientConfig

@returnsA Public Client. PublicClient

@example

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

const client = createPublicClient({ chain: mainnet, transport: http(), })

createPublicClient
({
chain?: Chain | Chain | undefined

Chain for the client.

chain
:
const calibration: Chain
calibration
, // or mainnet
transport: HttpTransport<undefined, false>

The RPC transport

transport
:
http<undefined, false>(url?: string | undefined, config?: HttpTransportConfig<undefined, false> | undefined): HttpTransport<undefined, false>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
(),
})
// Wallet client for transactions
const
const account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
}
account
=
function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount

@description Creates an Account from a private key.

@returnsA Private Key Account.

privateKeyToAccount
("0x...")
const
const walletClient: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
};
... 41 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
walletClient
=
createWalletClient<HttpTransport<undefined, false>, Chain, {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
... 4 more ...;
type: "local";
}, undefined>(parameters: {
...;
}): {
...;
}

Creates a Wallet Client with a given Transport configured for a Chain.

A Wallet Client is an interface to interact with Ethereum Account(s) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through Wallet Actions.

The Wallet Client supports signing over:

@paramconfig - WalletClientConfig

@returnsA Wallet Client. WalletClient

@example

// JSON-RPC Account import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains'

const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), })

@example

// Local Account import { createWalletClient, custom } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains'

const client = createWalletClient({ account: privateKeyToAccount('0x…') chain: mainnet, transport: http(), })

createWalletClient
({
account?: `0x${string}` | {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
} | Account | undefined

The Account to use for the Client. This will be used for Actions that require an account as an argument.

account
,
chain?: Chain | Chain | undefined

Chain for the client.

chain
:
const calibration: Chain
calibration
, // or mainnet
transport: HttpTransport<undefined, false>

The RPC transport

transport
:
http<undefined, false>(url?: string | undefined, config?: HttpTransportConfig<undefined, false> | undefined): HttpTransport<undefined, false>

@description Creates a HTTP transport that connects to a JSON-RPC API.

http
(),
})

The @filoz/synapse-core/chains subpath exports chain definitions with all contract addresses pre-configured for Filecoin Mainnet (mainnet) and Filecoin testnet (calibration) networks.

Query account balances, deposit funds, manage operator approvals, and settle payment rails on the Filecoin Pay contract.

import * as
import pay
pay
from "@filoz/synapse-core/pay"
import {
function parseUnits(value: string, decimals: number): bigint

Multiplies a string representation of a number by a given exponent of base 10 (10exponent).

@example

import { parseUnits } from 'viem'

parseUnits('420', 9) // 420000000000n

parseUnits
} from "viem"
// Query Filecoin Pay account info for the USDFC token
const
const info: pay.accounts.OutputType
info
= await
import pay
pay
.
function accounts(client: Client<Transport, Chain>, options: pay.accounts.OptionsType): Promise<pay.accounts.OutputType>
accounts
(
const publicClient: {
account: undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime: number;
ccipRead?: false | {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | undefined;
chain: Chain;
dataSuffix?: DataSuffix | undefined;
experimental_blockTag?: BlockTag | undefined;
key: string;
... 63 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
publicClient
, {
// If not provided, the USDFC token address will be used.
token?: `0x${string}`
token
:
const calibration: Chain
calibration
.
Chain.contracts: {
multicall3: ChainContract;
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
};
filecoinPay: {
address: Address;
abi: typeof filecoinPayV1Abi;
};
fwss: {
address: Address;
abi: typeof fwss;
};
fwssView: {
address: Address;
abi: typeof filecoinWarmStorageServiceStateViewAbi;
};
serviceProviderRegistry: {
address: Address;
abi: typeof serviceProviderRegistry;
};
sessionKeyRegistry: {
address: Address;
abi: typeof sessionKeyRegistryAbi;
};
pdp: {
address: Address;
abi: typeof pdpVerifierAbi;
};
endorsements: {
address: Address;
abi: typeof providerIdSetAbi;
};
}

Collection of contracts

contracts
.
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
}
usdfc
.
address: `0x${string}`
address
,
address: `0x${string}`
address
:
const account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
}
account
.
address: `0x${string}`
address
,
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const info: pay.accounts.OutputType
info
.
availableFunds: bigint
availableFunds
) // bigint — funds available in Filecoin Pay
// Deposit USDFC in Filecoin Pay
const
const depositTxHash: `0x${string}`
depositTxHash
= await
import pay
pay
.
function depositAndApprove(client: Client<Transport, Chain, Account>, options: pay.DepositAndApproveOptions): Promise<`0x${string}`>
depositAndApprove
(
const walletClient: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
};
... 41 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
walletClient
, {
// If not provided, the USDFC token address will be used.
token?: `0x${string}`
token
:
const calibration: Chain
calibration
.
Chain.contracts: {
multicall3: ChainContract;
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
};
filecoinPay: {
address: Address;
abi: typeof filecoinPayV1Abi;
};
fwss: {
address: Address;
abi: typeof fwss;
};
fwssView: {
address: Address;
abi: typeof filecoinWarmStorageServiceStateViewAbi;
};
serviceProviderRegistry: {
address: Address;
abi: typeof serviceProviderRegistry;
};
sessionKeyRegistry: {
address: Address;
abi: typeof sessionKeyRegistryAbi;
};
pdp: {
address: Address;
abi: typeof pdpVerifierAbi;
};
endorsements: {
address: Address;
abi: typeof providerIdSetAbi;
};
}

Collection of contracts

contracts
.
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
}
usdfc
.
address: `0x${string}`
address
,
amount: bigint
amount
:
function parseUnits(value: string, decimals: number): bigint

Multiplies a string representation of a number by a given exponent of base 10 (10exponent).

@example

import { parseUnits } from 'viem'

parseUnits('420', 9) // 420000000000n

parseUnits
("1", 18), // 1 USDFC
})
await
const publicClient: {
account: undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime: number;
ccipRead?: false | {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | undefined;
chain: Chain;
dataSuffix?: DataSuffix | undefined;
experimental_blockTag?: BlockTag | undefined;
key: string;
... 63 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
publicClient
.
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.

@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 depositTxHash: `0x${string}`
depositTxHash
})
// Withdraw USDFC from Filecoin Pay
const
const withdrawTxHash: `0x${string}`
withdrawTxHash
= await
import pay
pay
.
function withdraw(client: Client<Transport, Chain, Account>, options: pay.withdraw.OptionsType): Promise<Hash>
withdraw
(
const walletClient: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
};
... 41 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
walletClient
, {
// If not provided, the USDFC token address will be used.
token?: `0x${string}`
token
:
const calibration: Chain
calibration
.
Chain.contracts: {
multicall3: ChainContract;
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
};
filecoinPay: {
address: Address;
abi: typeof filecoinPayV1Abi;
};
fwss: {
address: Address;
abi: typeof fwss;
};
fwssView: {
address: Address;
abi: typeof filecoinWarmStorageServiceStateViewAbi;
};
serviceProviderRegistry: {
address: Address;
abi: typeof serviceProviderRegistry;
};
sessionKeyRegistry: {
address: Address;
abi: typeof sessionKeyRegistryAbi;
};
pdp: {
address: Address;
abi: typeof pdpVerifierAbi;
};
endorsements: {
address: Address;
abi: typeof providerIdSetAbi;
};
}

Collection of contracts

contracts
.
usdfc: {
address: Address;
abi: typeof erc20WithPermit;
}
usdfc
.
address: `0x${string}`
address
,
amount: bigint
amount
:
function parseUnits(value: string, decimals: number): bigint

Multiplies a string representation of a number by a given exponent of base 10 (10exponent).

@example

import { parseUnits } from 'viem'

parseUnits('420', 9) // 420000000000n

parseUnits
("1", 18), // 1 USDFC
})
await
const publicClient: {
account: undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime: number;
ccipRead?: false | {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | undefined;
chain: Chain;
dataSuffix?: DataSuffix | undefined;
experimental_blockTag?: BlockTag | undefined;
key: string;
... 63 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
publicClient
.
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.

@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 withdrawTxHash: `0x${string}`
withdrawTxHash
})

List approved storage providers.

import * as
import warmStorage
warmStorage
from "@filoz/synapse-core/warm-storage"
// List approved providers
const
const providers: warmStorage.getApprovedProviders.OutputType
providers
= await
import warmStorage
warmStorage
.
function getApprovedProviders(client: Client<Transport, Chain>, options?: warmStorage.getApprovedProviders.OptionsType): Promise<warmStorage.getApprovedProviders.OutputType>
getApprovedProviders
(
const publicClient: {
account: undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime: number;
ccipRead?: false | {
request?: (parameters: CcipRequestParameters) => Promise<CcipRequestReturnType>;
} | undefined;
chain: Chain;
dataSuffix?: DataSuffix | undefined;
experimental_blockTag?: BlockTag | undefined;
key: string;
... 63 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
publicClient
)
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const providers: warmStorage.getApprovedProviders.OutputType
providers
) // bigint[] — approved provider IDs

Create a data set and upload a file.

import * as
import piece
piece
from "@filoz/synapse-core/piece"
import * as
import sp
sp
from "@filoz/synapse-core/sp"
import {
function getPDPProvider(client: Client<Transport, Chain>, options: getPDPProvider.OptionsType): Promise<getPDPProvider.OutputType>
getPDPProvider
} from "@filoz/synapse-core/sp-registry"
// 1. Select a provider
const
const provider: PDPProvider
provider
= await
function getPDPProvider(client: Client<Transport, Chain>, options: getPDPProvider.OptionsType): Promise<getPDPProvider.OutputType>
getPDPProvider
(
const walletClient: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
};
... 41 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
walletClient
, {
providerId: bigint
providerId
: 1n })
// 2. Calculate PieceCID and upload data
const
const pieceCid: PieceLink
pieceCid
=
import piece
piece
.
function calculate(data: Uint8Array): piece.PieceCID
calculate
(
const data: Uint8Array<ArrayBuffer>
data
)
const
const size: number
size
=
import piece
piece
.
function getSize(pieceCid: piece.PieceCID): number
getSize
(
const pieceCid: PieceLink
pieceCid
)
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const size: number
size
) // size of the piece in bytes
await
import sp
sp
.
function uploadPiece(options: sp.uploadPiece.OptionsType): Promise<void>
export uploadPiece
uploadPiece
({
data: Uint8Array<ArrayBufferLike>
data
,
pieceCid: PieceLink
pieceCid
,
serviceURL: string
serviceURL
:
const provider: PDPProvider
provider
.
PDPProvider.pdp: PDPOffering
pdp
.
PDPOffering.serviceURL: string
serviceURL
,
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Piece uploaded")
await
import sp
sp
.
function findPiece(options: sp.findPiece.OptionsType): Promise<sp.findPiece.OutputType>
export findPiece
findPiece
({
pieceCid: PieceLink
pieceCid
,
serviceURL: string
serviceURL
:
const provider: PDPProvider
provider
.
PDPProvider.pdp: PDPOffering
pdp
.
PDPOffering.serviceURL: string
serviceURL
,
retry?: boolean
retry
: true,
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Piece parked")
// 3. Create a data set and add the piece on-chain
const
const result: createDataSetAndAddPieces.OutputType
result
= await
import sp
sp
.
function createDataSetAndAddPieces(client: Client<Transport, Chain, Account>, options: sp.CreateDataSetAndAddPiecesOptions): Promise<sp.createDataSetAndAddPieces.ReturnType>
createDataSetAndAddPieces
(
const walletClient: {
account: {
address: Address;
nonceManager?: NonceManager | undefined;
sign: (parameters: {
hash: Hash;
}) => Promise<Hex>;
signAuthorization: (parameters: AuthorizationRequest) => Promise<SignAuthorizationReturnType>;
signMessage: ({ message }: {
message: SignableMessage;
}) => Promise<Hex>;
signTransaction: <serializer extends SerializeTransactionFn<TransactionSerializable> = SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
serializer?: serializer | undefined;
} | undefined) => Promise<Hex>;
signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
publicKey: Hex;
source: "privateKey";
type: "local";
};
... 41 more ...;
extend: <const client extends {
...;
} & ExactPartial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}
walletClient
, {
serviceURL: string
serviceURL
:
const provider: PDPProvider
provider
.
PDPProvider.pdp: PDPOffering
pdp
.
PDPOffering.serviceURL: string
serviceURL
,
payee: `0x${string}`
payee
:
const provider: PDPProvider
provider
.
payee: `0x${string}`
payee
,
cdn: boolean
cdn
: false,
pieces: {
pieceCid: piece.PieceCID;
metadata?: MetadataObject;
}[]
pieces
: [{
pieceCid: PieceLink
pieceCid
}],
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Creating data set and adding piece")
// 4. Wait for confirmation
const
const confirmed: sp.waitForCreateDataSetAddPieces.ReturnType
confirmed
= await
import sp
sp
.
function waitForCreateDataSetAddPieces(options: sp.waitForCreateDataSetAddPieces.OptionsType): Promise<sp.waitForCreateDataSetAddPieces.ReturnType>
waitForCreateDataSetAddPieces
({
statusUrl: string
statusUrl
:
const result: createDataSetAndAddPieces.OutputType
result
.
statusUrl: string
statusUrl
,
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const confirmed: sp.waitForCreateDataSetAddPieces.ReturnType
confirmed
.
dataSetId: bigint
dataSetId
) // bigint — on-chain data set ID
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const confirmed: sp.waitForCreateDataSetAddPieces.ReturnType
confirmed
.
piecesIds: bigint[]
piecesIds
) // bigint[] — confirmed piece IDs
For large files, use uploadPieceStreaming instead of uploadPiece:
// Stream upload — PieceCID is calculated during transfer
const
const stream: ReadableStream<Uint8Array<ArrayBufferLike>>
stream
= new
var ReadableStream: new <Uint8Array<ArrayBufferLike>>(underlyingSource: UnderlyingDefaultSource<Uint8Array<ArrayBufferLike>>, strategy?: QueuingStrategy<Uint8Array<ArrayBufferLike>> | undefined) => ReadableStream<Uint8Array<ArrayBufferLike>> (+2 overloads)
ReadableStream
<
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

Uint8Array
>({ /* ... */ })
const
const uploaded: sp.uploadPieceStreaming.OutputType
uploaded
= await
import sp
sp
.
function uploadPieceStreaming(options: sp.uploadPieceStreaming.OptionsType): Promise<sp.uploadPieceStreaming.OutputType>
export uploadPieceStreaming
uploadPieceStreaming
({
data: any
data
:
const stream: ReadableStream<Uint8Array<ArrayBufferLike>>
stream
,
serviceURL: string
serviceURL
,
onProgress?: (bytesUploaded: number) => void
onProgress
(
bytes: number
bytes
) {
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(`${
bytes: number
bytes
} bytes uploaded`)
},
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const uploaded: sp.uploadPieceStreaming.OutputType
uploaded
.
pieceCid: PieceLink
pieceCid
) // PieceCID — calculated from streamed data
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const uploaded: sp.uploadPieceStreaming.OutputType
uploaded
.
size: number
size
) // number — total bytes uploaded

Download a piece from a storage provider.

import {
function downloadAndValidate(options: downloadAndValidate.OptionsType): Promise<Uint8Array>
downloadAndValidate
} from "@filoz/synapse-core/piece"
// Download a piece
const
const data: Uint8Array<ArrayBufferLike>
data
= await
function downloadAndValidate(options: downloadAndValidate.OptionsType): Promise<Uint8Array>
downloadAndValidate
({
url: string
url
: `${
const provider: PDPProvider
provider
.
PDPProvider.pdp: PDPOffering
pdp
.
PDPOffering.serviceURL: string
serviceURL
}/piece`,
expectedPieceCid: string | PieceLink
expectedPieceCid
: "bafkzcib...",
})
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
(
const data: Uint8Array<ArrayBufferLike>
data
) // Uint8Array — downloaded piece data

Check out the Synapse Core Reference for all available modules and functions.