PrepareTransactionException

class PrepareTransactionException(val message: String, val simulationError: String? = null) : Exception

Exception thrown when preparing a Soroban transaction fails.

This exception is raised during the transaction preparation flow, which involves simulating the transaction, calculating resource requirements, and populating authorization entries. When preparation fails, this exception provides context about what went wrong.

Common Failure Scenarios

Transaction preparation can fail for several reasons:

  • Contract invocation error during simulation

  • Insufficient resources (CPU instructions, memory, etc.)

  • Invalid contract or function parameters

  • Missing authorization entries

  • Network connectivity issues

  • State changes that invalidate the transaction

The simulationError property provides detailed information about simulation failures, which is crucial for debugging contract invocation issues.

Example Usage

try {
val preparedTx = sorobanServer.prepareTransaction(transaction)
} catch (e: PrepareTransactionException) {
println("Transaction preparation failed: ${e.message}")
e.simulationError?.let { error ->
println("Simulation error: $error")
}
}

See also

Constructors

Link copied to clipboard
constructor(message: String, simulationError: String? = null)

Properties

Link copied to clipboard
expect open val cause: Throwable?
Link copied to clipboard
open override val message: String

A descriptive error message explaining why preparation failed

Link copied to clipboard

Optional detailed error from the simulation response, providing contract-specific failure information