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
Wait briefly for funding to confirm
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.
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")