Soroban Data Builder
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
Constructors
Types
Functions
Builds the final SorobanTransactionData.
Builds and returns the SorobanTransactionData as a base64-encoded XDR string.
Sets the read-only portion of the storage footprint.
Sets the read-write portion of the storage footprint.
Sets the resource fee portion of the Soroban data.
Sets the resource consumption metrics.