Skip to content

React Integration

Install dependencies:

Terminal window
npm install @filoz/synapse-react wagmi viem @tanstack/react-query

Requirements:

  • React 18+, Wagmi 3.x, viem 2.x, TanStack Query 5.x
  • Connected Web3 wallet
  • Supported networks: Filecoin Mainnet, Filecoin Calibration

Wagmi config:

import {
const calibration: Chain
calibration
,
const mainnet: Chain
mainnet
} from "@filoz/synapse-core/chains";
import {
function createConfig<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]["id"], Transport>, const connectorFns extends readonly CreateConnectorFn[]>(parameters: CreateConfigParameters<chains, transports, connectorFns>): Config<chains, transports, connectorFns>
createConfig
,
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 "wagmi";
export const
const wagmiConfig: Config<readonly [Chain, Chain], {
[mainnet.id]: HttpTransport<undefined, false>;
[calibration.id]: HttpTransport<undefined, false>;
}, readonly CreateConnectorFn[]>
wagmiConfig
=
createConfig<readonly [Chain, Chain], {
[mainnet.id]: HttpTransport<undefined, false>;
[calibration.id]: HttpTransport<undefined, false>;
}, readonly CreateConnectorFn[]>(parameters: CreateConfigParameters<readonly [Chain, Chain], {
[mainnet.id]: HttpTransport<undefined, false>;
[calibration.id]: HttpTransport<undefined, false>;
}, readonly CreateConnectorFn[]>): Config<readonly [Chain, Chain], {
[mainnet.id]: HttpTransport<undefined, false>;
[calibration.id]: HttpTransport<undefined, false>;
}, readonly CreateConnectorFn[]>
createConfig
({
chains: readonly [Chain, Chain]
chains
: [
const calibration: Chain
calibration
,
const mainnet: Chain
mainnet
],
transports: {
[mainnet.id]: HttpTransport<undefined, false>;
[calibration.id]: HttpTransport<undefined, false>;
}
transports
: {
[
const mainnet: Chain
mainnet
.
id: number

ID in number form

id
]:
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
(),
[
const calibration: Chain
calibration
.
id: number

ID in number form

id
]:
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
(),
},
});

Provider setup:

Synapse React hooks work within Wagmi and TanStack Query providers. Set these up at the root of your app:

import {
class QueryClient
QueryClient
,
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
} from "@tanstack/react-query";
import {
function WagmiProvider(parameters: React.PropsWithChildren<WagmiProviderProps>): FunctionComponentElement<PropsWithChildren<HydrateProps>>
WagmiProvider
} from "wagmi";
const
const queryClient: QueryClient
queryClient
= new
new QueryClient(config?: QueryClientConfig): QueryClient
QueryClient
();
export default function
function App(): JSX.Element
App
() {
return (
<
function WagmiProvider(parameters: React.PropsWithChildren<WagmiProviderProps>): FunctionComponentElement<PropsWithChildren<HydrateProps>>
WagmiProvider
config: Config
config
={
const config: Config
config
}>
<
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
client: QueryClient
client
={
const queryClient: QueryClient
queryClient
}>
<
const YourApp: () => JSX.Element
YourApp
/>
</
const QueryClientProvider: ({ client, children, }: QueryClientProviderProps) => React.JSX.Element
QueryClientProvider
>
</
function WagmiProvider(parameters: React.PropsWithChildren<WagmiProviderProps>): FunctionComponentElement<PropsWithChildren<HydrateProps>>
WagmiProvider
>
);
}

Query account info and make deposits using hooks:

