getBuyWithCryptoQuote

Get a quote of type BuyWithCryptoQuote to buy any given token with crypto. This quote contains the information about the swap such as token amounts, processing fees, estimated time etc.

Once you have the quote, you can use prepareTransaction and prepare the transaction for submission.

Example

import { getBuyWithCryptoQuote } from "@thirdweb-dev/sdk";
const quote = await getBuyWithCryptoQuote({
clientId: "...",
fromAddress: "0x...", // wallet address
fromChainId: 137, // chain id of the source token
fromTokenAddress: "0x...", // token address of the source token
fromAmount: "10", // amount of source token to swap
// optionally, you can use `toAmount` instead if you only want a certain amount of destination token
toChainId: 10, // chain id of the destination token
toTokenAddress: "0x...", // token address of the destination token
toAddress: "0x...", // optional: send the tokens to a different address
maxSlippageBPS: 50, // optional: max 0.5% slippage
});
function getBuyWithCryptoQuote(
): Promise<BuyWithCryptoQuote>;

Parameters

object of type GetBuyWithCryptoQuoteParams

Type

let params: {
client: ThirdwebClient;
fromAddress: string;
fromChainId: number;
fromTokenAddress: string;
intentId?: string;
maxSlippageBPS?: number;
purchaseData?: object;
toAddress: string;
toChainId: number;
toTokenAddress: string;
} & (
| { fromAmount: string; toAmount?: never }
| { fromAmount?: never; toAmount: string }
);

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.