> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# simulateTransaction

> 模拟一个Solana交易，以预览日志、计算单元使用和账户变化，而无需将其提交到网络——用于估算费用、检测故障，并在签名前调试指令。

## 请求参数

<ParamField body="transaction" type="string" required>
  已签名的交易，作为编码字符串（base58 或 base64）。
</ParamField>

<ParamField body="encoding" type="string">
  用于交易数据的编码。

  * `base58`
  * `base64`
</ParamField>

<ParamField body="skipPreflight" type="boolean">
  跳过预检交易检查。
</ParamField>

<ParamField body="preflightCommitment" type="string">
  用于预检的承诺级别。

  * `confirmed`
  * `finalized`
  * `processed`
</ParamField>

<ParamField body="sigVerify" type="boolean">
  如果为 true，验证交易签名。
</ParamField>

<ParamField body="replaceRecentBlockhash" type="boolean">
  如果为 true，则用最新的 blockhash 替换交易的最近 blockhash。
</ParamField>

<ParamField body="minContextSlot" type="number">
  执行预检交易检查的最低 slot。
</ParamField>

<ParamField body="innerInstructions" type="boolean">
  如果为 true，则在响应中包含内部指令。
</ParamField>

<ParamField body="accounts" type="object" />

<ParamField body="accounts.addresses" type="array">
  要返回的账户数组，作为 base-58 编码字符串。
</ParamField>

<ParamField body="accounts.encoding" type="string">
  返回账户数据的编码格式。

  * `base64`
  * `base58`
  * `base64+zstd`
  * `jsonParsed`
</ParamField>


## OpenAPI

````yaml zh/openapi/rpc-http/simulateTransaction.yaml POST /
openapi: 3.1.0
info:
  title: Solana RPC API
  version: 1.0.0
  description: 用于在将交易提交到Solana网络之前测试和调试区块链交易的高级Solana交易模拟API。
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://mainnet.helius-rpc.com
    description: 主网RPC端点
  - url: https://devnet.helius-rpc.com
    description: 开发网RPC端点
