getBuyWithFiatStatus

Once you get a quote from getBuyWithFiatQuote and open the quote.onRampLink in a new tab, you can start polling for the transaction status using getBuyWithFiatStatus

You should keep calling this function at regular intervals while the status is in one of the pending states such as - "PENDING_PAYMENT", "PENDING_ON_RAMP_TRANSFER", "ON_RAMP_TRANSFER_IN_PROGRESS", "CRYPTO_SWAP_IN_PROGRESS" etc..

If quote.onRampToken is same as quote.toToken (same chain + same token address) - This means that the token can be directly bought from the on-ramp provider. But if they are different - On-ramp provider will send the quote.onRampToken to the user's wallet address and a swap is required to convert it to the desired token. You can use the isSwapRequiredPostOnramp utility function to check if a swap is required after the on-ramp is done.

When no swap is required

If there is no swap required - the status will become "ON_RAMP_TRANSFER_COMPLETED" once the on-ramp provider has sent the tokens to the user's wallet address. Once you receive this status, the process is complete.

When a swap is required

If a swap is required - the status will become "CRYPTO_SWAP_REQUIRED" once the on-ramp provider has sent the tokens to the user's wallet address. Once you receive this status, you need to start the swap process.

On receiving the "CRYPTO_SWAP_REQUIRED" status, you can use the getPostOnRampQuote function to get the quote for the swap of type BuyWithCryptoQuote .

Once you have this quote - You can follow the same steps as mentioned in the getBuyWithCryptoQuote documentation to perform the swap.

Example

// step 1 - get a quote
const fiatQuote = await getBuyWithFiatQuote(fiatQuoteParams);
// step 2 - open the on-ramp provider UI
window.open(quote.onRampLink, "_blank");
// step 3 - keep calling getBuyWithFiatStatus while the status is in one of the pending states
const fiatStatus = await getBuyWithFiatStatus({
client,
intentId: fiatQuote.intentId,
});
// when the fiatStatus.status is "ON_RAMP_TRANSFER_COMPLETED" - the process is complete
// when the fiatStatus.status is "CRYPTO_SWAP_REQUIRED" - start the swap process
function getBuyWithFiatStatus(
): Promise<BuyWithFiatStatus>;

Parameters

Object of type GetBuyWithFiatStatusParams

Type

let params: { client: ThirdwebClient; intentId: string };

Returns

let returnType:
| { status: "NOT_FOUND" }
| {
failureMessage?: string;
fromAddress: string;
intentId: string;
purchaseData?: object;
quote: {
createdAt: string;
estimatedDurationSeconds?: number;
estimatedOnRampAmount: string;
estimatedOnRampAmountWei: string;
estimatedToTokenAmount: string;
estimatedToTokenAmountWei: string;
fromCurrency: {
amount: string;
amountUnits: string;
currencySymbol: string;
decimals: number;
};
fromCurrencyWithFees: {
amount: string;
amountUnits: string;
currencySymbol: string;
decimals: number;
};
onRampToken: PayTokenInfo;
toToken: PayTokenInfo;
};
status:
| "NONE"
| "PENDING_PAYMENT"
| "PAYMENT_FAILED"
| "PENDING_ON_RAMP_TRANSFER"
| "ON_RAMP_TRANSFER_IN_PROGRESS"
| "ON_RAMP_TRANSFER_COMPLETED"
| "ON_RAMP_TRANSFER_FAILED"
| "CRYPTO_SWAP_REQUIRED"
| "CRYPTO_SWAP_COMPLETED"
| "CRYPTO_SWAP_FALLBACK"
| "CRYPTO_SWAP_IN_PROGRESS"
| "CRYPTO_SWAP_FAILED";
toAddress: string;
};