Onramp.prepare

Prepares an onramp transaction, returning a link from the specified provider to onramp to the specified token.

Example

import { Bridge } from "thirdweb";
import { ethereum } from "thirdweb/chains";
import { NATIVE_TOKEN_ADDRESS, toWei } from "thirdweb/utils";
const preparedOnramp = await Bridge.Onramp.prepare({
client: thirdwebClient,
onramp: "stripe",
chainId: ethereum.id,
tokenAddress: NATIVE_TOKEN_ADDRESS,
receiver: "0x...", // receiver's address
amount: toWei("10"), // 10 of the destination token
// Optional params:
// sender: "0x...", // sender's address
// onrampTokenAddress: NATIVE_TOKEN_ADDRESS, // token to initially onramp to
// onrampChainId: 1, // chain to initially onramp to
// currency: "USD",
// maxSteps: 2,
// purchaseData: { customId: "123" }
});
console.log(preparedOnramp.link); // URL to redirect the user to
console.log(preparedOnramp.currencyAmount); // Amount in fiat the user will pay

This function returns a quote that might look like:

{
id: "123e4567-e89b-12d3-a456-426614174000",
link: "https://onramp.example.com/session?id=...",
currency: "USD",
currencyAmount: 10.52,
destinationAmount: 10000000000000000000n, // 10 ETH if decimals 18
timestamp: 1689812800,
expiration: 1689842800,
steps: [
// ... further steps if any post-onramp swaps are needed
],
intent: {
onramp: "stripe",
chainId: 1,
tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
receiver: "0x...",
amount: "10000000000000000000"
}
}
function prepare(
options: Options,
): Promise<OnrampPrepareQuoteResponseData>;

Parameters

The options for preparing the onramp.

Type

let options: Options;

Returns

let returnType: Promise<OnrampPrepareQuoteResponseData>;

A promise that resolves to the prepared onramp details, including the link and quote.