SorobanDataBuilder

SorobanDataBuilder

Supports building xdr.SorobanTransactionData structures with various items set to specific values.

This is recommended for when you are building Operation.extendFootprintTtl / Operation.restoreFootprint operations and need to TransactionBuilder.setSorobanData to avoid (re)building the entire data structure from scratch.

Constructor

new SorobanDataBuilder(sorobanDataopt)

Source:
Parameters:
Name Type Attributes Description
sorobanData string | xdr.SorobanTransactionData <optional>

either a base64-encoded string that represents an xdr.SorobanTransactionData instance or an XDR instance itself (it will be copied); if omitted or "falsy" (e.g. an empty string), it starts with an empty instance

Example
// You want to use an existing data blob but override specific parts.
const newData = new SorobanDataBuilder(existing)
  .setReadOnly(someLedgerKeys)
  .setRefundableFee("1000")
  .build();

// You want an instance from scratch
const newData = new SorobanDataBuilder()
  .setFootprint([someLedgerKey], [])
  .setRefundableFee("1000")
  .build();

Classes

SorobanDataBuilder

Methods

appendFootprint(readOnly, readWrite) → {SorobanDataBuilder}

Appends the given ledger keys to the existing storage access footprint.

Source:
Parameters:
Name Type Description
readOnly Array.<xdr.LedgerKey>

read-only keys to add

readWrite Array.<xdr.LedgerKey>

read-write keys to add

Returns:
Type:
SorobanDataBuilder

this builder instance

build() → {xdr.SorobanTransactionData}

Source:
Returns:
Type:
xdr.SorobanTransactionData

a copy of the final data structure

getFootprint() → {xdr.LedgerFootprint}

Source:
Returns:
Type:
xdr.LedgerFootprint

the storage access pattern

getReadOnly() → {Array.<xdr.LedgerKey>}

Source:
Returns:
Type:
Array.<xdr.LedgerKey>

the read-only storage access pattern

getReadWrite() → {Array.<xdr.LedgerKey>}

Source:
Returns:
Type:
Array.<xdr.LedgerKey>

the read-write storage access pattern

setFootprint(readOnlyopt, readWriteopt) → {SorobanDataBuilder}

Sets the storage access footprint to be a certain set of ledger keys.

You can also set each field explicitly via SorobanDataBuilder.setReadOnly and SorobanDataBuilder.setReadWrite or add to the existing footprint via SorobanDataBuilder.appendFootprint.

Passing null|undefined to either parameter will IGNORE the existing values. If you want to clear them, pass [], instead.

Source:
Parameters:
Name Type Attributes Description
readOnly Array.<xdr.LedgerKey> | null <optional>

the set of ledger keys to set in the read-only portion of the transaction's sorobanData, or null | undefined to keep the existing keys

readWrite Array.<xdr.LedgerKey> | null <optional>

the set of ledger keys to set in the read-write portion of the transaction's sorobanData, or null | undefined to keep the existing keys

Returns:
Type:
SorobanDataBuilder

this builder instance

setReadOnly(readOnly) → {SorobanDataBuilder}

Source:
Parameters:
Name Type Description
readOnly Array.<xdr.LedgerKey>

read-only keys in the access footprint

Returns:
Type:
SorobanDataBuilder

setReadWrite(readWrite) → {SorobanDataBuilder}

Source:
Parameters:
Name Type Description
readWrite Array.<xdr.LedgerKey>

read-write keys in the access footprint

Returns:
Type:
SorobanDataBuilder

setResourceFee(fee) → {SorobanDataBuilder}

Sets the resource fee portion of the Soroban data.

Source:
Parameters:
Name Type Description
fee number | bigint | string

the resource fee to set (int64)

Returns:
Type:
SorobanDataBuilder

setResources(cpuInstrs, readBytes, writeBytes) → {SorobanDataBuilder}

Sets up the resource metrics.

You should almost NEVER need this, as its often generated / provided to you by transaction simulation/preflight from a Soroban RPC server.

Source:
Parameters:
Name Type Description
cpuInstrs number

number of CPU instructions

readBytes number

number of bytes being read

writeBytes number

number of bytes being written

Returns:
Type:
SorobanDataBuilder

(static) fromXDR(data) → {xdr.SorobanTransactionData}

Decodes and builds a xdr.SorobanTransactionData instance.

Source:
Parameters:
Name Type Description
data Uint8Array | Buffer | string

raw input to decode

Returns:
Type:
xdr.SorobanTransactionData