import {
function useAccountInfo(props?: UseAccountInfoProps): UseQueryResult<accounts.OutputType, Error>
useAccountInfo
,
function useDepositAndApprove(props?: UseDepositAndApproveProps): UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
useDepositAndApprove
} from "@filoz/synapse-react";
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";
import {
function useAccount<config extends Config = Config>(parameters?: UseConnectionParameters<config>): UseConnectionReturnType<config>
useAccount
} from "wagmi";
const
const PaymentsExample: () => JSX.Element
PaymentsExample
= () => {
const {
const address: `0x${string}` | undefined
address
} =
useAccount<Config>(parameters?: UseConnectionParameters<Config> | undefined): UseConnectionReturnType<Config>
useAccount
();
const {
data: accounts.OutputType | undefined

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

data
:
const account: accounts.OutputType | undefined

The last successfully resolved data for the query.

account
,
const isLoading: boolean

Is true whenever the first fetch for a query is in-flight.

  • Is the same as isFetching && isPending.

isLoading
} =
function useAccountInfo(props?: UseAccountInfoProps): UseQueryResult<accounts.OutputType, Error>
useAccountInfo
(
const address: `0x${string}` | undefined
address
? {
address?: `0x${string}`
address
,
UseAccountInfoProps.watch?: boolean
watch
: true } : {
UseAccountInfoProps.watch?: boolean
watch
: true }
);
const
const deposit: UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
deposit
=
function useDepositAndApprove(props?: UseDepositAndApproveProps): UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
useDepositAndApprove
({
UseDepositAndApproveProps.onHash?: (hash: string) => void
onHash
: (
hash: string
hash
) =>
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Tx:",
hash: string
hash
),
});
if (!
const address: `0x${string}` | undefined
address
) return <
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>Connect wallet</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>;
if (
const isLoading: boolean

Is true whenever the first fetch for a query is in-flight.

  • Is the same as isFetching && isPending.

isLoading
) return <
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>Loading...</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>;
return (
<
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Available: {
const account: accounts.OutputType | undefined

The last successfully resolved data for the query.

account
?.
availableFunds: bigint
availableFunds
.
BigInt.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings.

toString
()} USDFC</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
DOMAttributes<HTMLButtonElement>.onClick?: MouseEventHandler<HTMLButtonElement> | undefined
onClick
={() =>
const deposit: UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
deposit
.
mutate: (variables: UseDepositAndApproveVariables, options?: MutateOptions<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown> | undefined) => void

The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options.

@paramvariables - The variables object to pass to the mutationFn.

@paramoptions.onSuccess - This function will fire when the mutation is successful and will be passed the mutation's result.

@paramoptions.onError - This function will fire if the mutation encounters an error and will be passed the error.

@paramoptions.onSettled - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error.

mutate
({
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) })}
ButtonHTMLAttributes<HTMLButtonElement>.disabled?: boolean | undefined
disabled
={
const deposit: UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
deposit
.
isPending: boolean

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

isPending
}
>
{
const deposit: UseMutationResult<TransactionReceipt, Error, UseDepositAndApproveVariables, unknown>
deposit
.
isPending: boolean

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

isPending
? "Depositing..." : "Deposit 1 USDFC"}
</
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>
</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
);
};

Upload files and list data sets:

