# Simulate

> Documentation index: [llms.txt](https://namera.ai/llms.txt).

Source: https://namera.ai/docs/sdk/reference/executions/simulate

Simulate calls and evaluate the selected session key’s API policies.

`namera.executions.simulate(request)` does not sign, submit, or sponsor an operation.

## Usage [#usage]

Install `@namera-ai/sdk` and `viem`. Replace the example IDs and recipient with your own. The selected session must permit these calls on Base Sepolia.

<Tabs items={["index.ts", "client.ts"]}>
<Tab value="index.ts">

```ts title="index.ts"
import { namera } from "./client";
import type { SimulateExecutionRequest } from "@namera-ai/sdk";
import { parseEther } from "viem";

const request = {
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
} satisfies SimulateExecutionRequest;

const simulation = await namera.executions.simulate(request);
if (!simulation.success) throw new Error(simulation.error.message);

console.log(simulation.data);
```

</Tab>
<Tab value="client.ts">

```ts title="client.ts"
import { NameraClient } from "@namera-ai/sdk";

export const namera = new NameraClient({
  apiKey: process.env.NAMERA_API_KEY!,
});
```

</Tab>
</Tabs>

## Returns [#returns]

API methods return a `Promise<NameraResult<T, E>>`. When `success` is `true`,
`data` contains the value described below and `error` is `null`. On failure,
`data` is `null` and `error` describes the failure.

The JSON example shows the complete successful `data`, with illustrative values.
Date-time values use ISO strings in JSON; bigint values use decimal strings.
See [Handling Results and Errors](https://namera.ai/docs/sdk/handling-results-and-errors) for the error shape.

- **`namespace`** (`"eip155"`): Chain namespace.
- **`walletId`** (`string`): Account UUID.
- **`chainId`** (`SupportedEvmChainId`): Simulation network.
- **`account`** (`` `0x${string}` ``): Smart-account address.
- **`callsSucceeded`** (`boolean`): Whether the simulated calls succeeded.
- **`simulation`** (`EvmIntentSimulation`): userOperation gas estimates and calls results, assetChanges, and transfers.
- **`allowed`** (`boolean`): Point-in-time policy decision; not a guarantee of later execution.
- **`sessionKeyId`** (`string`): Present when allowed is true.
- **`denials`** (`readonly { sessionKeyId: string; policyId: string; code: EvmPolicyDenialCode }[]`): Nonempty when allowed is false; absent when allowed is true.

### Example Response [#example-response]

<div className="docs-response">

```json
{
  "namespace": "eip155",
  "walletId": "0199dfe1-0000-7000-8000-000000000001",
  "chainId": "eip155:84532",
  "account": "0x1111111111111111111111111111111111111111",
  "callsSucceeded": true,
  "simulation": {
    "userOperation": {
      "source": "eth_estimateUserOperationGas",
      "callGasLimit": "50000",
      "verificationGasLimit": "100000",
      "preVerificationGas": "50000",
      "maxFeePerGas": "1000000000",
      "maxPriorityFeePerGas": "1000000"
    },
    "calls": {
      "source": "viem.simulateCalls",
      "results": [
        {
          "status": "success",
          "returnData": "0x",
          "gasUsed": "21000"
        }
      ],
      "assetChanges": [],
      "transfers": [
        {
          "callIndex": 0,
          "from": "0x1111111111111111111111111111111111111111",
          "to": "0x2222222222222222222222222222222222222222",
          "value": "1000000000000000"
        }
      ]
    }
  },
  "allowed": true,
  "sessionKeyId": "0199dfe1-0000-7000-8000-000000000002"
}
```

</div>

## Parameters [#parameters]

Pass a `SimulateExecutionRequest` object. Simulation does not accept a `sponsor` field.

### namespace [#namespace]

- **Type:** `"eip155"`
- **Required**

The blockchain namespace. Use `"eip155"` for every currently supported Namera
network. This is not a chain ID; select the specific network with `chainId`.

```ts title="index.ts"
import { namera } from "./client";
import type { SimulateExecutionRequest } from "@namera-ai/sdk";
import { parseEther } from "viem";

const request = {
  namespace: "eip155", // [!code focus]
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
} satisfies SimulateExecutionRequest;

const simulation = await namera.executions.simulate(request);
if (!simulation.success) throw new Error(simulation.error.message);

console.log(simulation.data);
```

### walletId [#walletid]

- **Type:** `string`
- **Required**

The account UUID returned by `wallets.list()` or `wallets.get()`. Pass its `id`,
not its onchain `address`. The account must be accessible to the client’s credential.

```ts title="index.ts"
import { namera } from "./client";
import type { SimulateExecutionRequest } from "@namera-ai/sdk";
import { parseEther } from "viem";

const request = {
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001", // [!code focus]
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
} satisfies SimulateExecutionRequest;

const simulation = await namera.executions.simulate(request);
if (!simulation.success) throw new Error(simulation.error.message);

console.log(simulation.data);
```

### sessionKeyId [#sessionkeyid]

- **Type:** `string`
- **Required**

The session-key UUID returned by `sessionKeys.list()` or `sessionKeys.get()`.
This identifies the delegated session, not its signing key or network installation.
Your credential must have an active grant for this key.

For execution or signing, choose a key belonging to `walletId` with a confirmed
installation on `chainId` and permissions that allow the requested operation.

```ts title="index.ts"
import { namera } from "./client";
import type { SimulateExecutionRequest } from "@namera-ai/sdk";
import { parseEther } from "viem";

const request = {
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002", // [!code focus]
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
} satisfies SimulateExecutionRequest;

const simulation = await namera.executions.simulate(request);
if (!simulation.success) throw new Error(simulation.error.message);

console.log(simulation.data);
```

### chainId [#chainid]

- **Type:** `SupportedEvmChainId`
- **Required**

The target network in CAIP-2 format. For Base Sepolia, use `"eip155:84532"`,
not `84532` or `"84532"`. Use the network on which the account will execute, sign, or verify the payload.

The SDK restricts this field to the [supported network IDs](https://namera.ai/docs/sdk/supported-networks).
Network availability is also checked by the API.

```ts title="index.ts"
import { namera } from "./client";
import type { SimulateExecutionRequest } from "@namera-ai/sdk";
import { parseEther } from "viem";

const request = {
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532", // [!code focus]
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
} satisfies SimulateExecutionRequest;

const simulation = await namera.executions.simulate(request);
if (!simulation.success) throw new Error(simulation.error.message);

console.log(simulation.data);
```

### calls [#calls]

- **Type:** `readonly { to: EthereumAddress; value: bigint; data: Hex }[]`
- **Required**

One or more EVM calls, in execution order. Every call uses the same account,
network, and session key. Supply all three fields on each call; there are no
implicit values for `value` or `data`.

```ts title="index.ts"
import { namera } from "./client";
import { parseEther } from "viem";

const execution = await namera.executions.simulate({
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"), // [!code focus]
      data: "0x",
    },
  ],
});

if (!execution.success) throw new Error(execution.error.message);

console.log(execution.data);
```

#### calls.to [#callsto]

- **Type:** `EthereumAddress` (`` `0x${string}` ``)
- **Required**

The 20-byte recipient or contract address. Native transfers target the recipient;
contract calls target the contract, not the recipient encoded in its arguments.
The session’s permissions must allow this target.

```ts title="index.ts"
import { namera } from "./client";
import { parseEther } from "viem";

const execution = await namera.executions.simulate({
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222", // [!code focus]
      value: parseEther("0.001"),
      data: "0x",
    },
  ],
});

if (!execution.success) throw new Error(execution.error.message);

console.log(execution.data);
```

#### calls.value [#callsvalue]

- **Type:** `bigint`
- **Required**

The native-token amount in wei. Use `parseEther("0.001")` for 0.001 ETH or `0n`
for a call that sends no native tokens. Negative amounts are rejected. ERC-20
amounts belong in encoded calldata, not this field.

```ts title="index.ts"
import { namera } from "./client";
import { parseEther } from "viem";

const execution = await namera.executions.simulate({
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x2222222222222222222222222222222222222222",
      value: parseEther("0.001"), // [!code focus]
      data: "0x",
    },
  ],
});

if (!execution.success) throw new Error(execution.error.message);

console.log(execution.data);
```

#### calls.data [#callsdata]

- **Type:** `Hex` (`` `0x${string}` ``)
- **Required**

The encoded contract call. Use `"0x"` for a native transfer. For contract functions,
use viem’s `encodeFunctionData`; the SDK does not accept `abi`, `functionName`, or
`args` directly in a call.

```ts title="index.ts"
import { namera } from "./client";
import { encodeFunctionData, erc20Abi, parseUnits } from "viem";

const result = await namera.executions.simulate({
  namespace: "eip155",
  walletId: "0199dfe1-0000-7000-8000-000000000001",
  sessionKeyId: "0199dfe1-0000-7000-8000-000000000002",
  chainId: "eip155:84532",
  calls: [
    {
      to: "0x3333333333333333333333333333333333333333",
      value: 0n,
      data: encodeFunctionData({
        // [!code focus:5]
        abi: erc20Abi,
        functionName: "transfer",
        args: ["0x2222222222222222222222222222222222222222", parseUnits("1", 6)],
      }),
    },
  ],
});
if (!result.success) throw new Error(result.error.message);

console.log(result.data);
```

This encodes a transfer of one token with six decimals. Use your token’s actual
decimals and pass its contract address as `to`.

## Errors [#errors]

Execution, authorization, and network failures return `success: false`. See [Handling Results and Errors](https://namera.ai/docs/sdk/handling-results-and-errors)
for authentication, transport, and contract errors.

Guide: [Simulate Transactions](https://namera.ai/docs/sdk/guides/transactions/simulate-transactions).
