Friend Bot
object FriendBot
Helper object for funding test accounts using Stellar's FriendBot service.
FriendBot is a testnet and futurenet service that creates and funds test accounts with 10,000 XLM. This is useful for development and testing without requiring real funds.
Important: FriendBot is only available on testnet and futurenet. It will not work on the public Stellar network (mainnet).
Usage
import com.soneso.stellar.sdk.FriendBot
import com.soneso.stellar.sdk.KeyPair
suspend fun example() {
// Generate a new keypair
val keypair = KeyPair.random()
val accountId = keypair.getAccountId()
// Fund the account on testnet
FriendBot.fundTestnetAccount(accountId)
// Account is now ready to use with 10,000 XLM balance
}Content copied to clipboard
Futurenet
To use FriendBot with futurenet instead of testnet:
FriendBot.fundFuturenetAccount(accountId)Content copied to clipboard
Error Handling
try {
FriendBot.fundTestnetAccount(accountId)
println("Account funded successfully")
} catch (e: Exception) {
println("Failed to fund account: ${e.message}")
}Content copied to clipboard
Resource Management
FriendBot maintains a persistent HTTP client for performance. If you need to release resources (typically not needed):
FriendBot.close()Content copied to clipboard