PaymentOperation
public class PaymentOperation : Operation, @unchecked Sendable
Represents a payment operation that sends an asset from one account to another.
PaymentOperation is one of the most common operations on the Stellar network. It sends a specified amount of an asset (native XLM or issued assets) from the source account to a destination account. The destination account must already exist and, for non-native assets, must have a trustline established for that asset.
The payment operation will fail if:
- The destination account does not exist
- The destination lacks a trustline for non-native assets
- The source account has insufficient balance
- The destination account would exceed asset limits
- The asset issuer has authorization controls that prevent the transfer
Example:
// Send 100 XLM
let payment = try PaymentOperation(
sourceAccountId: nil,
destinationAccountId: "GDEST...",
asset: Asset(type: AssetType.ASSET_TYPE_NATIVE),
amount: 100.0
)
// Send 50 USD (issued asset)
let usd = Asset(type: AssetType.ASSET_TYPE_CREDIT_ALPHANUM4,
code: "USD",
issuer: "GISSUER...")!
let usdPayment = try PaymentOperation(
sourceAccountId: nil,
destinationAccountId: "GDEST...",
asset: usd,
amount: 50.0
)
See also:
-
The destination account that will receive the payment.
Declaration
Swift
public let destinationAccountId: String -
The asset being sent.
Declaration
Swift
public let asset: Asset -
The amount of the asset to send (in decimal format).
Declaration
Swift
public let amount: Decimal -
Creates a new PaymentOperation.
Throws
An error if the destination account ID is invalidDeclaration
Swift
public init(sourceAccountId: String?, destinationAccountId: String, asset: Asset, amount: Decimal) throwsParameters
sourceAccountIdOptional source account. If nil, uses the transaction source account.
destinationAccountIdThe account that will receive the payment (G-address or M-address)
assetThe asset to send (native XLM or issued asset)
amountThe amount to send in decimal format
-
Creates a new PaymentOperation object from the given PaymentOperationXDR object.
Declaration
Swift
public init(fromXDR: PaymentOperationXDR, sourceAccountId: String?)Parameters
fromXDRthe PaymentOperationXDR object to be used to create a new PaymentOperation object.
sourceAccountId(optional) source account Id, must be valid, otherwise it will be ignored.
View on GitHub
Install in Dash