Contract Client
A client to interact with Soroban smart contracts.
Beginner-Friendly Usage (Recommended)
// Load spec from network - enables automatic type conversion and result parsing
val client = ContractClient.forContract(contractId, rpcUrl, network)
// Invoke with native types - automatic argument conversion and execution
val balance = client.invoke(
functionName = "balance",
arguments = mapOf("account" to "GABC..."),
source = sourceAccount,
signer = null,
parseResultXdrFn = { xdr ->
(xdr as SCValXdr.I128).value.lo.value.toLong()
}
)
// Or use manual result parsing with funcResToNative
val resultXdr = client.invoke(
functionName = "balance",
arguments = mapOf("account" to "GABC..."),
source = sourceAccount,
signer = null
)
val balance = client.funcResToNative("balance", resultXdr) as BigIntegerAdvanced Usage (Transaction Control)
// Build transaction for manual control before signing
val tx = client.buildInvoke(
functionName = "transfer",
arguments = mapOf(
"from" to fromAccount,
"to" to toAccount,
"amount" to 1000
),
source = account.accountId,
signer = keypair
)
// Customize transaction
tx.raw?.addMemo(Memo.text("Payment"))
// Sign and submit
tx.signAndSubmit(keypair)Result Parsing
ContractClient provides helper methods for manual result parsing:
funcResToNative(functionName, scVal)- Convert XDR result to native Kotlin typesfuncArgsToXdrSCValues(functionName, args)- Convert native arguments to XDR
Type mapping (Soroban → Kotlin): | Soroban Type | Kotlin Type | |--------------|-------------| | u32, i32 | UInt, Int | | u64, i64 | ULong, Long | | u128, i128 | BigInteger | | bool | Boolean | | symbol, string | String | | address | String | | bytes | ByteArray | | vec
Properties
Functions
Build a transaction for invoking a contract method with Map arguments.
Convert a contract function result from XDR to native Kotlin types.
Convert a contract function result from base64-encoded XDR to native Kotlin types.
Get the contract specification.
Get available method names from contract spec. Returns empty set if spec not loaded.
Invoke a contract function with automatic type conversion (RECOMMENDED).
Convert a single native value to XDR based on type definition.