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
Synapseclass abstraction - Custom integrations that combine only the modules you need
Install dependencies:
npm install @filoz/synapse-core viemSynapse 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.
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:
- JSON-RPC Accounts (e.g. Browser Extension Wallets, WalletConnect, etc).
- Local Accounts (e.g. private key/mnemonic wallets).
createWalletClient, function http<rpcSchema extends RpcSchema | undefined = undefined, raw extends boolean = false>(url?: string | undefined, config?: HttpTransportConfig<rpcSchema, raw>): HttpTransport<rpcSchema, raw>
http } from "viem"import { function privateKeyToAccount(privateKey: Hex, options?: PrivateKeyToAccountOptions): PrivateKeyAccount
privateKeyToAccount } from "viem/accounts"import { const calibration: Chain
calibration, const mainnet: Chain
mainnet } from "@filoz/synapse-core/chains"
// Read-only client for queriesconst 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.
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>
http(),})
// Wallet client for transactionsconst 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
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:
- JSON-RPC Accounts (e.g. Browser Extension Wallets, WalletConnect, etc).
- Local Accounts (e.g. private key/mnemonic wallets).
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>
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.
Payments
Section titled “Payments”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).
parseUnits } from "viem"
// Query Filecoin Pay account info for the USDFC tokenconst 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.
log(const info: pay.accounts.OutputType
info.availableFunds: bigint
availableFunds) // bigint — funds available in Filecoin Pay
// Deposit USDFC in Filecoin Payconst 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).
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.
- Docs: https://viem.sh/docs/actions/public/waitForTransactionReceipt
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_sending-transactions
- JSON-RPC Methods:
- Polls
eth_getTransactionReceipt on each block until it has been processed.
- If a Transaction has been replaced:
- Calls
eth_getBlockByNumber and extracts the transactions
- Checks if one of the Transactions is a replacement
- If so, calls
eth_getTransactionReceipt.
waitForTransactionReceipt({ hash: `0x${string}`
The hash of the transaction.
hash: const depositTxHash: `0x${string}`
depositTxHash})
// Withdraw USDFC from Filecoin Payconst 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).
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.
- Docs: https://viem.sh/docs/actions/public/waitForTransactionReceipt
- Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_sending-transactions
- JSON-RPC Methods:
- Polls
eth_getTransactionReceipt on each block until it has been processed.
- If a Transaction has been replaced:
- Calls
eth_getBlockByNumber and extracts the transactions
- Checks if one of the Transactions is a replacement
- If so, calls
eth_getTransactionReceipt.
waitForTransactionReceipt({ hash: `0x${string}`
The hash of the transaction.
hash: const withdrawTxHash: `0x${string}`
withdrawTxHash})Storage
Section titled “Storage”List approved storage providers.
import * as import warmStorage
warmStorage from "@filoz/synapse-core/warm-storage"
// List approved providersconst 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.
log(const providers: warmStorage.getApprovedProviders.OutputType
providers) // bigint[] — approved provider IDsCreate 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 providerconst 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 dataconst 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.
log(const size: number
size) // size of the piece in bytesawait 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.
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.
log("Piece parked")
// 3. Create a data set and add the piece on-chainconst 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.
log("Creating data set and adding piece")
// 4. Wait for confirmationconst 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.
log(const confirmed: sp.waitForCreateDataSetAddPieces.ReturnType
confirmed.dataSetId: bigint
dataSetId) // bigint — on-chain data set IDvar console: Console
console.Console.log(...data: any[]): void
The console.log() static method outputs a message to the console.
log(const confirmed: sp.waitForCreateDataSetAddPieces.ReturnType
confirmed.piecesIds: bigint[]
piecesIds) // bigint[] — confirmed piece IDsFor large files, use uploadPieceStreaming instead of uploadPiece:
// Stream upload — PieceCID is calculated during transferconst 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.
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.
log(const uploaded: sp.uploadPieceStreaming.OutputType
uploaded.pieceCid: PieceLink
pieceCid) // PieceCID — calculated from streamed datavar console: Console
console.Console.log(...data: any[]): void
The console.log() static method outputs a message to the console.
log(const uploaded: sp.uploadPieceStreaming.OutputType
uploaded.size: number
size) // number — total bytes uploadedDownload a piece from a storage provider.
import { function downloadAndValidate(options: downloadAndValidate.OptionsType): Promise<Uint8Array>
downloadAndValidate } from "@filoz/synapse-core/piece"
// Download a piececonst 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.
log(const data: Uint8Array<ArrayBufferLike>
data) // Uint8Array — downloaded piece dataCheck out the Synapse Core Reference for all available modules and functions.