fund Wallet
Funds the smart account wallet using Friendbot (testnet only).
Creates a temporary keypair, funds it via Friendbot, then transfers the balance (minus reserve) to the smart account contract. Supports relayer fee sponsoring by converting source_account auth entries to Address credentials.
Flow:
Generate random temporary keypair
Fund temp account via Friendbot HTTP GET
Poll the Soroban RPC until the funded temp account is visible to simulation
Query temp account balance via native token contract simulation
Calculate transfer amount (balance - reserve)
Build transfer from temp to smart account
Simulate to get auth entries
Convert source_account auth entries to Address credentials (for relayer)
Sign auth entries with temp keypair
Re-simulate with signed auth entries
Decide fee sponsoring mode and submit
Return funded amount in XLM
Fee Sponsoring
When a relayer URL is configured via config.relayerUrl:
Mode 1: Used when no source_account auth exists after conversion. Sends host function + signed auth entries without signing the transaction envelope.
Mode 2: Used when source_account auth still exists (not converted). Sends fully signed transaction XDR with temp keypair signature.
When no relayer is configured, submits directly via RPC with temp keypair signature.
Latency
After Friendbot funding, the call waits for the temporary account to become visible to the Soroban RPC before simulating the balance read. That wait is a single poll bounded by OZConstants.RPC_VISIBILITY_TIMEOUT_SECONDS (45s); when testnet propagation is slow the worst-case added latency approaches that budget before the call either proceeds or raises TransactionException.Timeout. Invoked from createWallet(autoFund = true) this poll runs after the deploy contract-visibility poll, so the two budgets add up to roughly 90s in the worst case. The common case returns within a few seconds.
Source Account Auth Conversion
The funding flow converts source_account (Void) credentials to Address credentials with a generated nonce. This allows the relayer to substitute its own channel accounts for fee sponsoring, enabling zero-balance smart accounts to receive their first funds.
IMPORTANT: Only works on testnet. Do not use on mainnet.
Return
The amount funded in XLM
Parameters
The native token (XLM) contract address (C-address)
Optional override to force relayer or RPC submission (default: auto-detect)
See also
for source_account to Address credential conversion
Throws
if no wallet is connected
if the contract address is invalid
if any step of the funding flow fails
Example:
// Fund wallet (uses relayer if configured)
val fundedAmount = txOps.fundWallet(
nativeTokenContract = "CBCD1234..."
)
println("Funded $fundedAmount XLM")
// Fund wallet with direct RPC submission (no relayer)
val kit = OZSmartAccountKit.create(
config = config.copy(relayerUrl = null)
)
val amount = kit.transactionOperations.fundWallet(nativeTokenContract)
println("Funded directly: $amount XLM")