> For the complete documentation index, see [llms.txt](https://docs.coinvera.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coinvera.io/integration/solana/rpc/simulatetransaction.md).

# simulateTransaction

The `simulateTransaction` RPC method in **CoinVera** simulates the execution of a signed transaction **without broadcasting it to the network**. This is commonly used for **debugging**, **testing**, and **preflight validation** before sending a real transaction. It helps catch errors like insufficient funds, failed program logic, or compute unit limits.

***

#### ✅ Common Use Cases

* **Preflight Testing**\
  Simulate a transaction to verify whether it will succeed before submitting it.
* **Debugging**\
  Inspect `logMessages`, `computeUnitsConsumed`, and `err` fields to debug failing transactions.
* **Estimate Compute Usage**\
  See how many compute units a transaction consumes before hitting the cap.
* **Program Development**\
  Quickly iterate on smart contracts without submitting on-chain transactions.
* **Validate Instruction Formatting**\
  Catch serialization or parameter errors before execution.

***

#### 🧾 Request Parameters

```ts
[
  encodedTransaction: string,        // Required – base64-encoded signed transaction
  config?: {
    sigVerify?: boolean,             // Optional – verify signatures (default: false)
    commitment?: string,             // Optional – "processed", "confirmed", "finalized"
    replaceRecentBlockhash?: boolean,// Optional – use latest blockhash instead of original
    accounts?: {
      encoding?: string,             // Optional – "base64" | "base64+zstd" | "jsonParsed"
      addresses: string[]            // Optional – accounts to fetch data for during simulation
    },
    minContextSlot?: number          // Optional – minimum slot for simulation context
  }
]
```

**Key Fields:**

* **encodedTransaction**:\
  A fully signed transaction encoded in base64.
* **sigVerify**:\
  Whether to verify the transaction's signatures during simulation.
* **replaceRecentBlockhash**:\
  If `true`, substitutes the blockhash with the latest one (useful for testing older transactions).
* **accounts**:\
  Optionally return selected account data after simulation for inspection.
* **commitment**:\
  Level of commitment to simulate against. Typically `"processed"`.

***

#### 📦 Response Structure

```json
{
  "context": {
    "slot": 221446650
  },
  "value": {
    "err": null,
    "logs": [
      "Program 11111111111111111111111111111111 invoke [1]",
      "Program returned success"
    ],
    "accounts": [],
    "unitsConsumed": 1420,
    "returnData": {
      "programId": "SomeProgramAddress",
      "data": ["encodedDataHere", "base64"]
    }
  }
}
```

**Key Fields in `value`:**

* **err**: `null` if successful, or error details (e.g. `InstructionError`).
* **logs**: An array of log messages emitted during simulation.
* **accounts**: Optional account state if requested.
* **unitsConsumed**: Compute units used during simulation.
* **returnData**: Output returned from the transaction, if applicable.

***

#### 🧪 Example

**Simulate a Base64-Encoded Transaction**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "simulateTransaction",
  "params": [
    "Base64EncodedSignedTransactionHere",
    {
      "sigVerify": true,
      "commitment": "processed"
    }
  ]
}
```

***

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const fetch = require('node-fetch');

async function simulateTransaction(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'simulateTransaction',
        "params": [
            "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEEjNmKiZGiOtSZ+g0//wH5kEQo3+UzictY+KlLV8hjXcs44M/Xnr+1SlZsqS6cFMQc46yj9PIsxqkycxJmXT+veJjIvefX4nhY9rY+B5qreeqTHu4mG6Xtxr5udn4MN8PnBt324e51j94YQl285GzN2rYa/E2DuQ0n/r35KNihi/zamQ6EeyeeVDvPVgUO2W3Lgt9hT+CfyqHvIa11egFPCgEDAwIBAAkDZAAAAAAAAAA=",
            {
              "commitment": "confirmed",
              "encoding": "base64",
              "replaceRecentBlockhash": true
            }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

simulateTransaction(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def simulate_transaction(rpc_url):
    try:
        response = requests.post(
            rpc_url,
            headers={
                'Content-Type': 'application/json',
            },
            json={
                'jsonrpc': '2.0',
                'id': 1,
                'method': 'simulateTransaction',
                'params': [
                    'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEEjNmKiZGiOtSZ+g0//wH5kEQo3+UzictY+KlLV8hjXcs44M/Xnr+1SlZsqS6cFMQc46yj9PIsxqkycxJmXT+veJjIvefX4nhY9rY+B5qreeqTHu4mG6Xtxr5udn4MN8PnBt324e51j94YQl285GzN2rYa/E2DuQ0n/r35KNihi/zamQ6EeyeeVDvPVgUO2W3Lgt9hT+CfyqHvIa11egFPCgEDAwIBAAkDZAAAAAAAAAA=',
                    {
                        'commitment': 'confirmed',
                        'encoding': 'base64',
                        'replaceRecentBlockhash': True
                    }
                ]
            }
        )
        
        data = response.json()
        
        # Print the exact full response
        print('Full RPC Response:')
        print(json.dumps(data, indent=2))
        
        return data
        
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
simulate_transaction(RPC_URL)
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "2.3.3",
      "slot": 393226680
    },
    "value": {
      "accounts": null,
      "err": null,
      "innerInstructions": null,
      "loadedAccountsDataSize": 413,
      "logs": [
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]",
        "Program log: Instruction: Transfer",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 1714 of 200000 compute units",
        "Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success"
      ],
      "replacementBlockhash": {
        "blockhash": "6oFLsE7kmgJx9PjR4R63VRNtpAVJ648gCTr3nq5Hihit",
        "lastValidBlockHeight": 381186895
      },
      "returnData": null,
      "unitsConsumed": 1714
    }
  },
  "id": 1
}
```

***

#### 💡 Developer Tips

* **Efficient Debugging**\
  Use `simulateTransaction` with `"sigVerify": true` for a full dry-run, including signature validation.
* **Catch Instruction Errors**\
  Failed deserialization, invalid accounts, or custom program errors will surface in `err` or `logs`.
* **Track Compute Units**\
  Helps optimize transaction size and complexity before submission.
* **Avoid Mainnet Transaction Waste**\
  Prevent failed transactions (and SOL loss from fees) by simulating first—especially in production environments.
* **returnData Support**\
  If your program uses `sol_set_return_data`, use this method to capture and inspect its output.

***

The `simulateTransaction` method is a powerful utility for Solana developers using **CoinVera**, enabling safe, cost-free validation and debugging of transaction logic—before committing anything to the chain.
