diff --git a/apps/portal/src/app/dotnet/pay/buywithcrypto/page.mdx b/apps/portal/src/app/dotnet/pay/buywithcrypto/page.mdx deleted file mode 100644 index b04443ee830..00000000000 --- a/apps/portal/src/app/dotnet/pay/buywithcrypto/page.mdx +++ /dev/null @@ -1,38 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "BuyWithCrypto | thirdweb .NET SDK", - description: "Send a quoted swap transaction.", -}); - -# BuyWithCrypto - -Send a quoted swap transaction. See [GetBuyWithCryptoQuote](/dotnet/pay/getbuywithcryptoquote) for more information on how to get a swap quote. - -## Usage - -```csharp -using Thirdweb.Pay; - -var txHash = await ThirdwebPay.BuyWithCrypto(wallet, buyWithCryptoquote); -``` - -
- -#### wallet (required) - -An instance of `IThirdwebWallet`. This represents the signer of the transaction, which can be any type of wallet provider. - -#### BuyWithCryptoQuoteResult (required) - -See [GetBuyWithCryptoQuote](/dotnet/pay/getbuywithcryptoquote) for more information on the `BuyWithCryptoQuoteResult` object. - -
- -
- -### Return Value - -`string`: The transaction hash of the swap transaction. - -
diff --git a/apps/portal/src/app/dotnet/pay/buywithfiat/page.mdx b/apps/portal/src/app/dotnet/pay/buywithfiat/page.mdx deleted file mode 100644 index 1ea9f319b50..00000000000 --- a/apps/portal/src/app/dotnet/pay/buywithfiat/page.mdx +++ /dev/null @@ -1,36 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "BuyWithFiat | thirdweb .NET SDK", - description: "Trigger a crypto onramping flow.", -}); - -# BuyWithFiat - -Generate an onramp link to redirect users to. See [GetBuyWithFiatQuote](/dotnet/pay/getbuywithfiatquote) for more information on how to get an onramp quote. - -## Usage - -```csharp -using Thirdweb.Pay; - -// We return the raw onramp link you should redirect the user to. -var onRampLink = await ThirdwebPay.BuyWithFiat(buyWithFiatQuoteResult); -// You can then use the quote's intent id to track the onramp status. -``` - -
- -#### BuyWithFiatQuoteResult (required) - -See [GetBuyWithFiatQuote](/dotnet/pay/getbuywithfiatquote) for more information on the `BuyWithFiatQuoteResult` object. - -
- -
- -### Return Value - -`string`: The onramp link to redirect the user to. - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuyhistory/page.mdx b/apps/portal/src/app/dotnet/pay/getbuyhistory/page.mdx deleted file mode 100644 index d06da382f2f..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuyhistory/page.mdx +++ /dev/null @@ -1,68 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyHistory | thirdweb .NET SDK", - description: "Get buy history, supports cursor and pagination.", -}); - -# GetBuyHistory - -Get buy history for a specific wallet that executed a [Buy With Crypto](/dotnet/pay/buywithcrypto) or [Buy With Fiat](/dotnet/pay/buywithfiat) swap, supports cursor and pagination. - -## Usage - -```csharp -using Thirdweb.Pay; - -var history = await ThirdwebPay.GetBuyHistory(client, walletAddress); -``` - -
- -#### Client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -#### Wallet Address (required) - -`string`: The wallet address to get the swap history for. - -#### Start Index (optional) - -`int`: The start index of the swap history. - -#### Count (optional) - -`int`: The number of swaps to return. - -#### Cursor (optional) - -`string`: The cursor to get the next page of swap history. (Optional) - -#### Page Size (optional) - -`int`: The page size of the swap history. (Optional) - -
- -
- -### Return Value - -A `BuyHistoryResult` object containing the following properties: - -```csharp -string WalletAddress; // The wallet address. -List Page; // The buy history page. -string NextCursor; // The next cursor. -int PageSize; // The page size. -``` - -The `HistoryPage` object contains the following properties: - -```csharp -BuyWithCryptoStatusResult BuyWithCryptoStatus; // Swap status for Buy With Crypto transactions if any. -BuyWithFiatStatusResult BuyWithFiatStatus; // Swap status for Buy With Fiat transactions if any. -``` - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuywithcryptoquote/page.mdx b/apps/portal/src/app/dotnet/pay/getbuywithcryptoquote/page.mdx deleted file mode 100644 index 10afc78683d..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuywithcryptoquote/page.mdx +++ /dev/null @@ -1,83 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyWithCryptoQuote | thirdweb .NET SDK", - description: - "Get a quote containing a TransactionRequest for swapping any token pair.", -}); - -# GetBuyWithCryptoQuote - -Get a quote containing a TransactionRequest for swapping any token pair. - -## Usage - -```csharp -using Thirdweb.Pay; - -var swapQuoteParams = new BuyWithCryptoQuoteParams( - fromAddress: connectedAddress, - fromChainId: 137, - fromTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS; // MATIC - toTokenAddress: "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270"; // WMATIC - toAmount: "2" // I want to buy 2 WMATIC -); - -var quote = await ThirdwebPay.GetBuyWithCryptoQuote(client, swapQuoteParams); -``` - -
- -#### client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -#### BuyWithCryptoQuoteParams (required) - -A `BuyWithCryptoQuoteParams` object (with a helpful constructor) containing the following properties: - -```csharp -string fromAddress; // Address executing the swap -BigInteger? fromChainId; // Chain ID of the from token -string fromTokenAddress; // Address of the from token -string toTokenAddress; // Address of the to token -string fromAmount; // Optional, amount of from token -string fromAmountWei; // Optional, amount of from token in wei -BigInteger? toChainId; // Optional, chain ID of the to token -string toAmount; // Optional, amount of to token -string toAmountWei; // Optional, amount of to token in wei -string toAddress; // Optional, address to receive the to token -int? maxSlippageBPS; // Optional, maximum slippage in basis points -string intentId; // Optional, intent identifier used to link status to a BuyWithFiat onramp flow if any -object purchaseData; // Optional, additional data to be passed and retained during the flow -``` - -
- -
- -### Return Value - -A `BuyWithCryptoQuoteResult` object containing the following properties: - -```csharp -string quoteId; // Quote identifier -TransactionRequest transactionRequest; // TransactionRequest object for the swap -Approval approval; // Approval transaction details if needed -string fromAddress; // Address executing the swap -Token fromToken; // Token object of the from token -Token toToken; // Token object of the to token -string fromAmountWei; // Amount of from token in wei -string fromAmount; // Amount of from token -string toAmountMinWei; // Minimum amount of to token in wei -string toAmountMin; // Minimum amount of to token -string toAmountWei; // Amount of to token in wei -string toAmount; // Amount of to token -List paymentTokens; // Payment token details -List processingFees; // Processing fee details -Estimated estimated; // Estimated usd values, slippage, duration if available -int maxSlippageBPS; // Maximum slippage in basis points -string bridge // Bridge to be used if applicable -``` - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuywithcryptostatus/page.mdx b/apps/portal/src/app/dotnet/pay/getbuywithcryptostatus/page.mdx deleted file mode 100644 index af57fab24f0..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuywithcryptostatus/page.mdx +++ /dev/null @@ -1,51 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyWithCryptoStatus | thirdweb .NET SDK", - description: "Get swap status for a transaction hash.", -}); - -# GetBuyWithCryptoStatus - -Get swap status for a transaction hash returned by [BuyWithCrypto](/dotnet/pay/buywithcrypto). - -## Usage - -```csharp -using Thirdweb.Pay; - -var status = await ThirdwebPay.GetBuyWithCryptoStatus(client, txHash); -``` - -
- -#### Client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -#### Transaction Hash (required) - -`string`: The transaction hash of the swap transaction returned by [BuyWithCrypto](/dotnet/pay/buywithcrypto). - -
- -
- -### Return Value - -A `BuyWithCryptoStatusResult` object containing the following properties: - -```csharp -Quote Quote; // The quote object containing the swap details. -string SwapType; // The swap type, see SwapType enum. -TransactionDetails Source; // The source transaction details. -TransactionDetails Destination; // The destination transaction details. -string Status; // The status of the swap, see SwapStatus enum. -string SubStatus; // The sub status of the swap, see SwapSubStatus enum. -string FromAddress; // The source address. -string FailureMessage; // The failure message if the swap failed. -string Bridge; // The bridge used for the swap if applicable. -object PurchaseData; // Additional data passed when creating the quote -``` - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuywithfiatcurrencies/page.mdx b/apps/portal/src/app/dotnet/pay/getbuywithfiatcurrencies/page.mdx deleted file mode 100644 index 56b4bf6092f..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuywithfiatcurrencies/page.mdx +++ /dev/null @@ -1,34 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyWithFiatCurrencies | thirdweb .NET SDK", - description: "Get a list of supported fiat currencies.", -}); - -# GetBuyWithFiatCurrencies - -Returns a list of fiat currencies supported by Buy With Fiat that can be used when getting a quote using the [GetBuyWithFiatQuote](/dotnet/pay/getbuywithfiatquote) API. - -## Usage - -```csharp -using Thirdweb.Pay; - -var currencies = await ThirdwebPay.GetBuyWithFiatCurrencies(client); -``` - -
- -#### Client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -
- -
- -### Return Value - -`List`: A list of supported fiat currencies. - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuywithfiatquote/page.mdx b/apps/portal/src/app/dotnet/pay/getbuywithfiatquote/page.mdx deleted file mode 100644 index 9624e7e0e58..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuywithfiatquote/page.mdx +++ /dev/null @@ -1,80 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyWithFiatQuote | thirdweb .NET SDK", - description: - "Get a quote containing an intent id and onramp link for a fiat to crypto swap.", -}); - -# GetBuyWithFiatQuote - -Get a quote containing an intent id and onramp link for a fiat to crypto swap. - -## Usage - -```csharp -using Thirdweb.Pay; - - -var connectedAddress = await wallet.GetAddress(); - -var fiatQuoteParams = new BuyWithFiatQuoteParams( - fromCurrencySymbol: "USD", // US Dollar - toAddress: connectedAddress, // Receiver address - toChainId: "137", toTokenAddress: Thirdweb.Constants.NATIVE_TOKEN_ADDRESS, // MATIC - toAmount: "20" // I want to buy 20 MATIC -); - -var quote = await ThirdwebPay.GetBuyWithFiatQuote(client, fiatQuoteParams); -``` - -
- -#### Client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -#### BuyWithFiatQuoteParams - -A `BuyWithFiatQuoteParams` object (with a helpful constructor) containing the following properties: - -```csharp -string fromCurrencySymbol; // Currency symbol of the from token -string toAddress; // Address executing the swap -string toChainId; // Chain ID of the to token -string toTokenAddress; // Address of the to token -string fromAmount; // Optional, amount of from token -string fromAmountUnits; // Optional, amount of from token in units -string toAmount; // Optional, amount of to token -string toAmountWei; // Optional, amount of to token in wei -double? maxSlippageBPS; // Optional, maximum slippage in basis points -bool isTestMode; // Optional, enters test mode onramp flow, defaults to false -string preferredProvider; // Optional, can be set to "STRIPE", "KADO", etc. -object purchaseData; // Optional, additional data to be passed and retained during the flow -``` - -
- -
- -### Return Value - -A `BuyWithFiatQuoteResult` object containing the following properties: - -```csharp -string IntentId; // Intent identifier used to track the onramp status -string ToAddress; // Address to receive the tokens -OnRampCurrency FromCurrency; // OnRamp Currency details -OnRampCurrency FromCurrencyWithFees; // OnRamp Currency details with fees -OnRampToken OnRampToken; // OnRamp Token details -string Provider; // Onramp provider -Token ToToken; // Token details of the to token -string EstimatedToAmountMinWei; // Estimated to token amount received min in wei -string EstimatedToAmountMin; // Estimated to token amount received min -List ProcessingFees; // Processing fee details -string EstimatedDurationSeconds; // Estimated onramp duration in seconds -double MaxSlippageBPS; // Maximum slippage in basis points -string OnRampLink; // Onramp link that will be used to trigger the onramp flow -``` - -
diff --git a/apps/portal/src/app/dotnet/pay/getbuywithfiatstatus/page.mdx b/apps/portal/src/app/dotnet/pay/getbuywithfiatstatus/page.mdx deleted file mode 100644 index 4cd0ea43c64..00000000000 --- a/apps/portal/src/app/dotnet/pay/getbuywithfiatstatus/page.mdx +++ /dev/null @@ -1,74 +0,0 @@ -import { Details, createMetadata } from "@doc"; - -export const metadata = createMetadata({ - title: "GetBuyWithFiatStatus | thirdweb .NET SDK", - description: "Get swap status for a transaction hash.", -}); - -# GetBuyWithFiatStatus - -Get onramp status for an intent id returned by [BuyWithFiat](/dotnet/pay/buywithfiat). - -## Usage - -```csharp -using Thirdweb.Pay; - -var status = await ThirdwebPay.GetBuyWithFiatStatus(client, _quote.IntentId); -``` - -In some cases, you may onramp to an intermediary token that requires an additional step, in these cases the `CRYPTO_SWAP_REQUIRED` status indicates that the onramp transfer has completed and you may now use the intent id to trigger a [BuyWithCrypto](/dotnet/pay/buywithcrypto) transaction to get to your destination token. The flow is the same for [GetBuyWithCryptoQuote](/dotnet/pay/getbuywithcryptoquote), though you may now pass the intent id as a parameter to link both statuses together. - -
- -#### Client (required) - -`ThirdwebClient`: The Thirdweb client instance. - -#### Intent ID - -`string`: The intent id returned by the quote. - -
- -
- -### Return Value - -A `BuyWithFiatStatusResult` object containing the following properties: - -```csharp -string IntentId; // Intent identifier to track onramp flow status -string Status; // Status of the onramp flow -string ToAddress; // Address to receive the tokens -OnRampQuote Quote; // OnRamp Quote details -TransactionDetails Source; // Source transaction details -TransactionDetails Destination; // Destination transaction details -string FailureMessage; // Failure message if any -object PurchaseData; // Additional data passed when creating the quote -``` - -
- -
- -### OnRamp Status - -Possible status returned for a onramp transactions - -```csharp -NONE - No status. -PENDING_PAYMENT - Payment is pending. -PAYMENT_FAILED - Payment has failed. -PENDING_ON_RAMP_TRANSFER - Pending on-ramp transfer. -ON_RAMP_TRANSFER_IN_PROGRESS - On-ramp transfer is in progress. -ON_RAMP_TRANSFER_COMPLETED - On-ramp transfer is completed -ON_RAMP_TRANSFER_FAILED - On-ramp transfer has failed. -CRYPTO_SWAP_REQUIRED - Crypto swap is required. -CRYPTO_SWAP_COMPLETED - Crypto swap is completed. -CRYPTO_SWAP_FALLBACK - Crypto swap fallback. -CRYPTO_SWAP_IN_PROGRESS - Crypto swap is in progress. -CRYPTO_SWAP_FAILED - Crypto swap has failed. -``` - -
diff --git a/apps/portal/src/app/dotnet/pay/quickstart/page.mdx b/apps/portal/src/app/dotnet/pay/quickstart/page.mdx deleted file mode 100644 index 8cfadfed4cb..00000000000 --- a/apps/portal/src/app/dotnet/pay/quickstart/page.mdx +++ /dev/null @@ -1,83 +0,0 @@ -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.", -}); - -# Quickstart - -Thirdweb Universal Bridge is a powerful service that allows you to easily integrate fiat onramps and cross-chain crypto purchases. - -## Cross-Chain Swaps - -This example demonstrates how to perform a cross-chain swap using the Thirdweb Universal Bridge SDK. - -```csharp -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.Status); - Console.WriteLine($"Swap status: {JsonConvert.SerializeObject(swapStatus, Formatting.Indented)}"); - await Task.Delay(5000); -} -``` - -## Fiat Onramps - -This example demonstrates how to use the Thirdweb Universal Bridge SDK to initiate a fiat onramp. - -```csharp -// 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.Status); - Console.WriteLine($"Fiat onramp status: {JsonConvert.SerializeObject(onRampStatus, Formatting.Indented)}"); - await Task.Delay(5000); -} -``` - -## Learn More - -Please refer to our official [Thirdweb Universal Bridge](/connect/pay/overview) documentation for more general information. diff --git a/apps/portal/src/app/dotnet/sidebar.tsx b/apps/portal/src/app/dotnet/sidebar.tsx index 653f4978097..22e740d1f96 100644 --- a/apps/portal/src/app/dotnet/sidebar.tsx +++ b/apps/portal/src/app/dotnet/sidebar.tsx @@ -198,59 +198,6 @@ const transactions: SidebarLink = { ], }; -const pay: SidebarLink = { - name: "Payments", - isCollapsible: false, - links: [ - { - name: "Quickstart", - href: "/dotnet/pay/quickstart", - }, - { - name: "Buy With Fiat", - links: [ - { - name: "Get Buy With Fiat Quote", - href: "/dotnet/pay/getbuywithfiatquote", - }, - { - name: "Buy With Fiat", - href: "/dotnet/pay/buywithfiat", - }, - { - name: "Get Buy With Fiat Status", - href: "/dotnet/pay/getbuywithfiatstatus", - }, - { - name: "Get Buy With Fiat Currencies", - href: "/dotnet/pay/getbuywithfiatcurrencies", - }, - ], - }, - { - name: "Buy With Crypto", - links: [ - { - name: "Get Buy With Crypto Quote", - href: "/dotnet/pay/getbuywithcryptoquote", - }, - { - name: "Buy With Crypto", - href: "/dotnet/pay/buywithcrypto", - }, - { - name: "Get Buy With Crypto Status", - href: "/dotnet/pay/getbuywithcryptostatus", - }, - ], - }, - { - name: "Get Buy History", - href: "/dotnet/pay/getbuyhistory", - }, - ], -}; - export const sidebar: SideBar = { name: ".NET SDK", links: [ @@ -329,6 +276,23 @@ export const sidebar: SideBar = { { separator: true, }, + { + name: "Bridge", + isCollapsible: false, + links: [ + { + name: "Quickstart", + href: "/dotnet/universal-bridge/quickstart", + }, + { + name: "Universal Bridge Full Reference", + href: "https://thirdweb-dev.github.io/dotnet/docs/Thirdweb.Bridge.ThirdwebBridge.html", + }, + ], + }, + { + separator: true, + }, { name: "Indexer", isCollapsible: false, @@ -363,6 +327,5 @@ export const sidebar: SideBar = { { separator: true, }, - pay, ], }; diff --git a/apps/portal/src/app/dotnet/universal-bridge/quickstart/page.mdx b/apps/portal/src/app/dotnet/universal-bridge/quickstart/page.mdx new file mode 100644 index 00000000000..53f3df0b0d5 --- /dev/null +++ b/apps/portal/src/app/dotnet/universal-bridge/quickstart/page.mdx @@ -0,0 +1,130 @@ +import { Details, createMetadata } from "@doc"; + +export const metadata = createMetadata({ + title: "ThirdwebBridge | Thirdweb .NET SDK", + description: + "Instantiate Universal Bridge to use any asset on any chain.", +}); + +# Universal Bridge .NET Integration +We've built Universal Bridge to allow your users to use any asset on any chain, and it's ready for you to try. + +This integration simplifies onchain asset trading, and we've added extensions in .NET to integrate with any `IThirdwebWallet` nicely. + +## Core APIs + +The design is akin to letting us know what your intent is. +- Buy: "I want to buy x USDC on y Chain using z Token" +- Sell: "I want to sell x USDC on y Chain for z Token" +- Transfer: "Just transfer all my money to vitalik" + +We will return the transactions needed to achieve whatever you desire. +You may then handle execution yourself or use our extensions. + +### Instantiation +```csharp +using Thirdweb.Bridge; + +// Create a ThirdwebBridge instance +var bridge = await ThirdwebBridge.Create(client); +``` + +### Buy - Get a quote for buying a specific amount of tokens +```csharp +var buyQuote = await bridge.Buy_Quote( + originChainId: 1, + originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum + destinationChainId: 324, + destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync + buyAmountWei: BigInteger.Parse("0.1".ToWei()) +); +Console.WriteLine($"Buy quote: {JsonConvert.SerializeObject(buyQuote, Formatting.Indented)}"); +``` + +### Buy - Get an executable set of transactions (alongside a quote) for buying a specific amount of tokens +```csharp +var preparedBuy = await bridge.Buy_Prepare( + originChainId: 1, + originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum + destinationChainId: 324, + destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync + buyAmountWei: BigInteger.Parse("0.1".ToWei()), + sender: await Utils.GetAddressFromENS(client, "vitalik.eth"), + receiver: await myWallet.GetAddress() +); +Console.WriteLine($"Prepared Buy contains {preparedBuy.Transactions.Count} transaction(s)!"); +``` + +### Sell - Get a quote for selling a specific amount of tokens +```csharp +var sellQuote = await bridge.Sell_Quote( + originChainId: 324, + originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync + destinationChainId: 1, + destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum + sellAmountWei: BigInteger.Parse("0.1".ToWei()) +); +Console.WriteLine($"Sell quote: {JsonConvert.SerializeObject(sellQuote, Formatting.Indented)}"); +``` + +### Sell - Get an executable set of transactions (alongside a quote) for selling a specific amount of tokens +```csharp +var preparedSell = await bridge.Sell_Prepare( + originChainId: 324, + originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync + destinationChainId: 1, + destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum + sellAmountWei: BigInteger.Parse("0.1".ToWei()), + sender: await Utils.GetAddressFromENS(client, "vitalik.eth"), + receiver: await myWallet.GetAddress() +); +Console.WriteLine($"Prepared Sell contains {preparedSell.Transactions.Count} transaction(s)!"); +``` + +### Transfer - Get an executable transaction for transferring a specific amount of tokens +_Why not just transfer with the SDK? Stay tuned for webhooks, think direct payments!_ +```csharp +var preparedTransfer = await bridge.Transfer_Prepare( + chainId: 137, + tokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync + transferAmountWei: BigInteger.Parse("0.1".ToWei()), + sender: await Utils.GetAddressFromENS(client, "vitalik.eth"), + receiver: await myWallet.GetAddress() +); +Console.WriteLine($"Prepared Transfer: {JsonConvert.SerializeObject(preparedTransfer, Formatting.Indented)}"); +``` + +## Manual Execution +_This is not production code, we're just showcasing some of the APIs that would help you execute and poll status here._ +```csharp +// You may use our extensions to execute yourself... +var myTx = await preparedTransfer.Transactions[0].ToThirdwebTransaction(myWallet); +var myHash = await ThirdwebTransaction.Send(myTx); + +// ...and poll for the status... +var status = await bridge.Status(transactionHash: myHash, chainId: 1); +var isComplete = status.StatusType == StatusType.COMPLETED; +Console.WriteLine($"Status: {JsonConvert.SerializeObject(status, Formatting.Indented)}"); + +// Or use our Execute extensions directly to handle everything for you! +``` + +## Managed Execution +The SDK comes with some extensions that simplify the use of `ThirdwebBridge`. + +```csharp +// Execute a prepared Buy +var buyResult = await bridge.Execute(myWallet, preparedBuy); +var buyHashes = buyResult.Select(receipt => receipt.TransactionHash).ToList(); +Console.WriteLine($"Buy hashes: {JsonConvert.SerializeObject(buyHashes, Formatting.Indented)}"); + +// Execute a prepared Sell +var sellResult = await bridge.Execute(myWallet, preparedSell); +var sellHashes = sellResult.Select(receipt => receipt.TransactionHash).ToList(); +Console.WriteLine($"Sell hashes: {JsonConvert.SerializeObject(sellHashes, Formatting.Indented)}"); + +// Execute a prepared Transfer +var transferResult = await bridge.Execute(myWallet, preparedTransfer); +var transferHashes = transferResult.Select(receipt => receipt.TransactionHash).ToList(); +Console.WriteLine($"Transfer hashes: {JsonConvert.SerializeObject(transferHashes, Formatting.Indented)}"); +``` \ No newline at end of file