import {
function useUpload(props: UseUploadProps): UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
useUpload
,
function useDataSets(props: UseDataSetsProps): UseQueryResult<{
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[], Error>
useDataSets
,
function useProviders(props?: UseProvidersProps): UseQueryResult<getApprovedPDPProviders.OutputType, Error>
useProviders
} from "@filoz/synapse-react";
import {
function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version16.8.0

@seehttps://react.dev/reference/react/useState

useState
} from "react";
import {
function useAccount<config extends Config = Config>(parameters?: UseConnectionParameters<config>): UseConnectionReturnType<config>
useAccount
} from "wagmi";
const
const StorageExample: () => JSX.Element
StorageExample
= () => {
const {
const address: `0x${string}` | undefined
address
} =
useAccount<Config>(parameters?: UseConnectionParameters<Config> | undefined): UseConnectionReturnType<Config>
useAccount
();
const {
data: getApprovedPDPProviders.OutputType | undefined

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

data
:
const providers: getApprovedPDPProviders.OutputType | undefined

The last successfully resolved data for the query.

providers
} =
function useProviders(props?: UseProvidersProps): UseQueryResult<getApprovedPDPProviders.OutputType, Error>
useProviders
();
const {
data: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[] | undefined

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

The last successfully resolved data for the query.

data
:
const dataSets: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[] | undefined

The last successfully resolved data for the query.

dataSets
} =
function useDataSets(props: UseDataSetsProps): UseQueryResult<{
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[], Error>
useDataSets
(
const address: `0x${string}` | undefined
address
? {
UseDataSetsProps.address?: `0x${string}`
address
} : {});
const [
const files: File[]
files
,
const setFiles: Dispatch<SetStateAction<File[]>>
setFiles
] =
useState<File[]>(initialState: File[] | (() => File[])): [File[], Dispatch<SetStateAction<File[]>>] (+1 overload)

Returns a stateful value, and a function to update it.

@version16.8.0

@seehttps://react.dev/reference/react/useState

useState
<
interface File

The File interface provides information about files and allows JavaScript in a web page to access their content.

MDN Reference

File
[]>([]);
const
const upload: UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
upload
=
function useUpload(props: UseUploadProps): UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
useUpload
({
UseUploadProps.onHash?: (hash: string) => void
onHash
: (
hash: string
hash
) =>
var console: Console
console
.
Console.log(...data: any[]): void

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

MDN Reference

log
("Tx:",
hash: string
hash
),
});
if (!
const address: `0x${string}` | undefined
address
) return <
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>Connect wallet</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>;
return (
<
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Providers: {
const providers: getApprovedPDPProviders.OutputType | undefined

The last successfully resolved data for the query.

providers
?.
Array<T>.length: number | undefined

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

length
?? 0}</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Data sets: {
const dataSets: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[] | undefined

The last successfully resolved data for the query.

dataSets
?.
Array<T>.length: number | undefined

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

length
?? 0}</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
{
const dataSets: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[] | undefined

The last successfully resolved data for the query.

dataSets
?.
Array<{ pieces: PieceWithMetadata[]; pdpRailId: bigint; cacheMissRailId: bigint; cdnRailId: bigint; payer: Address; payee: Address; ... 10 more ...; provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider; }>.map<U>(callbackfn: (value: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}, index: number, array: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}[]) => U, thisArg?: any): U[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
) => (
<
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
Attributes.key?: Key | null | undefined
key
={
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
.
dataSetId: bigint
dataSetId
.
BigInt.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings.

toString
()}>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Dataset {
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
.
dataSetId: bigint
dataSetId
.
BigInt.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings.

toString
()}: {
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
.
pieces: PieceWithMetadata[]
pieces
.
Array<T>.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</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
<
JSX.IntrinsicElements.input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
input
InputHTMLAttributes<HTMLInputElement>.type?: HTMLInputTypeAttribute | undefined
type
="file"
InputHTMLAttributes<HTMLInputElement>.multiple?: boolean | undefined
multiple
InputHTMLAttributes<HTMLInputElement>.onChange?: ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined
onChange
={(
e: ChangeEvent<HTMLInputElement, HTMLInputElement>
e
) =>
e: ChangeEvent<HTMLInputElement, HTMLInputElement>
e
.
ChangeEvent<HTMLInputElement, HTMLInputElement>.target: EventTarget & HTMLInputElement
target
.
HTMLInputElement.files: FileList | null

The HTMLInputElement.files property allows you to access the FileList selected with the <input type='file'> element.

MDN Reference

files
&&
const setFiles: (value: SetStateAction<File[]>) => void
setFiles
(
var Array: ArrayConstructor
Array
.
ArrayConstructor.from<File>(iterable: Iterable<File> | ArrayLike<File>): File[] (+3 overloads)

Creates an array from an iterable object.

@paramiterable An iterable object to convert to an array.

from
(
e: ChangeEvent<HTMLInputElement, HTMLInputElement>
e
.
ChangeEvent<HTMLInputElement, HTMLInputElement>.target: EventTarget & HTMLInputElement
target
.
HTMLInputElement.files: FileList

The HTMLInputElement.files property allows you to access the FileList selected with the <input type='file'> element.

MDN Reference

files
))
}
/>
<
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
DOMAttributes<HTMLButtonElement>.onClick?: MouseEventHandler<HTMLButtonElement> | undefined
onClick
={() =>
const upload: UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
upload
.
mutate: (variables: UseUploadVariables, options?: MutateOptions<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown> | undefined) => void

The mutation function you can call with variables to trigger the mutation and optionally hooks on additional callback options.

@paramvariables - The variables object to pass to the mutationFn.

@paramoptions.onSuccess - This function will fire when the mutation is successful and will be passed the mutation's result.

@paramoptions.onError - This function will fire if the mutation encounters an error and will be passed the error.

@paramoptions.onSettled - This function will fire when the mutation is either successfully fetched or encounters an error and be passed either the data or error.

mutate
({
UseUploadVariables.files: File[]
files
,
UseUploadVariables.dataSetId: bigint
dataSetId
:
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
.
dataSetId: bigint
dataSetId
})}
ButtonHTMLAttributes<HTMLButtonElement>.disabled?: boolean | undefined
disabled
={
const upload: UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
upload
.
isPending: boolean

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

isPending
||
const files: File[]
files
.
Array<File>.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}
>
{
const upload: UseMutationResult<{
txHash: `0x${string}`;
txStatus: "confirmed";
dataSetId: bigint;
pieceCount: number;
addMessageOk: true;
piecesAdded: true;
confirmedPieceIds: bigint[];
}, Error, UseUploadVariables, unknown>
upload
.
isPending: boolean

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

A boolean variable derived from status.

  • true if the mutation is currently executing.

isPending
? "Uploading..." : "Upload"}
</
JSX.IntrinsicElements.button: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
button
>
{
ds: {
pieces: PieceWithMetadata[];
pdpRailId: bigint;
cacheMissRailId: bigint;
cdnRailId: bigint;
payer: Address;
payee: Address;
serviceProvider: Address;
commissionBps: bigint;
clientDataSetId: bigint;
pdpEndEpoch: bigint;
providerId: bigint;
dataSetId: bigint;
live: boolean;
managed: boolean;
cdn: boolean;
metadata: import("/opt/buildhome/repo/packages/synapse-core/dist/src/types").MetadataObject;
provider: import("/opt/buildhome/repo/packages/synapse-core/dist/src/sp-registry/types").PDPProvider;
}
ds
.
pieces: PieceWithMetadata[]
pieces
.
Array<PieceWithMetadata>.map<JSX.Element>(callbackfn: (value: PieceWithMetadata, index: number, array: PieceWithMetadata[]) => JSX.Element, thisArg?: any): JSX.Element[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
p: PieceWithMetadata
p
) => (
<
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
Attributes.key?: Key | null | undefined
key
={
p: PieceWithMetadata
p
.
Piece.id: bigint
id
.
BigInt.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings.

toString
()}>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Piece {
p: PieceWithMetadata
p
.
Piece.id: bigint
id
.
BigInt.toString(radix?: number): string

Returns a string representation of an object.

@paramradix Specifies a radix for converting numeric values to strings.

toString
()}: {
p: PieceWithMetadata
p
.
Piece.cid: PieceLink
cid
.
Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, 1>.toV1(): Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, 1>
toV1
().
Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, 1>.toString<string>(base?: MultibaseEncoder<string> | undefined): ToString<Link<MerkleTreeNode, RAW_CODE, MulticodecCode<4113, "fr32-sha2-256-trunc254-padded-binary-tree">, Version>, string>

Returns a string representation of an object.

toString
()}</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>URL: {
p: PieceWithMetadata
p
.
Piece.url: string
url
}</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
<
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>Metadata: {
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
p: PieceWithMetadata
p
.
PieceWithMetadata.metadata: MetadataObject
metadata
)}</
JSX.IntrinsicElements.p: DetailedHTMLProps<HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
p
>
</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
))}
</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
))}
</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
);
};

Check out the Synapse React Reference for all available query and mutation hooks.