# selectReachableProviders

> **selectReachableProviders**(`client`, `options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/outputtype/)\>

Defined in: [packages/synapse-core/src/warm-storage/select-reachable-providers.ts:87](https://github.com/FilOzone/synapse-sdk/blob/5989c4b03ed2fe4cf8b1ef29efe1d4ff1ad4c7bc/packages/synapse-core/src/warm-storage/select-reachable-providers.ts#L87)

Select providers that answer a ping.

Fetches the selection input with [fetchProviderSelectionInput](/reference/filoz/synapse-core/warm-storage/functions/fetchproviderselectioninput/), ranks
candidates with [selectProviders](/reference/filoz/synapse-core/warm-storage/functions/selectproviders/), and pings them with [ping](/reference/filoz/synapse-core/sp/functions/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

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `client` | `Client`\<`Transport`, `Chain`\> | The client to use to fetch the selection input. |
| `options` | [`OptionsType`](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/optionstype/) | [selectReachableProviders.OptionsType](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/optionstype/) |

## Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`OutputType`](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/outputtype/)\>

Ranked locations [selectReachableProviders.OutputType](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/outputtype/).
  May be shorter than `count` if fewer reachable providers are available.

## Example

```ts
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

Errors [selectReachableProviders.ErrorType](/reference/filoz/synapse-core/warm-storage/namespaces/selectreachableproviders/type-aliases/errortype/). Throws
  `NoEndorsedProviderError` when `requireEndorsedPrimary` is set and no
  endorsed provider is eligible or answers, and with `signal.reason` when
  `signal` aborts.