# simulateTransaction

> import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import CreditCost from '@site/src/components/CreditCost/CreditCostPrice.js'

# `simulateTransaction`

Simulate sending a transaction. <CreditCost network="solana" method="simulateTransaction" />

This method is useful for testing and debugging transactions before sending them to the network.

## Parameters

- `transaction`: (string) _[required]_ - The transaction as an encoded string. The transaction must have a valid
  block hash, but doesn't need to be signed.
- `config`: (object) _[optional]_ - Configuration object with the following options:
  - `commitment`: (string) _[optional]_ - The commitment level to use for the query. The default is `finalized`. Possible values are:
    - `finalized` - Queries the most recent block confirmed by a super majority of the cluster as having
      reached maximum lockout, meaning the cluster has recognized this block as finalized.
    - `confirmed` - Queries the most recent block that has been voted on by a super majority of the cluster.
    - `processed` - Queries its most recent block. The block may still be skipped by the cluster.
  - `sigVerify`: (boolean) _[optional]_ - If `true`, verifies the signatures in the transaction.
    Conflicts with `replaceRecentBlockhash`. The default is `false`.
  - `replaceRecentBlockhash`: (boolean) _[optional]_ - If `true`, replaces the recent block hash in the transaction with the
    latest block hash. Conflicts with `sigVerify`. The default is `false`.
  - `encoding`: (string) _[optional]_ - The encoding format to use. Can be one of `base58` (deprecated) or `base64`.
  - `minContextSlot`: _[optional]_ - The minimum slot to use for the query.
  - `innerInstructions`: (boolean) _[optional]_ - If `true`, returns the inner instructions of the transaction.
    The inner instructions will be `jsonParsed` where possible, otherwise `json`.
  - `accounts`: (object) _[optional]_ - An object containing the following fields:
    - `addresses`: (array) _[optional]_ - An array of addresses to include in the response.
    - `encoding`: (string) _[optional]_ - The encoding format to use. Can be one of `base58`, `base64`, `base64+zstd`,
      or `jsonParsed`.

## Returns

`result` - `null` if the account doesn't exist; otherwise an object with the following fields:

- `context` - An object containing the following keys:
  - `slot` - The slot number of the block that was queried.
  - `apiVersion` - The API version used for the query.
- `value` - An object with the following fields:
  - `err` - An error if transaction failed, `null` if transaction succeeded.
  - `logs` - An array of log messages generated by the transaction. Returns `null` if the simulation failed.
  - `accounts` -
    - `data` - The account data, encoded in the specified format.
    - `executable` - A boolean indicating whether the account is executable.
    - `lamports` - The number of lamports in the account.
    - `owner` - The public key of the program that owns the account.
    - `rentEpoch` - The epoch in which the account will next be due for rent.
    - `space` - The size of the account data in bytes.
  - `unitsConsumed` - The number of compute units consumed by the transaction.
  - `returnData` - An array of objects containing the following fields:
    - `programId` - The public key of the program that executed the transaction.
    - `data` - The account data, encoded as `base64` binary data.
  - `innerInstructions` - An array of [inner instructions](https://solana.com/docs/rpc/json-structures#inner-instructions).

### Request

<Tabs>
  <TabItem value="curl">

```bash
curl https://solana-testnet.infura.io/v3/<YOUR-API-KEY> \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "simulateTransaction", "params": ["AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=", {"encoding": "base64"}]}'
```

  </TabItem>
</Tabs>

### Response

<Tabs>
  <TabItem value="JSON">

```bash
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 218 },
    "value": {
      "err": null,
      "accounts": null,
      "logs": [
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri invoke [1]",
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri consumed 2366 of 1400000 compute units",
        "Program return: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri KgAAAAAAAAA=",
        "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success"
      ],
      "returnData": {
        "data": ["Kg==", "base64"],
        "programId": "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
      },
      "unitsConsumed": 2366
    }
  },
  "id": 1
}
```

  </TabItem>
</Tabs>
