Skip to content

xrp.buyOffer()

[Source]

Place an order on the decentralized exchange (DEX) to acquire XRP.

XRP is the base asset: amount is the XRP being bought, and price is the counter-asset paid for it.

Signature

xrp.buyOffer(
  params: XrpOfferParams,
  options?: XrpWriteOptions,
): Promise<SubmissionResult<undefined>>

Parameters

ParameterTypeRequiredDescription
amountstringYesThe amount of XRP to buy, as a decimal string. Must be non-negative, with at most 6 decimal places (1 drop, XRP's smallest unit).
orderTypeIOUOrderTypeYesThe order type: 'limit', 'market', 'fok', or 'passive'.
priceXrpOfferPriceYesWhat's offered in payment — an MPT or an IOU (see below).
domainIDstringNoRestrict the offer to a permissioned domain. Omit for the open DEX.
hybridbooleanNoWhether a domain-scoped offer also works the open DEX. Only meaningful with domainID; defaults to true when domainID is set.
offerSequencenumberNoA prior offer sequence to replace.

price (XrpOfferPrice) is one of:

ShapeDescription
{ ticker: string; issuer: string; amount: string }Priced in an IOU. Must be non-negative, with at most 15 significant digits — the XRPL issued-currency limit.
{ mptIssuanceId: string; amount: string }Priced in an MPT. However, the XRPL DEX doesn't support MPTs yet and will always be rejected.

Options

options is an optional second argument that sets the source account and overrides the fee.

OptionTypeRequiredDescription
fromAccountSelectorNoThe account to act as — an r-address string, or an object { address } or { signer, account? }. Defaults to the primary signer's primary account. (For IOU operations, this is the issuer.)
feeFeeIntentNoFee override — a priority tier and/or a maxFeeDrops cap.
idempotencyKeystringNoA prior submission's idempotencyKey, to retry to the same intent instead of creating a duplicate. Auto-generated when omitted.

Returns

Resolves to a SubmissionResult<undefined>.

Every simpleXRPL write resolves to a SubmissionResult<T> — a union tagged by source, with the backend's raw response preserved verbatim. Its common fields are:

FieldTypeDescription
intentTThe operation-specific output — see the operation's own return fields.
source'xrpld' | 'custody' | 'palisade'Which backend produced the result; discriminates response.
responseTxResponse | custody record | Palisade recordThe backend's raw response, preserved verbatim.
txHashstring (optional)The XRPL transaction hash, once the transaction is on-ledger.
intentIdstring (optional)The custodian intent id, when the path produced one. Hold onto this to resume via client.intent.
idempotencyKeystring (optional)The UUIDv7 this submission carried. Pass it back as a later call's idempotencyKey to retry to the same intent rather than creating a duplicate.

Return fields

XRP.buyOffer attaches no intent output; intent is undefined.

Underlying XRPL transactor

Builds and submits a single OfferCreate transaction, with the XRP leg as TakerPays and the price as TakerGets. Throws an IntentValidationError if price is MPT-denominated.

Example

// Buy 50 XRP, paying 100 USD for it.
await client.xrp.buyOffer({
  amount: '50',
  orderType: 'limit',
  price: { ticker: 'USD', issuer: 'rIssuer...', amount: '100' },
})