prepareTransaction

suspend fun prepareTransaction(transaction: Transaction, useUpgradedAuth: Boolean = true): Transaction

Prepares a transaction by simulating it and applying resource estimates.

This is a convenience method that:

  1. Calls simulateTransaction to get resource estimates

  2. Calls prepareTransaction with the simulation results

The returned transaction is ready for signing and submission. The fee will be updated to include estimated resource fees.

Example

val prepared = server.prepareTransaction(transaction)
prepared.sign(keypair)
server.sendTransaction(prepared)

Return

A copy of the transaction with footprint and fees populated

Parameters

transaction

The transaction to prepare

useUpgradedAuth

When true (the default), requests Protocol-27 ADDRESS_V2 auth entries during simulation. The flag is sent on every request; an explicit false requests legacy ADDRESS entries. RPC servers without Protocol 27 support ignore the flag and return legacy entries. Set false on networks below Protocol 27, where ADDRESS_V2 entries invalidate the transaction.

Throws

If simulation fails

If the RPC request fails


suspend fun prepareTransaction(transaction: Transaction, simulateResponse: SimulateTransactionResponse): Transaction

Prepares a transaction using existing simulation results.

Applies simulation results to the transaction without re-simulating. Use this when you've already called simulateTransaction and want to inspect results before preparing.

The method:

  • Validates simulation succeeded (no error)

  • Applies resource footprint from simulation

  • Updates authorization entries (if applicable)

  • Calculates total fee (base fee + resource fee)

Return

A copy of the transaction with simulation results applied

Parameters

transaction

The transaction to prepare

simulateResponse

The simulation results to apply

Throws

If simulation contains an error