TransferServerService

public final class TransferServerService : @unchecked Sendable

Implements SEP-0006 - Deposit and Withdrawal API.

This class provides programmatic deposit and withdrawal functionality for Stellar assets without requiring user interaction in a web interface. Unlike SEP-0024, SEP-6 is designed for automated workflows and server-to-server integrations.

Key Differences from SEP-0024

  • SEP-6: Programmatic API for automation (no user web interface)
  • SEP-24: Interactive flows with hosted web UI for user input

Typical Workflow

// Initialize service
let result = await TransferServerService.forDomain(domain: "testanchor.stellar.org")
guard case .success(let service) = result else { return }

// Get info about supported assets
let info = await service.info()

// Deposit flow
let depositRequest = DepositRequest(
    assetCode: "USDC",
    account: accountId,
    jwt: jwtToken
)
let depositResult = await service.deposit(request: depositRequest)

// Withdraw flow
let withdrawRequest = WithdrawRequest(
    type: "bank_account",
    assetCode: "USDC",
    account: accountId,
    dest: "123456789", // Bank account number
    jwt: jwtToken
)
let withdrawResult = await service.withdraw(request: withdrawRequest)

Exchange Operations

SEP-6 supports asset conversion during deposit/withdrawal using SEP-38 quotes:

// Deposit with exchange (e.g., receive BRL, send USDC to Stellar)
let exchangeRequest = DepositExchangeRequest(
    destinationAsset: "stellar:USDC:G...",
    sourceAsset: "iso4217:BRL",
    amount: "1000",
    account: accountId,
    jwt: jwtToken
)
let result = await service.depositExchange(request: exchangeRequest)

See also:

  • SEP-0006 Specification
  • [InteractiveService] for SEP-24 (interactive flows)
  • [WebAuthenticator] for SEP-10 authentication
  • The base URL of the SEP-6 transfer server endpoint for programmatic deposit and withdrawal.

    Declaration

    Swift

    public let transferServiceAddress: String
  • Initializes a SEP-6 transfer server service with the specified endpoint address.

    Declaration

    Swift

    public init(serviceAddress: String)

    Parameters

    serviceAddress

    The base URL of the transfer server, trailing slashes are automatically removed

  • forDomain(domain:) Asynchronous

    Creates a TransferServerService instance based on information from the stellar.toml file for a given domain.

    Fetches the stellar.toml file from the domain and extracts the TRANSFER_SERVER URL.

    Declaration

    Swift

    public static func forDomain(domain: String) async -> TransferServerServiceForDomainEnum

    Parameters

    domain

    The domain to fetch stellar.toml from (e.g., “https://example.com”)

    Return Value

    TransferServerServiceForDomainEnum with the service instance or an error

  • deposit(request:) Asynchronous

    Initiates a SEP-6 deposit flow to convert external assets into Stellar tokens via an anchor.

    Declaration

    Swift

    public func deposit(request: DepositRequest) async -> DepositResponseEnum

    Parameters

    request

    Deposit request containing asset code, destination account, and optional parameters

    Return Value

    DepositResponseEnum with instructions for transferring external assets to the anchor, or an error

  • Initiates a SEP-6 deposit with asset conversion using SEP-38 quotes for non-equivalent token exchange.

    Declaration

    Swift

    public func depositExchange(request: DepositExchangeRequest) async -> DepositResponseEnum

    Parameters

    request

    Exchange deposit request specifying source asset, destination asset, amount, and account

    Return Value

    DepositResponseEnum with conversion details and instructions, or an error

  • withdraw(request:) Asynchronous

    Initiates a SEP-6 withdrawal flow to convert Stellar tokens into off-chain assets via an anchor.

    Declaration

    Swift

    public func withdraw(request: WithdrawRequest) async -> WithdrawResponseEnum

    Parameters

    request

    Withdrawal request with asset code, withdrawal type, destination, and optional account details

    Return Value

    WithdrawResponseEnum with instructions for receiving off-chain assets, or an error

  • Initiates a SEP-6 withdrawal with asset conversion using SEP-38 quotes for non-equivalent token exchange.

    Declaration

    Swift

    public func withdrawExchange(request: WithdrawExchangeRequest) async -> WithdrawResponseEnum

    Parameters

    request

    Exchange withdrawal request specifying source asset, destination asset, amount, and withdrawal details

    Return Value

    WithdrawResponseEnum with conversion details and instructions, or an error

  • Retrieves SEP-6 anchor capabilities including supported assets, operations, and authentication requirements.

    Declaration

    Swift

    public func info(language: String? = nil, jwtToken: String? = nil) async -> AnchorInfoResponseEnum

    Parameters

    language

    RFC 4646 language code for localized responses, defaults to English

    jwtToken

    Optional SEP-10 authentication token if required by the anchor

    Return Value

    AnchorInfoResponseEnum with anchor capabilities and configuration, or an error

  • fee(request:) Asynchronous

    Retrieves fee information for SEP-6 deposit or withdrawal operations (deprecated, use SEP-38 /price endpoint).

    Declaration

    Swift

    public func fee(request: FeeRequest) async -> AnchorFeeResponseEnum

    Parameters

    request

    Fee request containing operation type, asset code, and transaction amount

    Return Value

    AnchorFeeResponseEnum with calculated fee details for the specified operation, or an error

  • Retrieves transaction history for SEP-6 deposits and withdrawals filtered by account and asset.

    Declaration

    Swift

    public func getTransactions(request: AnchorTransactionsRequest) async -> AnchorTransactionsResponseEnum

    Parameters

    request

    Transaction query request with account, asset code, optional filters, and SEP-10 JWT token

    Return Value

    AnchorTransactionsResponseEnum with list of deposit and withdrawal transactions, or an error

  • Retrieves detailed status and information for a specific SEP-6 transaction by ID or Stellar transaction hash.

    Declaration

    Swift

    public func getTransaction(request: AnchorTransactionRequest) async -> AnchorTransactionResponseEnum

    Parameters

    request

    Transaction lookup request with transaction ID, Stellar hash, or external ID, and SEP-10 JWT token

    Return Value

    AnchorTransactionResponseEnum with detailed transaction status and processing information, or an error

  • Updates a SEP-6 transaction with additional customer information when requested by the anchor via pending_transaction_info_update status.

    Declaration

    Swift

    public func patchTransaction(id: String, jwt: String?, contentType: String, body: Data) async -> AnchorTransactionResponseEnum

    Parameters

    id

    The anchor’s transaction ID requiring additional information

    jwt

    SEP-10 authentication token for the transaction owner

    contentType

    HTTP content type for the request body (e.g., application/json or multipart/form-data)

    body

    Encoded request data containing the required customer information updates

    Return Value

    AnchorTransactionResponseEnum with updated transaction details, or an error