Skip to content

getPieces

getPieces(client, options): Promise<OutputType>

Defined in: packages/synapse-core/src/pdp-verifier/get-pieces.ts:73

Get one bounded page of visible pieces for a data set.

Pieces remain visible without an active provider; their URL is null unless CDN retrieval is configured for the data set and chain.

Pieces scheduled for removal are filtered from items, while nextCursor continues to describe the unfiltered source page. A page can therefore be empty and still have a continuation. Treat it as opaque and use paginate to traverse every page.

Parameter Type Description
client Client<Transport, Chain> The client to use to get the pieces.
options { address: `0x${string}`; contractAddress?: `0x${string}`; cursor?: bigint; dataSet: PdpDataSet; limit?: bigint; } getPieces.OptionsType
options.address `0x${string}` The address of the user.
options.contractAddress? `0x${string}` Optional PDPVerifier contract address override.
options.cursor? bigint Opaque continuation cursor returned by the previous page. Defaults to 0n.
options.dataSet PdpDataSet The data set to get the pieces from.
options.limit? bigint Maximum number of items to return. Must be greater than 0n.

Promise<OutputType>

The active pieces for the data set getPieces.OutputType

Read the first page

import { getPieces } from '@filoz/synapse-core/pdp-verifier'
import { calibration } from '@filoz/synapse-core/chains'
import { createPublicClient, http } from 'viem'

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

const address = '0x0000000000000000000000000000000000000000'
const page = await getPieces(client, { dataSet, address })
console.log(page.items, page.nextCursor)

Iterate over every page

import { paginate } from '@filoz/synapse-core'
import { getPieces } from '@filoz/synapse-core/pdp-verifier'

for await (const piece of paginate(({ cursor }) =>
  getPieces(client, { dataSet, address, cursor })
)) {
  console.log(piece.id, piece.cid, piece.url)
}

Errors getPieces.ErrorType