Payments

Sell a Specific Amount of Tokens

You can create a payment with either the input amount (sell) or output amount (buy) of a token. Most examples focus on buying a specific amount, but you can just as easily sell a specific amount of tokens.

Generate a sell payment

To generate a sale, use the same inputs as Buy.prepare, but with the Sell.prepare function. The following function will sell 50 USDT on Arbitrum. The returned destinationAmount will indicate how much USDC on Optimism you'll receive after fees.

import { Bridge } from "thirdweb";
const preparedQuote = await Bridge.Sell.prepare({
originChainId: 42161,
originTokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", // USDT on Arbitrum
destinationChainId: 10,
destinationTokenAddress:
"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", // USDC on Optimism
amount: 50_000_000n, // 50 USDT in wei (USDT has 6 decimals)
sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
receiver: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
client,
});

You can execute this quote exactly like a buy. See the Send a Payment guide for more details on this process.

Going further

To connect with other auth strategies, use external wallets, or sponsor gas for users, check out the following guides:

Explore Full API References