SorobanDataBuilder

Builder for constructing SorobanTransactionDataXdr structures.

SorobanTransactionData contains the resource footprint and fee information required for Soroban smart contract transactions. This builder provides a fluent API for constructing and modifying these structures.

Use Cases

This builder is particularly useful for:

  • Building com.soneso.stellar.sdk.operations.ExtendFootprintTTLOperation transactions

  • Building com.soneso.stellar.sdk.operations.RestoreFootprintOperation transactions

  • Manually constructing transaction footprints for testing

  • Modifying simulation results before transaction submission

For most Soroban transactions, you should use SorobanServer.prepareTransaction which automatically populates the SorobanTransactionData from simulation results.

Structure

SorobanTransactionData consists of:

  • Resource Fee: Additional fee for resource consumption (beyond base transaction fee)

  • Resources: CPU, memory, and storage metrics

  • CPU Instructions: Number of WASM instructions to execute

  • Disk Read Bytes: Bytes read from ledger storage

  • Write Bytes: Bytes written to ledger storage and memory

  • Footprint: Ledger keys accessed by the transaction

  • Read-Only: Keys read but not modified

  • Read-Write: Keys both read and modified

Basic Usage

// Start with empty data
val builder = SorobanDataBuilder()
.setResourceFee(50000)
.setResources(SorobanDataBuilder.Resources(
cpuInstructions = 1000000,
diskReadBytes = 5000,
writeBytes = 2000
))
.setReadOnly(listOf(ledgerKey1))
.setReadWrite(listOf(ledgerKey2))

val sorobanData = builder.build()

From Simulation Results

// Start with simulation results
val simulation = server.simulateTransaction(tx)
val builder = SorobanDataBuilder(simulation.transactionData!!)
.setResourceFee(simulation.minResourceFee!! + 10000) // Add buffer

val sorobanData = builder.build()

Modifying Existing Data

// Modify existing soroban data
val updated = SorobanDataBuilder(transaction.sorobanData!!)
.setReadWrite(listOf(additionalKey)) // Replace read-write keys
.build()

Immutability

The builder uses defensive copying to ensure immutability:

  • Each setter returns a new builder instance

  • The build method returns a deep copy of the data

  • Original data structures are never mutated

See also

com.soneso.stellar.sdk.operations.ExtendFootprintTTLOperation
com.soneso.stellar.sdk.operations.RestoreFootprintOperation

Constructors

Link copied to clipboard
constructor()

Creates a new builder with empty SorobanTransactionData.

constructor(sorobanData: String)

Creates a new builder from base64-encoded XDR string.

constructor(sorobanData: SorobanTransactionDataXdr)

Creates a new builder from existing SorobanTransactionData.

Types

Link copied to clipboard
data class Resources(val cpuInstructions: Long, val diskReadBytes: Long, val writeBytes: Long)

Resource consumption metrics for Soroban transactions.

Functions

Link copied to clipboard

Builds the final SorobanTransactionData.

Link copied to clipboard

Builds and returns the SorobanTransactionData as a base64-encoded XDR string.

Link copied to clipboard

Sets the read-only portion of the storage footprint.

Link copied to clipboard

Sets the read-write portion of the storage footprint.

Link copied to clipboard

Sets the resource fee portion of the Soroban data.

Link copied to clipboard

Sets the resource consumption metrics.