transfer

suspend fun transfer(tokenContract: String, recipient: String, amount: String, decimals: Int? = null, forceMethod: SubmissionMethod? = null): TransactionResult

Transfers tokens from the smart account to a recipient.

Works with any SEP-41 compatible token (XLM via SAC, custom Soroban tokens). The amount is a decimal string converted to the token's base units before submission: decimals is used when supplied, otherwise the token's on-chain decimals() is fetched via fetchTokenDecimals.

Flow:

  1. Validates recipient address and prevents self-transfer

  2. Resolves the token decimals and converts amount to base units

  3. Delegates to contractCall which builds the host function, simulates, signs auth entries via WebAuthn, re-simulates, and submits

IMPORTANT: This method requires WebAuthn interaction to sign auth entries. The user will be prompted for biometric authentication.

Return

TransactionResult indicating success or failure

Parameters

tokenContract

The token contract address (C-address). Use the SAC address for XLM or the token's contract address for custom tokens.

recipient

The recipient address (G-address for accounts, C-address for contracts)

amount

Decimal amount string (e.g., "10", "100.5")

decimals

The token's decimal scale used to convert amount to base units. When null (default), the token's on-chain decimals() is fetched via fetchTokenDecimals. Supply it to skip the extra simulation round-trip (XLM and SAC-wrapped classic assets use 7).

forceMethod

Optional override to force relayer or RPC submission (default: auto-detect)

Throws

if no wallet is connected

if recipient address is invalid

if the recipient is the smart account itself

if the amount is not a valid positive decimal, has more fractional digits than the token's decimals allow, or is outside the i128 range

if simulation, signing, or submission fails

if biometric authentication fails

Example:

val result = txOps.transfer(
tokenContract = "CBCD1234...",
recipient = "GA7QYNF7...",
amount = "10.5"
)

if (result.success) {
println("Transferred. Hash: ${result.hash ?: ""}")
} else {
println("Transfer failed: ${result.error ?: ""}")
}