security: []
paths:
  /:
    post:
      tags:
        - RPC
      summary: simulateTransaction
      description: >-
        模拟 Solana
        交易而不在区块链上执行它们。这个强大的调试工具允许开发人员测试交易执行，验证程序行为，估算计算单元消耗，检测错误，并在将交易提交到网络之前预览账户状态变化。对于
        Solana 应用程序开发、智能合约测试和交易优化至关重要。
      operationId: simulateTransaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                jsonrpc:
                  type: string
                  enum:
                    - '2.0'
                  description: JSON-RPC 协议版本。
                  example: '2.0'
                  default: '2.0'
                id:
                  type: string
                  description: 请求的唯一标识符。
                  example: '1'
                  default: '1'
                method:
                  type: string
                  enum:
                    - simulateTransaction
                  description: 要调用的 RPC 方法名称。
                  example: simulateTransaction
                  default: simulateTransaction
                params:
                  type: array
                  description: 用于模拟交易的参数。
                  default:
                    - >-
                      AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=
                    - encoding: base64
                  items:
                    oneOf:
                      - type: string
                        description: 签名的交易，作为编码字符串（base58 或 base64）。
                        example: >-
                          AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=
                      - type: object
                        description: 模拟的配置对象。
                        properties:
                          encoding:
                            type: string
                            description: 用于交易数据的编码。
                            enum:
                              - base58
                              - base64
                            example: base64
                          skipPreflight:
                            type: boolean
                            description: 跳过预检交易检查。
                            example: false
                          preflightCommitment:
                            type: string
                            description: 用于预检的承诺级别。
                            enum:
                              - confirmed
                              - finalized
                              - processed
                            example: finalized
                          sigVerify:
                            type: boolean
                            description: 如果为 true，验证交易签名。
                            example: false
                          replaceRecentBlockhash:
                            type: boolean
                            description: 如果为 true，用最新的替换交易的最近区块哈希。
                            example: false
                          minContextSlot:
                            type: integer
                            description: 执行预检交易检查的最小槽位。
                            example: 1000
                          innerInstructions:
                            type: boolean
                            description: 如果为 true，在响应中包含内部指令。
                            example: false
                          accounts:
                            type: object
                            properties:
                              addresses:
                                type: array
                                description: 要返回的账户数组，以 base-58 编码的字符串形式。
                                items:
                                  type: string
                                  example: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri
                              encoding:
                                type: string
                                description: 返回账户数据的编码格式。
                                enum:
                                  - base64
                                  - base58
                                  - base64+zstd
                                  - jsonParsed
                                example: base64
      responses:
        '200':
          description: 成功模拟了交易。
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                    description: JSON-RPC协议版本。
                    enum:
                      - '2.0'
                    example: '2.0'
                  id:
                    type: string
                    description: 与请求匹配的标识符。
                    example: '1'
                  result:
                    type: object
                    description: 模拟交易的结果。
                    properties:
                      context:
                        type: object
                        description: 模拟响应的上下文。
                        properties:
                          apiVersion:
                            type: string
                            description: RPC节点的API版本。
                            example: 2.3.3
                          slot:
                            type: integer
                            description: 获取数据的槽位。
                            example: 393226680
                      value:
                        type: object
                        description: 模拟交易结果的详细信息。
                        properties:
                          accounts:
                            type:
                              - array
                              - 'null'
                            items:
                              type: object
                              description: 与交易相关的账户详细信息。
                              example:
                                lamports: 5000
                                owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
                          err:
                            type:
                              - object
                              - 'null'
                            description: 如果交易失败则为错误信息，成功则为null。
                            example: null
                          innerInstructions:
                            type:
                              - array
                              - 'null'
                            description: 交易过程中执行的内部指令。
                            example: null
                          loadedAccountsDataSize:
                            type:
                              - integer
                              - 'null'
                            description: 模拟过程中加载的所有账户数据的总字节大小。
                            example: 413
                          logs:
                            type:
                              - array
                              - 'null'
                            items:
                              type: string
                            description: 交易模拟中的程序执行日志。
                            example:
                              - >-
                                Program
                                TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
                                invoke [1]
                              - 'Program log: Instruction: Transfer'
                              - >-
                                Program
                                TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
                                consumed 1714 of 200000 compute units
                              - >-
                                Program
                                TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
                                success
                          replacementBlockhash:
                            type:
                              - object
                              - 'null'
                            description: >-
                              Replacement blockhash information when
                              replaceRecentBlockhash is enabled.
                            properties:
                              blockhash:
                                type: string
                                description: The replacement blockhash.
                                example: 6oFLsE7kmgJx9PjR4R63VRNtpAVJ648gCTr3nq5Hihit
                              lastValidBlockHeight:
                                type: integer
                                description: >-
                                  The last valid block height for the
                                  replacement blockhash.
                                example: 381186895
                          returnData:
                            type:
                              - object
                              - 'null'
                            properties:
                              programId:
                                type: string
                                example: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri
                              data:
                                type: array
                                items:
                                  type: string
                                example:
                                  - Kg==
                                  - base64
                            description: Data returned by the transaction if any.
                            example: null
                          unitsConsumed:
                            type:
                              - integer
                              - 'null'
                            description: >-
                              Total compute units consumed during the
                              simulation.
                            example: 1714
              example:
                jsonrpc: '2.0'
                id: 1
                result:
                  context:
                    apiVersion: 2.3.3
                    slot: 393226680
                  value:
                    accounts: null
                    err: null
                    innerInstructions: null
                    loadedAccountsDataSize: 413
                    logs:
                      - 程序 TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb 调用 [1]
                      - 程序日志：指令：转移
                      - >-
                        程序 TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb 消耗了 1714
                        个计算单元中的 200000 个
                      - 程序 TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb 成功
                    replacementBlockhash:
                      blockhash: 6oFLsE7kmgJx9PjR4R63VRNtpAVJ648gCTr3nq5Hihit
                      lastValidBlockHeight: 381186895
                    returnData: null
                    unitsConsumed: 1714
        '400':
          description: 错误请求 - 请求参数无效或请求格式错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32602
                  message: 参数无效
                id: '1'
        '401':
          description: 未授权 - API 密钥无效或缺失。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32001
                  message: 未授权
                id: '1'
        '429':
          description: 请求过多 - 超过速率限制。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32005
                  message: 请求过多
                id: '1'
        '500':
          description: 内部服务器错误 - 服务器发生错误。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32603
                  message: 内部错误
                id: '1'
        '503':
          description: 服务不可用 - 服务暂时不可用。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32002
                  message: 服务不可用
                id: '1'
        '504':
          description: 网关超时 - 请求超时。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32003
                  message: 网关超时
                id: '1'
      security:
        - ApiKeyQuery: []
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        jsonrpc:
          type: string
          description: JSON-RPC协议版本。
          enum:
            - '2.0'
          example: '2.0'
        error:
          type: object
          properties:
            code:
              type: integer
              description: 错误代码。
              example: -32602
            message:
              type: string
              description: 错误信息。
            data:
              type: object
              description: 关于错误的附加数据。
        id:
          type: string
          description: 与请求匹配的标识符。
          example: '1'
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api-key
      description: 您的Helius API密钥。您可以在[仪表板](https://dashboard.helius.dev/api-keys)中免费获取一个。

````