prepareTransaction

suspend fun prepareTransaction(transaction: Transaction): 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

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