# withSignal

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

Defined in: [packages/synapse-core/src/utils/abort.ts:82](https://github.com/FilOzone/synapse-sdk/blob/5989c4b03ed2fe4cf8b1ef29efe1d4ff1ad4c7bc/packages/synapse-core/src/utils/abort.ts#L82)

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

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. Wrap receipt waits in [abortable](/reference/filoz/synapse-core/utils/functions/abortable/) 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),
})
```