Skip to content

selectReachableProviders

selectReachableProviders(client, options): Promise<OutputType>

Defined in: packages/synapse-core/src/warm-storage/select-reachable-providers.ts:87

Select providers that answer a ping.

Fetches the selection input with fetchProviderSelectionInput, ranks candidates with selectProviders, and pings them with ping. A candidate that fails its ping is excluded and the next one is tried, so every returned location is from a provider that answered.

With requireEndorsedPrimary, every endorsed candidate for the first location is pinged concurrently and the highest-ranked one that answers wins, so a faster, lower-ranked provider cannot displace it. The other locations are pinged one candidate at a time.

Parameter Type Description
client Client<Transport, Chain> The client to use to fetch the selection input.
options OptionsType selectReachableProviders.OptionsType

Promise<OutputType>

Ranked locations selectReachableProviders.OutputType. May be shorter than count if fewer reachable providers are available.

import { selectReachableProviders } from '@filoz/synapse-core/warm-storage'
import { createPublicClient, http } from 'viem'
import { calibration } from '@filoz/synapse-core/chains'

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

const [primary, secondary] = await selectReachableProviders(client, {
  address: '0x1234567890123456789012345678901234567890',
  metadata: { source: 'my-app' },
  count: 2,
  requireEndorsedPrimary: true,
})

console.log(primary.provider.id, primary.dataSetId)

Errors selectReachableProviders.ErrorType. Throws NoEndorsedProviderError when requireEndorsedPrimary is set and no endorsed provider is eligible or answers, and with signal.reason when signal aborts.