# simulateTransaction

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://solana-mainnet.g.alchemy.com/v2/{apiKey}

Simulates sending a transaction.

Reference: https://www.alchemy.com/docs/chains/solana/solana-api-endpoints/simulate-transaction

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| Transaction | string | Yes | The transaction to simulate, as an encoded string. |
| Configuration | object | No | Optional configuration object containing additional options. |

## Result

**Simulated transaction result** (object): The result of simulating the transaction.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "simulateTransaction",
  "params": [
    "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==",
    {
      "encoding": "base64"
    }
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "err": null,
    "logs": [
      "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
      "Program log: Instruction: Transfer",
      "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1714 of 200000 compute units",
      "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success"
    ],
    "accounts": null,
    "unitsConsumed": 1714,
    "returnData": null,
    "innerInstructions": null
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://solana-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "simulateTransaction",
  "params": [
    "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==",
    {
      "encoding": "base64"
    }
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'simulateTransaction',
    params: [
      'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==',
      {encoding: 'base64'}
    ]
  })
};

fetch('https://solana-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "simulateTransaction",
    "params": ["AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==", { "encoding": "base64" }]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://solana-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"simulateTransaction\",\n  \"params\": [\n    \"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==\",\n    {\n      \"encoding\": \"base64\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://solana-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"simulateTransaction\",\n  \"params\": [\n    \"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==\",\n    {\n      \"encoding\": \"base64\"\n    }\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://solana-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"simulateTransaction\",\n  \"params\": [\n    \"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==\",\n    {\n      \"encoding\": \"base64\"\n    }\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: simulateTransaction
description: Simulates sending a transaction.
x-compute-units: 20
params:
  - name: Transaction
    required: true
    description: The transaction to simulate, as an encoded string.
    schema:
      type: string
  - name: Configuration
    required: false
    description: Optional configuration object containing additional options.
    schema:
      title: SimulateTransaction Configuration
      type: object
      properties:
        commitment:
          title: Commitment Level
          type: string
          description: Configures the state commitment for querying.
          enum:
            - processed
            - confirmed
            - finalized
          default: finalized
        sigVerify:
          type: boolean
          description: If true, the transaction signatures will be verified.
          default: false
        replaceRecentBlockhash:
          type: boolean
          description: If true, replaces recent blockhash with the most recent one.
          default: false
        minContextSlot:
          title: Minimum Context Slot
          type: integer
          description: The minimum slot that the request can be evaluated at.
        encoding:
          type: string
          description: Encoding used for the transaction data.
          enum:
            - base58
            - base64
          default: base58
        innerInstructions:
          type: boolean
          description: If true, includes inner instructions in the response.
          default: false
        accounts:
          title: SimulateTransaction Accounts Configuration
          type: object
          properties:
            addresses:
              type: array
              description: An array of account Pubkeys to return.
              items:
                title: Pubkey
                type: string
                description: Base-58 encoded public key.
            encoding:
              description: Encoding for returned account data.
              default: base64
              title: Data Encoding
              type: string
              enum:
                - base58
                - base64
                - base64+zstd
                - jsonParsed
examples:
  - name: simulateTransaction example
    params:
      - name: Transaction
        value: AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDZDnD3LUKXWQB8kE0TBLbgGOZmAFW2KdPBOEJie5JAGbhbwJIKOS2F6RAMYzzNMwSCCpNg9MnCHEbVcVPNRByxQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpjJclj04lr3XiJv5dZ3MN1MlkHd0BkPZ/IFOrnFYCxQECAgABDAIAAAAgTgAAAAAAAA==
      - name: Configuration
        value:
          encoding: base64
    result:
      name: Simulated transaction result
      value:
        err: null
        logs:
          - Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]
          - 'Program log: Instruction: Transfer'
          - Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1714 of 200000 compute units
          - Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success
        accounts: null
        unitsConsumed: 1714
        returnData: null
        innerInstructions: null
result:
  name: Simulated transaction result
  description: The result of simulating the transaction.
  schema:
    title: Simulated Transaction Result
    type: object
    properties:
      err:
        type: string
        nullable: true
        description: Error if the transaction failed, null if succeeded.
      logs:
        type: array
        nullable: true
        description: Log messages output during execution.
        items:
          type: string
      accounts:
        type: array
        nullable: true
        description: Array of account information.
        items:
          title: Account Information
          type: object
          properties:
            lamports:
              type: integer
              description: Number of lamports assigned to this account.
            owner:
              title: Pubkey
              type: string
              description: Program owner of this account.
            data:
              title: Account Data
              type: array
              description: Account data in the specified encoding format.
              items:
                type: string
            executable:
              type: boolean
              description: Indicates if the account contains a program.
            rentEpoch:
              type: integer
              description: The epoch at which this account will next owe rent.
            size:
              type: integer
              description: The data size of the account.
      unitsConsumed:
        type: integer
        description: Compute budget units consumed.
      returnData:
        title: Return Data
        type: object
        nullable: true
        properties:
          programId:
            title: Pubkey
            type: string
            description: Program that generated the return data.
          data:
            type: array
            description: Return data as base-64 encoded binary data.
            items:
              type: string
      innerInstructions:
        type: object
        nullable: true
        description: Inner instructions if `innerInstructions` is true.
```
