> ## 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

> simulateTransaction xem trước nhật ký, mức sử dụng đơn vị tính toán và các thay đổi tài khoản của một giao dịch Solana mà không gửi giao dịch — giúp ước tính phí và phát hiện lỗi.

## Tham số yêu cầu

<ParamField body="transaction" type="string" required>
  Giao dịch đã ký, ở dạng chuỗi được mã hóa (base58 hoặc base64).
</ParamField>

<ParamField body="encoding" type="string">
  Kiểu mã hóa được dùng cho dữ liệu giao dịch.

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

<ParamField body="skipPreflight" type="boolean">
  Bỏ qua các bước kiểm tra sơ bộ giao dịch.
</ParamField>

<ParamField body="preflightCommitment" type="string">
  Mức cam kết được dùng cho bước kiểm tra sơ bộ.

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

<ParamField body="sigVerify" type="boolean">
  Nếu là true, xác minh các chữ ký của giao dịch.
</ParamField>

<ParamField body="replaceRecentBlockhash" type="boolean">
  Nếu là true, thay thế blockhash gần đây của giao dịch bằng blockhash mới nhất.
</ParamField>

<ParamField body="minContextSlot" type="number">
  Slot tối thiểu để thực hiện các bước kiểm tra sơ bộ giao dịch.
</ParamField>

<ParamField body="innerInstructions" type="boolean">
  Nếu là true, đưa các chỉ thị nội bộ vào phản hồi.
</ParamField>

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

<ParamField body="accounts.addresses" type="array">
  Mảng tài khoản cần trả về, ở dạng chuỗi được mã hóa base-58.
</ParamField>

<ParamField body="accounts.encoding" type="string">
  Định dạng mã hóa cho dữ liệu tài khoản được trả về.

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


## OpenAPI

````yaml vi/openapi/rpc-http/simulateTransaction.yaml POST /
openapi: 3.1.0
info:
  title: Solana RPC API
  version: 1.0.0
  description: >-
    API mô phỏng giao dịch Solana nâng cao để kiểm thử và gỡ lỗi các giao dịch
    blockchain trước khi gửi chúng lên mạng Solana.
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://mainnet.helius-rpc.com
    description: Điểm cuối RPC Mainnet
  - url: https://devnet.helius-rpc.com
    description: Điểm cuối RPC Devnet
