# Engine.with

Runs a function with an engine installed, then restores the previous engine.

Only safe for synchronous functions: the engine is process-wide for the duration of the call, so concurrent asynchronous work would observe it too. Passing a function that returns a promise throws [`Engine.AsyncScopeError`](/node/crypto/Engine/errors#asyncscopeerror).

## Imports

:::code-group
```ts [Named]
import { Engine } from 'ox/node'
```

```ts [Entrypoint]
import * as Engine from 'ox/node/Engine'
```
:::

## Examples

```ts twoslash
import { Engine, Hash } from 'ox'

const hash = Engine.with(
  { Hash: { keccak256: () => new Uint8Array(32) } },
  () => Hash.keccak256('0xdeadbeef')
)
// @log: '0x0000000000000000000000000000000000000000000000000000000000000000'
```

## Definition

```ts
function with<returnType>(
  value: engine.Engine,
  fn: () => returnType,
): returnType
```

**Source:** [src/core/Engine.ts](https://github.com/wevm/ox/blob/main/src/core/Engine.ts#L221)

## Parameters

### value

* **Type:** `engine.Engine`

Engine to install for the duration of the call.

#### value.Bls

* **Type:** `Bls`
* **Optional**

Implementation for [`Bls`](/api/Bls).

#### value.Ed25519

* **Type:** `Eddsa`
* **Optional**

Implementation for [`Ed25519`](/api/Ed25519).

#### value.Hash

* **Type:** `Hash`
* **Optional**

Implementation for [`Hash`](/api/Hash).

#### value.Keystore

* **Type:** `Keystore`
* **Optional**

Implementation for [`Keystore`](/api/Keystore).

#### value.Mnemonic

* **Type:** `Mnemonic`
* **Optional**

Implementation for [`Mnemonic`](/api/Mnemonic).

#### value.P256

* **Type:** `Ecdsa`
* **Optional**

Implementation for [`P256`](/api/P256).

#### value.Secp256k1

* **Type:** `Ecdsa`
* **Optional**

Implementation for [`Secp256k1`](/api/Secp256k1).

#### value.X25519

* **Type:** `Ecdh`
* **Optional**

Implementation for [`X25519`](/api/X25519).

### fn

* **Type:** `() => returnType`

Synchronous function to run.

## Return Type

The return value of `fn`.

`returnType`
