transfer

suspend fun transfer(tokenContract: String, recipient: String, amount: String, 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 stroops (7 decimal places) internally.

Flow:

  1. Validates recipient address and prevents self-transfer

  2. Converts amount to stroops using BigInteger arithmetic

  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"). Converted to stroops automatically.

forceMethod

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

Throws

if no wallet is connected

if recipient address is invalid or same as smart account

if amount is not a valid positive decimal

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 ?: ""}")
}