PaymentPathsService

public class PaymentPathsService : @unchecked Sendable

Service for finding payment paths on the Stellar network.

Payment paths allow sending one asset and having the recipient receive a different asset through automatic conversions on the Stellar DEX. This service finds available paths and their costs for path payment operations.

Example usage:

let sdk = StellarSDK()

// Find paths to send USD and receive XLM
let response = await sdk.paymentPaths.findPaymentPaths(
    destinationAccount: "GDEST...",
    destinationAssetType: AssetTypeAsString.NATIVE,
    destinationAmount: "100",
    sourceAccount: "GSOURCE..."
)
switch response {
case .success(let paths):
    for path in paths.paths {
        print("Source amount: \(path.sourceAmount)")
        print("Path length: \(path.path.count)")
    }
case .failure(let error):
    print("Error: \(error)")
}

See also:

  • Finds payment paths from source to destination account for a specified amount.

    Declaration

    Swift

    open func findPaymentPaths(destinationAccount: String, destinationAssetType: String, destinationAssetCode: String? = nil, destinationAssetIssuer: String? = nil, destinationAmount: String, sourceAccount: String) async -> PaymentPathsResponseEnum

    Parameters

    destinationAccount

    The destination account ID

    destinationAssetType

    Type of destination asset: “native”, “credit_alphanum4”, or “credit_alphanum12”

    destinationAssetCode

    Asset code if not “native”

    destinationAssetIssuer

    Asset issuer if not “native”

    destinationAmount

    The amount to be received by the destination

    sourceAccount

    The source account ID

    Return Value

    PaymentPathsResponseEnum with available paths or error

  • Finds strict receive payment paths from source to destination.

    The Stellar Network allows payments to be made across assets through path payments. A path payment specifies a series of assets to route a payment through, from source asset (the asset debited from the payer) to destination asset (the asset credited to the payee).

    A strict receive path search is specified using:

    • The source account id or source assets.
    • The asset and amount that the destination account should receive.

    As part of the search, Horizon will load a list of assets available to the source account id and will find any payment paths from those source assets to the desired destination asset. The search’s amount parameter will be used to determine if a given path can satisfy a payment of the desired amount.

    The endpoint will not allow requests which provide both a source_account and a source_assets parameter. All requests must provide one or the other.

    Note: XLM should be represented as “native”. Issued assets should be represented as “Code:IssuerAccountID”.

    See: Stellar developer docs

    Declaration

    Swift

    open func strictReceive(sourceAccount: String? = nil, sourceAssets: String? = nil, destinationAccount: String? = nil, destinationAssetType: String? = nil, destinationAssetCode: String? = nil, destinationAssetIssuer: String? = nil, destinationAmount: String? = nil) async -> PaymentPathsResponseEnum

    Parameters

    sourceAccount

    Optional. The sender’s account id. Any returned path must use an asset that the sender has a trustline to.

    sourceAssets

    Optional. A comma separated list of assets. Any returned path must use an asset included in this list. e.g. “USD:GAEDTJ4PPEFVW5XV2S7LUXBEHNQMX5Q2GM562RJGOQG7GVCE5H3HIB4V,native”

    destinationAccount

    Optional. The destination account that any returned path should use.

    destinationAssetType

    Optional. The type of the destination asset: “native”, “credit_alphanum4”, or “credit_alphanum12”

    destinationAssetCode

    Required if destinationAssetType is not native. e.g. “USD”

    destinationAssetIssuer

    Required if destinationAssetType is not native

    destinationAmount

    The amount, denominated in the destination asset, that any returned path should be able to satisfy

    Return Value

    PaymentPathsResponseEnum with available paths or error

  • Finds strict send payment paths from source to destination.

    The Stellar Network allows payments to be made across assets through path payments. A path payment specifies a series of assets to route a payment through, from source asset (the asset debited from the payer) to destination asset (the asset credited to the payee).

    A Path Payment Strict Send allows a user to specify the amount of the asset to send. The amount received will vary based on offers in the order books.

    A path payment strict send search is specified using:

    • The destination account id or destination assets.
    • The source asset.
    • The source amount.

    As part of the search, Horizon will load a list of assets available to the source account id or use the assets passed in the request and will find any payment paths from those source assets to the desired destination asset. The source’s amount parameter will be used to determine if a given path can satisfy a payment of the desired amount.

    The endpoint will not allow requests which provide both a destination_account and destination_assets parameter. All requests must provide one or the other.

    Note: XLM should be represented as “native”. Issued assets should be represented as “Code:IssuerAccountID”.

    See: Stellar developer docs

    Declaration

    Swift

    open func strictSend(sourceAmount: String? = nil, sourceAssetType: String? = nil, sourceAssetCode: String? = nil, sourceAssetIssuer: String? = nil, destinationAccount: String? = nil, destinationAssets: String? = nil) async -> PaymentPathsResponseEnum

    Parameters

    sourceAmount

    Optional. The amount, denominated in the source asset, that any returned path should be able to satisfy.

    sourceAssetType

    Optional. The type of the source asset: “native”, “credit_alphanum4”, or “credit_alphanum12”

    sourceAssetCode

    Required if sourceAssetType is not native. e.g. “USD”

    sourceAssetIssuer

    Required if sourceAssetType is not native

    destinationAccount

    Optional. The destination account that any returned path should use.

    destinationAssets

    Optional. A comma separated list of assets. Any returned path must use an asset included in this list. e.g. “USD:GAEDTJ4PPEFVW5XV2S7LUXBEHNQMX5Q2GM562RJGOQG7GVCE5H3HIB4V,native”

    Return Value

    PaymentPathsResponseEnum with available paths or error