getPostOnRampQuote

When buying a token with fiat currency - It only involes doing on-ramp if the on-ramp provider supports buying the given destination token directly.

If the on-ramp provider does not support buying the destination token directly, user can be sent an intermediate token with fiat currency from the on-ramp provider which can be swapped to destination token onchain.

getPostOnRampQuote function is used to get the quote for swapping the on-ramp token to destination token.

When you get a "Buy with Fiat" status of type "CRYPTO_SWAP_REQUIRED" from the getBuyWithFiatStatus function, you can use getPostOnRampQuote function to get the quote of type BuyWithCryptoQuote for swapping the on-ramp token to destination token

Once you have the quote, you can start the Swap process by following the same steps as mentioned in the getBuyWithCryptoQuote documentation.

Example

import {
getPostOnRampQuote,
getBuyWithFiatStatus,
} from "thirdweb/pay";
// previous steps
const fiatQuote = await getBuyWithFiatQuote(fiatQuoteParams);
window.open(fiatQuote.onRampLink, "_blank");
const buyWithFiatStatus = await getBuyWithFiatStatus({
client,
intentId,
}); // keep calling this until status is "settled" state
// when a swap is required after onramp
if (buyWithFiatStatus.status === "CRYPTO_SWAP_REQUIRED") {
const buyWithCryptoQuote = await getPostOnRampQuote({
client,
buyWithFiatStatus,
});
}
function getPostOnRampQuote(
): Promise<BuyWithCryptoQuote>;

Parameters

object of type GetPostOnRampQuoteParams

Type

let params: {
buyWithFiatStatus: BuyWithFiatStatus;
client: ThirdwebClient;
};

Returns

let returnType: {
client: ThirdwebClient;
paymentTokens: Array<QuotePaymentToken>;
processingFees: Array<QuotePaymentToken>;
swapDetails: {
estimated: {
durationSeconds?: number;
feesUSDCents: number;
fromAmountUSDCents: number;
gasCostUSDCents?: number;
slippageBPS: number;
toAmountMinUSDCents: number;
toAmountUSDCents: number;
};
fromAddress: string;
fromAmount: string;
fromAmountWei: string;
fromToken: QuoteTokenInfo;
maxSlippageBPS: number;
toAddress: string;
toAmount: string;
toAmountMin: string;
toAmountMinWei: string;
toAmountWei: string;
toToken: QuoteTokenInfo;
};
transactionRequest: PrepareTransactionOptions;
};

Object of type BuyWithCryptoQuote which contains the information about the quote such as processing fees, estimated time, converted token amounts, etc.