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:
- Stellar developer docs
- PathPaymentOperation for executing path payments
-
findPaymentPaths(destinationAccount:AsynchronousdestinationAssetType: destinationAssetCode: destinationAssetIssuer: destinationAmount: sourceAccount: ) 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 -> PaymentPathsResponseEnumParameters
destinationAccountThe destination account ID
destinationAssetTypeType of destination asset: “native”, “credit_alphanum4”, or “credit_alphanum12”
destinationAssetCodeAsset code if not “native”
destinationAssetIssuerAsset issuer if not “native”
destinationAmountThe amount to be received by the destination
sourceAccountThe source account ID
Return Value
PaymentPathsResponseEnum with available paths or error
-
strictReceive(sourceAccount:AsynchronoussourceAssets: destinationAccount: destinationAssetType: destinationAssetCode: destinationAssetIssuer: destinationAmount: ) 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”.
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 -> PaymentPathsResponseEnumParameters
sourceAccountOptional. The sender’s account id. Any returned path must use an asset that the sender has a trustline to.
sourceAssetsOptional. A comma separated list of assets. Any returned path must use an asset included in this list. e.g. “USD:GAEDTJ4PPEFVW5XV2S7LUXBEHNQMX5Q2GM562RJGOQG7GVCE5H3HIB4V,native”
destinationAccountOptional. The destination account that any returned path should use.
destinationAssetTypeOptional. The type of the destination asset: “native”, “credit_alphanum4”, or “credit_alphanum12”
destinationAssetCodeRequired if destinationAssetType is not native. e.g. “USD”
destinationAssetIssuerRequired if destinationAssetType is not native
destinationAmountThe amount, denominated in the destination asset, that any returned path should be able to satisfy
Return Value
PaymentPathsResponseEnum with available paths or error
-
strictSend(sourceAmount:AsynchronoussourceAssetType: sourceAssetCode: sourceAssetIssuer: destinationAccount: destinationAssets: ) 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”.
Declaration
Swift
open func strictSend(sourceAmount: String? = nil, sourceAssetType: String? = nil, sourceAssetCode: String? = nil, sourceAssetIssuer: String? = nil, destinationAccount: String? = nil, destinationAssets: String? = nil) async -> PaymentPathsResponseEnumParameters
sourceAmountOptional. The amount, denominated in the source asset, that any returned path should be able to satisfy.
sourceAssetTypeOptional. The type of the source asset: “native”, “credit_alphanum4”, or “credit_alphanum12”
sourceAssetCodeRequired if sourceAssetType is not native. e.g. “USD”
sourceAssetIssuerRequired if sourceAssetType is not native
destinationAccountOptional. The destination account that any returned path should use.
destinationAssetsOptional. 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
View on GitHub
Install in Dash