security: []
paths:
  /:
    post:
      tags:
        - RPC
      summary: simulateTransaction
      description: >
        Mô phỏng các giao dịch Solana mà không thực thi chúng trên blockchain.
        Công cụ 

        gỡ lỗi mạnh mẽ này cho phép nhà phát triển kiểm thử quá trình thực thi
        giao dịch, xác minh hành vi của chương trình,

        ước tính mức tiêu thụ đơn vị tính toán, phát hiện lỗi và xem trước các
        thay đổi trạng thái tài khoản

        trước khi gửi giao dịch lên mạng. Đây là công cụ thiết yếu để phát triển
        ứng dụng Solana,

        kiểm thử hợp đồng thông minh và tối ưu hóa giao dịch.
      operationId: simulateTransaction
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                jsonrpc:
                  type: string
                  enum:
                    - '2.0'
                  description: Phiên bản giao thức JSON-RPC.
                  example: '2.0'
                  default: '2.0'
                id:
                  type: string
                  description: Mã định danh duy nhất cho yêu cầu.
                  example: '1'
                  default: '1'
                method:
                  type: string
                  enum:
                    - simulateTransaction
                  description: Tên của phương thức RPC cần gọi.
                  example: simulateTransaction
                  default: simulateTransaction
                params:
                  type: array
                  description: Các tham số để mô phỏng giao dịch.
                  default:
                    - >-
                      AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=
                    - encoding: base64
                  items:
                    oneOf:
                      - type: string
                        description: >-
                          Giao dịch đã ký, dưới dạng chuỗi được mã hóa (base58
                          hoặc base64).
                        example: >-
                          AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDArczbMia1tLmq7zz4DinMNN0pJ1JtLdqIJPUw3YrGCzYAMHBsgN27lcgB6H2WQvFgyZuJYHa46puOQo9yQ8CVQbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp20C7Wj2aiuk5TReAXo+VTVg8QTHjs0UjNMMKCvpzZ+ABAgEBARU=
                      - type: object
                        description: Đối tượng cấu hình cho quá trình mô phỏng.
                        properties:
                          encoding:
                            type: string
                            description: Kiểu mã hóa dùng cho dữ liệu giao dịch.
                            enum:
                              - base58
                              - base64
                            example: base64
                          skipPreflight:
                            type: boolean
                            description: >-
                              Bỏ qua các bước kiểm tra giao dịch trước khi thực
                              thi.
                            example: false
                          preflightCommitment:
                            type: string
                            description: >-
                              Mức cam kết dùng cho bước kiểm tra trước khi thực
                              thi.
                            enum:
                              - confirmed
                              - finalized
                              - processed
                            example: finalized
                          sigVerify:
                            type: boolean
                            description: Nếu là true, xác minh chữ ký giao dịch.
                            example: false
                          replaceRecentBlockhash:
                            type: boolean
                            description: >-
                              Nếu là true, thay thế blockhash gần đây của giao
                              dịch bằng blockhash mới nhất.
                            example: false
                          minContextSlot:
                            type: integer
                            description: >-
                              Slot tối thiểu để thực hiện các bước kiểm tra giao
                              dịch trước khi thực thi.
                            example: 1000
                          innerInstructions:
                            type: boolean
                            description: Nếu là true, đưa các lệnh nội bộ vào phản hồi.
                            example: false
                          accounts:
                            type: object
                            properties:
                              addresses:
                                type: array
                                description: >-
                                  Mảng các tài khoản cần trả về, dưới dạng chuỗi
                                  được mã hóa base-58.
                                items:
                                  type: string
                                  example: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri
                              encoding:
                                type: string
                                description: >-
                                  Định dạng mã hóa cho dữ liệu tài khoản được
                                  trả về.
                                enum:
                                  - base64
                                  - base58
                                  - base64+zstd
                                  - jsonParsed
                                example: base64
      responses:
        '200':
          description: Đã mô phỏng giao dịch thành công.
          content:
            application/json:
              schema:
                type: object
                properties:
                  jsonrpc:
                    type: string
                    description: Phiên bản giao thức JSON-RPC.
                    enum:
                      - '2.0'
                    example: '2.0'
                  id:
                    type: string
                    description: Mã định danh khớp với yêu cầu.
                    example: '1'
                  result:
                    type: object
                    description: Kết quả của giao dịch được mô phỏng.
                    properties:
                      context:
                        type: object
                        description: Ngữ cảnh của phản hồi mô phỏng.
                        properties:
                          apiVersion:
                            type: string
                            description: Phiên bản API của nút RPC.
                            example: 2.3.3
                          slot:
                            type: integer
                            description: Slot nơi dữ liệu được truy xuất.
                            example: 393226680
                      value:
                        type: object
                        description: Chi tiết về kết quả giao dịch được mô phỏng.
                        properties:
                          accounts:
                            type:
                              - array
                              - 'null'
                            items:
                              type: object
                              description: Chi tiết tài khoản liên quan đến giao dịch.
                              example:
                                lamports: 5000
                                owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
                          err:
                            type:
                              - object
                              - 'null'
                            description: Lỗi nếu giao dịch thất bại; null nếu thành công.
                            example: null
                          innerInstructions:
                            type:
                              - array
                              - 'null'
                            description: Các lệnh nội bộ được thực thi trong giao dịch.
                            example: null
                          loadedAccountsDataSize:
                            type:
                              - integer
                              - 'null'
                            description: >-
                              Tổng kích thước tính bằng byte của tất cả dữ liệu
                              tài khoản được tải trong quá trình mô phỏng.
                            example: 413
                          logs:
                            type:
                              - array
                              - 'null'
                            items:
                              type: string
                            description: >-
                              Nhật ký thực thi chương trình từ quá trình mô
                              phỏng giao dịch.
                            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: >-
                              Thông tin blockhash thay thế khi
                              replaceRecentBlockhash được bật.
                            properties:
                              blockhash:
                                type: string
                                description: Blockhash thay thế.
                                example: 6oFLsE7kmgJx9PjR4R63VRNtpAVJ648gCTr3nq5Hihit
                              lastValidBlockHeight:
                                type: integer
                                description: >-
                                  Chiều cao khối hợp lệ cuối cùng cho blockhash
                                  thay thế.
                                example: 381186895
                          returnData:
                            type:
                              - object
                              - 'null'
                            properties:
                              programId:
                                type: string
                                example: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri
                              data:
                                type: array
                                items:
                                  type: string
                                example:
                                  - Kg==
                                  - base64
                            description: Dữ liệu do giao dịch trả về, nếu có.
                            example: null
                          unitsConsumed:
                            type:
                              - integer
                              - 'null'
                            description: >-
                              Tổng số đơn vị tính toán đã tiêu thụ trong quá
                              trình mô phỏng.
                            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:
                      - >-
                        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
        '400':
          description: >-
            Yêu cầu không hợp lệ - Tham số yêu cầu không hợp lệ hoặc yêu cầu sai
            định dạng.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32602
                  message: Invalid params
                id: '1'
        '401':
          description: Chưa được xác thực - Khóa API không hợp lệ hoặc bị thiếu.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32001
                  message: Unauthorized
                id: '1'
        '429':
          description: Quá nhiều yêu cầu - Đã vượt quá giới hạn tốc độ.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32005
                  message: Too many requests
                id: '1'
        '500':
          description: Lỗi máy chủ nội bộ - Đã xảy ra lỗi trên máy chủ.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32603
                  message: Internal error
                id: '1'
        '503':
          description: Dịch vụ không khả dụng - Dịch vụ tạm thời không khả dụng.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32002
                  message: Service unavailable
                id: '1'
        '504':
          description: Hết thời gian chờ cổng kết nối - Yêu cầu đã hết thời gian chờ.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                jsonrpc: '2.0'
                error:
                  code: -32003
                  message: Gateway timeout
                id: '1'
      security:
        - ApiKeyQuery: []
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        jsonrpc:
          type: string
          description: Phiên bản giao thức JSON-RPC.
          enum:
            - '2.0'
          example: '2.0'
        error:
          type: object
          properties:
            code:
              type: integer
              description: Mã lỗi.
              example: -32602
            message:
              type: string
              description: Thông báo lỗi.
            data:
              type: object
              description: Dữ liệu bổ sung về lỗi.
        id:
          type: string
          description: Mã định danh khớp với yêu cầu.
          example: '1'
  securitySchemes:
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api-key
      description: >-
        Khóa API Helius của bạn. Bạn có thể nhận khóa miễn phí trong [bảng điều
        khiển](https://dashboard.helius.dev/api-keys).

````