ThirdwebBridge - Onramp Integration & Improved APIs
This release brings you new Onramp APIs, as well as new QOL parameters for the general ThirdwebBridge
APIs, in line with the latest changes made to the service.
Do note that some responses now have obsolete propeties. Generally the main change is that instead of returning a list of transactions, Prepare endpoints will return a set of Steps. You can still use our extensions to Execute any prepared quote you receive directly, we'll handle the steps for you as usual.
Basic example of using the new Onramp APIs in .NET
The onramp flow will return a link for you to display/open as you please. You may poll the status of that onramp by its ID.
In some cases, you may receive an additional set of onchain transactions required to get to your destination token post on-ramp, in such cases, you may use our extension IsSwapRequiredPostOnramp
to check, and if a swap is indeed required, you may use our Execute
extensions to execute the transactions, or manually execute them by going through each Step
.
// Onramp - Get a quote for buying crypto with Fiat
var preparedOnramp = await bridge.Onramp_Prepare(
onramp: OnrampProvider.Coinbase,
chainId: 8453,
tokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
amount: "10000000",
receiver: await myWallet.GetAddress()
);
Console.WriteLine($"Onramp link: {preparedOnramp.Link}");
Console.WriteLine($"Full onramp quote and steps data: {JsonConvert.SerializeObject(preparedOnramp, Formatting.Indented)}");
while (true)
{
var onrampStatus = await bridge.Onramp_Status(id: preparedOnramp.Id);
Console.WriteLine($"Full Onramp Status: {JsonConvert.SerializeObject(onrampStatus, Formatting.Indented)}");
if (onrampStatus.StatusType is StatusType.COMPLETED or StatusType.FAILED)
{
break;
}
await ThirdwebTask.Delay(5000);
}
if (preparedOnramp.IsSwapRequiredPostOnramp())
{
// Execute additional steps that are required post-onramp to get to your token, manually or via the Execute extension
var receipts = await bridge.Execute(myWallet, preparedOnramp);
Console.WriteLine($"Onramp receipts: {JsonConvert.SerializeObject(receipts, Formatting.Indented)}");
}
else
{
Console.WriteLine("No additional steps required post-onramp, you can use the tokens directly!");
}