# simulateTransaction

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

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

Simulates a transaction invocation to estimate resource fees, required authorizations, and return values without submitting to the network.

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

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| transaction | string | Yes | Base64-encoded TransactionEnvelope XDR with a single invokeHostFunction operation. |
| resourceConfig | object | No | Resource configuration with instructionLeeway for extra instruction budget. |
| xdrFormat | string | No | Output format for XDR fields, either "base64" (default) or "json". |
| authMode | string | No | Authorization mode. "enforce" (default), "record", or "record_allow_nonroot". |

## Result

**result** (object): Simulation result with fee estimate, events, and transaction data.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "simulateTransaction",
  "params": [
    "AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA="
  ],
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://stellar-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "simulateTransaction",
  "params": [
    "AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=",
    {
      "instructionLeeway": 1
    },
    "string",
    "string"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'simulateTransaction',
    params: [
      'AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=',
      {instructionLeeway: 1},
      'string',
      'string'
    ]
  })
};

fetch('https://stellar-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://stellar-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "simulateTransaction",
    "params": ["AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=", { "instructionLeeway": 1 }, "string", "string"]
}
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://stellar-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"simulateTransaction\",\n  \"params\": [\n    \"AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=\",\n    {\n      \"instructionLeeway\": 1\n    },\n    \"string\",\n    \"string\"\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://stellar-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    \"AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=\",\n    {\n      \"instructionLeeway\": 1\n    },\n    \"string\",\n    \"string\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://stellar-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    \"AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=\",\n    {\n      \"instructionLeeway\": 1\n    },\n    \"string\",\n    \"string\"\n  ]\n}", false);
var response = await client.PostAsync(request);

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

```


## OpenRPC Method Specification

```yaml
name: simulateTransaction
summary: Simulate transaction
description: Simulates a transaction invocation to estimate resource fees, required authorizations, and return values without submitting to the network.
paramStructure: by-name
x-compute-units: 20
params:
  - name: transaction
    required: true
    description: Base64-encoded TransactionEnvelope XDR with a single invokeHostFunction operation.
    schema:
      type: string
  - name: resourceConfig
    required: false
    description: Resource configuration with instructionLeeway for extra instruction budget.
    schema:
      type: object
      properties:
        instructionLeeway:
          type: integer
  - name: xdrFormat
    required: false
    description: Output format for XDR fields, either "base64" (default) or "json".
    schema:
      type: string
  - name: authMode
    required: false
    description: Authorization mode. "enforce" (default), "record", or "record_allow_nonroot".
    schema:
      type: string
result:
  name: result
  description: Simulation result with fee estimate, events, and transaction data.
  schema:
    type: object
    properties:
      latestLedger:
        type: integer
      minResourceFee:
        type: string
      transactionData:
        type: string
examples:
  - name: simulateTransaction example
    description: |
      Simulates a read-only call to `name()` on the native XLM Stellar Asset Contract
      (`CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA`). The envelope is unsigned —
      simulation never checks signatures, sequence numbers, or time bounds, so this example
      is stable indefinitely and returns the SCV-encoded string `"native"` in `results[0].xdr`
      along with a populated `minResourceFee`, `transactionData`, and `events`.
    params:
      - name: transaction
        value: AAAAAgAAAAA7mRE4Dv6Yi6CokA6xz+RPNm99vpRr7QdyQPf2JN8VxQAAAGQAAAAAAAAAZQAAAAEAAAAAAAAAAAAAAABp/P05AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABJbT82FmuwvpjSEOMSJs8PBDJi20hvk/TyzDLaJU++XcAAAAEbmFtZQAAAAAAAAAAAAAAAAAAAAA=
```
