Sep06Service
SEP-6 Programmatic Deposit and Withdrawal service client.
Provides non-interactive deposit and withdrawal flows with Stellar anchors. SEP-6 enables wallets to offer on/off ramp functionality through a standardized protocol where all required information is provided programmatically in API requests.
This service handles all communication with SEP-6 compliant anchors, including:
Discovering anchor capabilities and supported assets via /info
Initiating programmatic deposit flows via /deposit and /deposit-exchange
Initiating programmatic withdrawal flows via /withdraw and /withdraw-exchange
Querying fee information via /fee (deprecated, use SEP-38)
Querying transaction status and history
Updating transaction information via PATCH
Authentication:
The /info endpoint may not require authentication depending on anchor configuration
All other endpoints require a valid SEP-10 JWT token
Typical workflow:
Create service instance via fromDomain or fromUrl
Call info to discover supported assets and limits
Authenticate via SEP-10 WebAuth to obtain a JWT token
Follow deposit instructions or send withdrawal payment
Poll transaction to monitor completion
Example - Complete deposit flow:
// 1. Initialize from domain
val sep06 = Sep06Service.fromDomain("anchor.example.com")
// 2. Check supported assets
val info = sep06.info()
val usdcEnabled = info.deposit?.get("USDC")?.enabled == true
// 3. Authenticate via SEP-10
val webAuth = WebAuth.fromDomain("anchor.example.com", network)
val jwt = webAuth.jwtToken(accountId, listOf(keyPair)).token
// 4. Initiate deposit
val response = sep06.deposit(Sep06DepositRequest(
assetCode = "USDC",
account = keyPair.getAccountId(),
jwt = jwt,
amount = "100"
))
// 5. Follow deposit instructions
response.instructions?.forEach { (field, instruction) ->
println("$field: ${instruction.value} - ${instruction.description}")
}
// 6. Poll for completion
val tx = sep06.transaction(Sep06TransactionRequest(id = response.id, jwt = jwt))
println("Status: ${tx.transaction.status}")Example - Error handling:
try {
val response = sep06.deposit(request)
} catch (e: Sep06AuthenticationRequiredException) {
// JWT expired, re-authenticate via SEP-10
} catch (e: Sep06CustomerInformationNeededException) {
// Additional KYC fields required, submit via SEP-12
println("Required fields: ${e.fields}")
} catch (e: Sep06CustomerInformationStatusException) {
// KYC status prevents transaction
println("KYC status: ${e.status}")
} catch (e: Sep06InvalidRequestException) {
// Invalid parameters, check request
} catch (e: Sep06ServerErrorException) {
// Anchor server error, retry with backoff
}Example - SEP-38 quote integration:
// Get firm quote first
val quoteService = QuoteService.fromDomain("anchor.example.com")
val quote = quoteService.postQuote(
Sep38QuoteRequest(
context = "sep6",
sellAsset = "iso4217:USD",
buyAsset = "stellar:USDC:GA...",
sellAmount = "100"
),
jwt
)
// Use quote in deposit-exchange
val response = sep06.depositExchange(Sep06DepositExchangeRequest(
destinationAsset = "USDC",
sourceAsset = "iso4217:USD",
amount = quote.sellAmount,
account = keyPair.getAccountId(),
jwt = jwt,
quoteId = quote.id
))See also:
fromDomain for automatic configuration from stellar.toml
Sep06DepositRequest for deposit parameters
Sep06WithdrawRequest for withdrawal parameters
Sep06Transaction for transaction status and details
Functions
Initiates a programmatic deposit.
Initiates a programmatic deposit with asset conversion (SEP-38 exchange).
Gets the fee for a deposit or withdrawal operation.
Gets anchor capabilities and supported assets.
Updates a transaction with additional information requested by the anchor.
Gets a single transaction by its identifier.
Gets transaction history for the authenticated account.
Initiates a programmatic withdrawal.
Initiates a programmatic withdrawal with asset conversion (SEP-38 exchange).