Scv

object Scv

Provides a range of methods to help you build and parse SCValXdr more conveniently.

This utility class offers factory methods for creating Soroban Contract Values (SCVal) from Kotlin native types and converting them back. All methods are optimized for production use with proper validation and error handling.

Usage Example

// Create SCVal from primitive types
val int32Val = Scv.toInt32(42)
val stringVal = Scv.toString("hello")
val boolVal = Scv.toBoolean(true)

// Create SCVal from collections
val vecVal = Scv.toVec(listOf(int32Val, stringVal))
val mapVal = Scv.toMap(linkedMapOf(
Scv.toSymbol("key") to Scv.toInt64(100L)
))

// Convert back to Kotlin types
val intValue = Scv.fromInt32(int32Val) // 42
val strValue = Scv.fromString(stringVal) // "hello"

Functions

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_ADDRESS to SCAddressXdr.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_BOOL to Boolean.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_BYTES to ByteArray.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_DURATION to ULong.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_ERROR to SCErrorXdr.

Link copied to clipboard
fun fromInt128(scVal: SCValXdr): BigInteger

Convert from SCValXdr with the type of SCValTypeXdr.SCV_I128 to BigInteger.

Link copied to clipboard
fun fromInt256(scVal: SCValXdr): BigInteger

Convert from SCValXdr with the type of SCValTypeXdr.SCV_I256 to BigInteger.

Link copied to clipboard
fun fromInt32(scVal: SCValXdr): Int

Convert from SCValXdr with the type of SCValTypeXdr.SCV_I32 to Int.

Link copied to clipboard
fun fromInt64(scVal: SCValXdr): Long

Convert from SCValXdr with the type of SCValTypeXdr.SCV_I64 to Long.

Link copied to clipboard

Parse from SCValXdr with the type of SCValTypeXdr.SCV_LEDGER_KEY_CONTRACT_INSTANCE. This function validates the type and returns Unit if successful.

Link copied to clipboard
Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_MAP to LinkedHashMap.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_STRING to String.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_SYMBOL to String.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_TIMEPOINT to ULong.

Link copied to clipboard
fun fromUint128(scVal: SCValXdr): BigInteger

Convert from SCValXdr with the type of SCValTypeXdr.SCV_U128 to BigInteger.

Link copied to clipboard
fun fromUint256(scVal: SCValXdr): BigInteger

Convert from SCValXdr with the type of SCValTypeXdr.SCV_U256 to BigInteger.

Link copied to clipboard
fun fromUint32(scVal: SCValXdr): UInt

Convert from SCValXdr with the type of SCValTypeXdr.SCV_U32 to UInt.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_U64 to ULong.

Link copied to clipboard

Convert from SCValXdr with the type of SCValTypeXdr.SCV_VEC to List.

Link copied to clipboard
fun fromVoid(scVal: SCValXdr)

Parse from SCValXdr with the type of SCValTypeXdr.SCV_VOID. This function validates the type and returns Unit if successful.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_ADDRESS.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_BOOL.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_BYTES.

Link copied to clipboard
Link copied to clipboard
fun toDuration(duration: ULong): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_DURATION.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_ERROR.

Link copied to clipboard
fun toInt128(value: BigInteger): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_I128.

Link copied to clipboard
fun toInt256(value: BigInteger): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_I256.

Link copied to clipboard
fun toInt32(value: Int): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_I32.

Link copied to clipboard
fun toInt64(value: Long): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_I64.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun toString(string: String): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_STRING.

Link copied to clipboard
fun toSymbol(symbol: String): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_SYMBOL.

Link copied to clipboard
fun toTimePoint(timePoint: ULong): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_TIMEPOINT.

Link copied to clipboard
fun toUint128(value: BigInteger): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_U128.

Link copied to clipboard
fun toUint256(value: BigInteger): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_U256.

Link copied to clipboard
fun toUint32(value: UInt): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_U32.

Link copied to clipboard
fun toUint64(value: ULong): SCValXdr

Build a SCValXdr with the type of SCValTypeXdr.SCV_U64.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_VEC.

Link copied to clipboard

Build a SCValXdr with the type of SCValTypeXdr.SCV_VOID.