FriendBot

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
}

Futurenet

To use FriendBot with futurenet instead of testnet:

FriendBot.fundFuturenetAccount(accountId)

Error Handling

try {
FriendBot.fundTestnetAccount(accountId)
println("Account funded successfully")
} catch (e: Exception) {
println("Failed to fund account: ${e.message}")
}

Resource Management

FriendBot maintains a persistent HTTP client for performance. If you need to release resources (typically not needed):

FriendBot.close()

See also

Functions

Link copied to clipboard
fun close()

Closes the HTTP client and releases resources.

Link copied to clipboard
suspend fun fundFuturenetAccount(accountId: String): Boolean

Funds a futurenet account using FriendBot.

Link copied to clipboard
suspend fun fundTestnetAccount(accountId: String): Boolean

Funds a testnet account using FriendBot.