AssembledTransaction

Represents a prepared transaction ready for signing and submission.

AssembledTransaction is obtained from ContractClient methods (ContractClient.invoke, ContractClient.buildInvoke) and should not be constructed directly.

AssembledTransaction manages the complete lifecycle:

  1. Simulate - Get resource estimates from the network

  2. Sign - Add transaction and/or authorization signatures

  3. Submit - Send to network and poll for completion

  4. Parse - Convert result to desired type

Usage Patterns

Read-Only Call (No Signing)

val assembled = client.invoke<Long>(
functionName = "balance",
parameters = listOf(Scv.toAddress(account)),
source = account,
signer = null,
parseResultXdrFn = { Scv.fromInt128(it).toLong() }
)
val balance = assembled.result() // Returns simulated result

Write Call (Standard Flow)

val assembled = client.invoke<Unit>(
functionName = "transfer",
parameters = listOf(from, to, amount),
source = account,
signer = keypair,
parseResultXdrFn = null
)
val result = assembled.signAndSubmit(keypair) // One-step

Advanced Flow (Separate Steps)

val assembled = client.invoke<TransferResult>(...)
assembled.sign(keypair) // Sign transaction
assembled.signAuthEntries(keypair) // Sign auth entries if needed
val result = assembled.submit() // Submit and wait

Multi-Auth Workflow (Atomic Swaps, etc.)

// Build transaction (e.g., atomic swap between Alice and Bob)
val tx = atomicSwapClient.invoke<Unit>(
functionName = "swap",
parameters = listOf(alice, bob, tokenA, tokenB, amounts...),
source = invokerAccount,
signer = invokerKeyPair
)

// Check who needs to sign auth entries
val whoElseNeedsToSign = tx.needsNonInvokerSigningBy()
// Returns: ["GALICE...", "GBOB..."]

// Sign auth entries for Alice
tx.signAuthEntries(aliceKeyPair)

// Sign auth entries for Bob (using delegate for remote signing)
tx.signAuthEntries(
authEntriesSigner = KeyPair.fromAccountId(bobId),
authorizeEntryDelegate = { entry, network ->
// Send to remote server for signing
val entryXdr = entry.toXdrBase64()
val signedXdr = remoteSignService.sign(entryXdr)
SorobanAuthorizationEntryXdr.fromXdrBase64(signedXdr)
}
)

// Submit transaction
val result = tx.signAndSubmit(invokerKeyPair)

Parameters

T

The type of the parsed result

Properties

Link copied to clipboard

The built transaction after simulation (null before simulation).

Link copied to clipboard

The get transaction response (null before completion).

Link copied to clipboard

The TransactionBuilder before simulation.

Link copied to clipboard

The send transaction response (null before submission).

Link copied to clipboard

The signed transaction (separate from builtTransaction).

Link copied to clipboard

The simulation response (null before simulation).

Functions

Link copied to clipboard

Get structured simulation result data.

Link copied to clipboard

Check if this is a read-only call.

Link copied to clipboard
fun needsNonInvokerSigningBy(includeAlreadySigned: Boolean = false): Set<String>

Get the addresses that need to sign authorization entries.

Link copied to clipboard
suspend fun restoreFootprint()

Restores the contract footprint.

Link copied to clipboard
fun result(): T

Get the result from simulation.

Link copied to clipboard
suspend fun sign(transactionSigner: KeyPair? = null, force: Boolean = false): AssembledTransaction<T>

Signs the transaction.

Link copied to clipboard
suspend fun signAndSubmit(transactionSigner: KeyPair? = null, force: Boolean = false): T

Signs the transaction and submits it in one step.

Link copied to clipboard
suspend fun signAuthEntries(authEntriesSigner: KeyPair, validUntilLedgerSequence: Long? = null, authorizeEntryDelegate: suspend (SorobanAuthorizationEntryXdr, Network) -> SorobanAuthorizationEntryXdr? = null): AssembledTransaction<T>

Signs authorization entries in the transaction.

Link copied to clipboard
suspend fun simulate(restore: Boolean = true): AssembledTransaction<T>

Simulates the transaction on the network.

Link copied to clipboard
suspend fun submit(): T

Submits the transaction to the network.

Link copied to clipboard

Get the transaction envelope as base64-encoded XDR.