# Evm.setInspector

Installs an inspector, so executions record what they did.

A trace comes back on the result of each execution afterwards. Recording cannot change what executes: the same transaction produces the same result traced or not.

## Imports

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

```ts [Entrypoint]
import * as Evm from 'ox/evm/Evm'
```
:::

## Examples

```ts twoslash
// @noErrors
import { Evm, Inspector } from 'ox/evm'

// Calls, creates, logs, and self-destructs. Cheap enough to leave on.
Evm.setInspector(evm, {})

const result = Evm.callTx(evm, transaction)
Inspector.tree(result.trace)
```

### Recording instructions

```ts twoslash
// @noErrors
import { Evm, Inspector } from 'ox/evm'

// Millions of events for a busy transaction, so bound it and expect
// `truncated`.
Evm.setInspector(evm, {
  limit: 4_000_000,
  stack: true,
  steps: true
})

const result = Evm.callTx(evm, transaction)
Inspector.steps(result.trace)
```

## Definition

```ts
function setInspector<asynchronous>(
  evm: Evm<asynchronous>,
  options?: Inspector.Options,
): Awaitable<asynchronous, void>
```

**Source:** [src/evm/Evm.ts](https://github.com/wevm/ox/blob/main/src/evm/Evm.ts#L816)

## Parameters

### evm

* **Type:** `Evm<asynchronous>`

EVM to inspect.

#### evm.'~async'

* **Type:** `asynchronous`

#### evm.'~chainId'

* **Type:** `bigint`

#### evm.'~config'

* **Type:** `{ block: Block; specId: "frontier" | "homestead" | "tangerine" | "spuriousDragon" | "byzantium" | "petersburg" | "istanbul" | "berlin" | "london" | "merge" | "shanghai" | "cancun" | "prague" | "osaka" | "amsterdam"; version?: Version; }`

The engine's current execution config.

Held so a setter can replace one half without discarding the other, since
the adapter's operation carries both.

#### evm.'~driver'

* **Type:** `asynchronous extends true ? Driver : undefined`

Drives the asynchronous source, when there is one.

#### evm.'~engine'

* **Type:** `Engine`

#### evm.block

* **Type:** `Block`

#### evm.specId

* **Type:** `"frontier" | "homestead" | "tangerine" | "spuriousDragon" | "byzantium" | "petersburg" | "istanbul" | "berlin" | "london" | "merge" | "shanghai" | "cancun" | "prague" | "osaka" | "amsterdam"`

#### evm.version

* **Type:** `Version`
* **Optional**

### options

* **Type:** `Inspector.Options`
* **Optional**

What to record.

#### options.limit

* **Type:** `number`
* **Optional**

Largest trace to keep, in bytes.

Recording stops at the limit and the trace reports `truncated`, keeping what
ran first: a trace is always a prefix of the execution, never a stream with
gaps. Execution is unaffected either way.

#### options.memory

* **Type:** `boolean`
* **Optional**

Records memory size on each instruction. Requires `steps`.

#### options.stack

* **Type:** `boolean`
* **Optional**

Records the stack on each instruction. Requires `steps`.

#### options.steps

* **Type:** `boolean`
* **Optional**

Records every instruction.

Off by default, and worth leaving off: a mainnet transaction runs millions of
instructions, where calls, creates, and logs number in the tens. Turn this on
to debug a specific execution, not to observe one in production.

## Return Type

`Awaitable<asynchronous, void>`
