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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
client |
Client<Transport, Chain> |
The client to use to fetch the selection input. |
options |
OptionsType |
selectReachableProviders.OptionsType |
Returns
Section titled “Returns”Ranked locations selectReachableProviders.OutputType.
May be shorter than count if fewer reachable providers are available.
Example
Section titled “Example”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)Throws
Section titled “Throws”Errors selectReachableProviders.ErrorType. Throws
NoEndorsedProviderError when requireEndorsedPrimary is set and no
endorsed provider is eligible or answers, and with signal.reason when
signal aborts.