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:

  1. Create service instance via fromDomain or fromUrl

  2. Call info to discover supported assets and limits

  3. Authenticate via SEP-10 WebAuth to obtain a JWT token

  4. Call deposit or withdraw to initiate a programmatic flow

  5. Follow deposit instructions or send withdrawal payment

  6. 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:

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Initiates a programmatic deposit.

Link copied to clipboard

Initiates a programmatic deposit with asset conversion (SEP-38 exchange).

Link copied to clipboard
suspend fun fee(request: Sep06FeeRequest): Sep06FeeResponse

Gets the fee for a deposit or withdrawal operation.

Link copied to clipboard
suspend fun info(language: String? = null, jwt: String? = null): Sep06InfoResponse

Gets anchor capabilities and supported assets.

Link copied to clipboard
suspend fun patchTransaction(request: Sep06PatchTransactionRequest): HttpResponse

Updates a transaction with additional information requested by the anchor.

Link copied to clipboard

Gets a single transaction by its identifier.

Link copied to clipboard

Gets transaction history for the authenticated account.

Link copied to clipboard

Initiates a programmatic withdrawal.

Link copied to clipboard

Initiates a programmatic withdrawal with asset conversion (SEP-38 exchange).