import { Details, createMetadata } from "@doc";
export const metadata = createMetadata({ title: "Thirdweb Universal Bridge Quickstart | thirdweb .NET SDK", description: "End to end examples for using the Thirdweb Universal Bridge SDK.", });
Thirdweb Universal Bridge is a powerful service that allows you to easily integrate fiat onramps and cross-chain crypto purchases.
This example demonstrates how to perform a cross-chain swap using the Thirdweb Universal Bridge SDK.
using Thirdweb.Pay;
// Swap Polygon MATIC to Base ETH
var swapQuoteParams = new BuyWithCryptoQuoteParams(
fromAddress: walletAddress,
fromChainId: 137,
fromTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
toTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
toChainId: 8453,
toAmount: "0.1"
);
var swapQuote = await ThirdwebPay.GetBuyWithCryptoQuote(client, swapQuoteParams);
Console.WriteLine($"Swap quote: {JsonConvert.SerializeObject(swapQuote, Formatting.Indented)}");
// Initiate swap
var txHash = await ThirdwebPay.BuyWithCrypto(wallet: privateKeyWallet, buyWithCryptoQuote: swapQuote);
Console.WriteLine($"Swap transaction hash: {txHash}");
// Poll for status
var currentSwapStatus = SwapStatus.NONE;
while (currentSwapStatus is not SwapStatus.COMPLETED and not SwapStatus.FAILED)
{
var swapStatus = await ThirdwebPay.GetBuyWithCryptoStatus(client, txHash);
currentSwapStatus = Enum.Parse<SwapStatus>(swapStatus.Status);
Console.WriteLine($"Swap status: {JsonConvert.SerializeObject(swapStatus, Formatting.Indented)}");
await Task.Delay(5000);
}
This example demonstrates how to use the Thirdweb Universal Bridge SDK to initiate a fiat onramp.
// Get a Buy with Fiat quote
var fiatQuoteParams = new BuyWithFiatQuoteParams(
fromCurrencySymbol: "USD",
toAddress: walletAddress,
toChainId: "137",
toTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS,
toAmount: "20"
);
var fiatOnrampQuote = await ThirdwebPay.GetBuyWithFiatQuote(client, fiatQuoteParams);
Console.WriteLine($"Fiat onramp quote: {JsonConvert.SerializeObject(fiatOnrampQuote, Formatting.Indented)}");
// Get a Buy with Fiat link
var onRampLink = ThirdwebPay.BuyWithFiat(fiatOnrampQuote);
Console.WriteLine($"Fiat onramp link: {onRampLink}");
// Open onramp link to start the process (use your framework's version of this)
var psi = new ProcessStartInfo { FileName = onRampLink, UseShellExecute = true };
_ = Process.Start(psi);
// Poll for status
var currentOnRampStatus = OnRampStatus.NONE;
while (currentOnRampStatus is not OnRampStatus.ON_RAMP_TRANSFER_COMPLETED and not OnRampStatus.ON_RAMP_TRANSFER_FAILED)
{
var onRampStatus = await ThirdwebPay.GetBuyWithFiatStatus(client, fiatOnrampQuote.IntentId);
currentOnRampStatus = Enum.Parse<OnRampStatus>(onRampStatus.Status);
Console.WriteLine($"Fiat onramp status: {JsonConvert.SerializeObject(onRampStatus, Formatting.Indented)}");
await Task.Delay(5000);
}
Please refer to our official Thirdweb Universal Bridge documentation for more general information.