# withSignal

> **withSignal**\<`transport`\>(`transport`, `signal`): `transport`

Defined in: [packages/synapse-core/src/utils/abort.ts:87](https://github.com/FilOzone/synapse-sdk/blob/840d7b2c6263846ac51b7558000e62dd68d33a44/packages/synapse-core/src/utils/abort.ts#L87)

Wrap a viem transport so its requests reject with iso-web's AbortError once the signal aborts.

:::caution[Deprecated]
  Use viem's `client.scope({ signal })`, which aborts requests in flight, stops the
transport's retries and keeps its request timeout. Wrap calls in [abortable](/reference/filoz/synapse-core/utils/functions/abortable/) for an
iso-web AbortError.

Unlike passing `fetchOptions.signal` to viem's `http` transport, this keeps the transport's own
request timeout and retries. For the default Filecoin transports, `getTransport(chain, { signal })`
does this for you. Requests in flight are not cancelled, only the wait for them; requests
made after the signal aborted reject without being sent.

Limits:
- Contract reads reject with viem's `ContractFunctionExecutionError`, with the AbortError in its
  `cause` chain. Wrap the call in [abortable](/reference/filoz/synapse-core/utils/functions/abortable/) to reject with the AbortError itself.
- The transport's retries for a request in flight keep sending after the abort; the caller only
  stops waiting for them.
- viem's `waitForTransactionReceipt` swallows polling errors, so on a `withSignal` client it runs
  until its timeout. Pass the signal to its `signal` option instead.
  :::

## Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| <a id="type-parameter-transport"></a> `transport` *extends* `Transport` | The transport to wrap. |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `transport` | `transport` | - |
| `signal` | [`AbortSignal`](https://developer.mozilla.org/docs/Web/API/AbortSignal) \| `undefined` | The signal to abort requests. The transport is returned as is when undefined. |

## Returns

`transport`

The wrapped transport.

## Example

```ts
import { createPublicClient, http } from 'viem'
import { calibration } from '@filoz/synapse-core/chains'
import { withSignal } from '@filoz/synapse-core/utils'

const controller = new AbortController()
const client = createPublicClient({
  chain: calibration,
  transport: withSignal(http('https://my-rpc.example.com'), controller.signal),
})
```