Skip to content

Commit 151f474

Browse files
committed
GET -> POST on /prepare
1 parent 85aeb65 commit 151f474

File tree

2 files changed

+185
-234
lines changed

2 files changed

+185
-234
lines changed

Thirdweb.Console/Program.cs

Lines changed: 115 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -45,123 +45,121 @@
4545

4646
#region Bridge
4747

48-
var myWallet = await PrivateKeyWallet.Generate(client);
49-
50-
// Create a ThirdwebBridge instance
51-
var bridge = await ThirdwebBridge.Create(client);
52-
53-
// Buy - Get a quote for buying a specific amount of tokens
54-
var buyQuote = await bridge.Buy_Quote(
55-
originChainId: 1,
56-
originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
57-
destinationChainId: 324,
58-
destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
59-
buyAmountWei: BigInteger.Parse("0.01".ToWei())
60-
);
61-
Console.WriteLine($"Buy quote: {JsonConvert.SerializeObject(buyQuote, Formatting.Indented)}");
62-
63-
// Buy - Get an executable set of transactions (alongside a quote) for buying a specific amount of tokens
64-
var preparedBuy = await bridge.Buy_Prepare(
65-
originChainId: 1,
66-
originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
67-
destinationChainId: 324,
68-
destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
69-
buyAmountWei: BigInteger.Parse("0.01".ToWei()),
70-
sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
71-
receiver: await myWallet.GetAddress()
72-
);
73-
Console.WriteLine($"Prepared Buy contains {preparedBuy.Steps.Count} steps(s) with a total of {preparedBuy.Steps.Sum(step => step.Transactions.Count)} transactions!");
74-
75-
// Sell - Get a quote for selling a specific amount of tokens
76-
var sellQuote = await bridge.Sell_Quote(
77-
originChainId: 324,
78-
originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
79-
destinationChainId: 1,
80-
destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
81-
sellAmountWei: BigInteger.Parse("0.01".ToWei())
82-
);
83-
Console.WriteLine($"Sell quote: {JsonConvert.SerializeObject(sellQuote, Formatting.Indented)}");
84-
85-
// Sell - Get an executable set of transactions (alongside a quote) for selling a specific amount of tokens
86-
var preparedSell = await bridge.Sell_Prepare(
87-
originChainId: 324,
88-
originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
89-
destinationChainId: 1,
90-
destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
91-
sellAmountWei: BigInteger.Parse("0.01".ToWei()),
92-
sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
93-
receiver: await myWallet.GetAddress()
94-
);
95-
Console.WriteLine($"Prepared Sell contains {preparedBuy.Steps.Count} steps(s) with a total of {preparedBuy.Steps.Sum(step => step.Transactions.Count)} transactions!");
96-
97-
// Transfer - Get an executable transaction for transferring a specific amount of tokens
98-
var preparedTransfer = await bridge.Transfer_Prepare(
99-
chainId: 137,
100-
tokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // POL on Polygon
101-
transferAmountWei: BigInteger.Parse("0.01".ToWei()),
102-
sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
103-
receiver: await myWallet.GetAddress()
104-
);
105-
Console.WriteLine($"Prepared Transfer: {JsonConvert.SerializeObject(preparedTransfer, Formatting.Indented)}");
106-
107-
// You may use our extensions to execute yourself...
108-
var myTx = await preparedTransfer.Transactions[0].ToThirdwebTransaction(myWallet);
109-
var myHash = await ThirdwebTransaction.Send(myTx);
110-
111-
// ...and poll for the status...
112-
var status = await bridge.Status(transactionHash: myHash, chainId: 1);
113-
var isComplete = status.StatusType == StatusType.COMPLETED;
114-
Console.WriteLine($"Status: {JsonConvert.SerializeObject(status, Formatting.Indented)}");
115-
116-
// Or use our Execute extensions directly to handle everything for you!
117-
118-
// Execute a prepared Buy
119-
var buyResult = await bridge.Execute(myWallet, preparedBuy);
120-
var buyHashes = buyResult.Select(receipt => receipt.TransactionHash).ToList();
121-
Console.WriteLine($"Buy hashes: {JsonConvert.SerializeObject(buyHashes, Formatting.Indented)}");
122-
123-
// Execute a prepared Sell
124-
var sellResult = await bridge.Execute(myWallet, preparedSell);
125-
var sellHashes = sellResult.Select(receipt => receipt.TransactionHash).ToList();
126-
Console.WriteLine($"Sell hashes: {JsonConvert.SerializeObject(sellHashes, Formatting.Indented)}");
127-
128-
// Execute a prepared Transfer
129-
var transferResult = await bridge.Execute(myWallet, preparedTransfer);
130-
var transferHashes = transferResult.Select(receipt => receipt.TransactionHash).ToList();
131-
Console.WriteLine($"Transfer hashes: {JsonConvert.SerializeObject(transferHashes, Formatting.Indented)}");
132-
133-
// Onramp - Get a quote for buying crypto with Fiat
134-
var preparedOnramp = await bridge.Onramp_Prepare(
135-
onramp: OnrampProvider.Coinbase,
136-
chainId: 8453,
137-
tokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
138-
amount: "10000000",
139-
receiver: await myWallet.GetAddress()
140-
);
141-
Console.WriteLine($"Onramp link: {preparedOnramp.Link}");
142-
Console.WriteLine($"Full onramp quote and steps data: {JsonConvert.SerializeObject(preparedOnramp, Formatting.Indented)}");
143-
144-
while (true)
145-
{
146-
var onrampStatus = await bridge.Onramp_Status(id: preparedOnramp.Id);
147-
Console.WriteLine($"Full Onramp Status: {JsonConvert.SerializeObject(onrampStatus, Formatting.Indented)}");
148-
if (onrampStatus.StatusType is StatusType.COMPLETED or StatusType.FAILED)
149-
{
150-
break;
151-
}
152-
await ThirdwebTask.Delay(5000);
153-
}
154-
155-
if (preparedOnramp.IsSwapRequiredPostOnramp())
156-
{
157-
// Execute additional steps that are required post-onramp to get to your token, manually or via the Execute extension
158-
var receipts = await bridge.Execute(myWallet, preparedOnramp);
159-
Console.WriteLine($"Onramp receipts: {JsonConvert.SerializeObject(receipts, Formatting.Indented)}");
160-
}
161-
else
162-
{
163-
Console.WriteLine("No additional steps required post-onramp, you can use the tokens directly!");
164-
}
48+
// // Create a ThirdwebBridge instance
49+
// var bridge = await ThirdwebBridge.Create(client);
50+
51+
// // Buy - Get a quote for buying a specific amount of tokens
52+
// var buyQuote = await bridge.Buy_Quote(
53+
// originChainId: 1,
54+
// originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
55+
// destinationChainId: 324,
56+
// destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
57+
// buyAmountWei: BigInteger.Parse("0.01".ToWei())
58+
// );
59+
// Console.WriteLine($"Buy quote: {JsonConvert.SerializeObject(buyQuote, Formatting.Indented)}");
60+
61+
// // Buy - Get an executable set of transactions (alongside a quote) for buying a specific amount of tokens
62+
// var preparedBuy = await bridge.Buy_Prepare(
63+
// originChainId: 1,
64+
// originTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
65+
// destinationChainId: 324,
66+
// destinationTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
67+
// buyAmountWei: BigInteger.Parse("0.01".ToWei()),
68+
// sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
69+
// receiver: await myWallet.GetAddress()
70+
// );
71+
// Console.WriteLine($"Prepared Buy contains {preparedBuy.Steps.Count} steps(s) with a total of {preparedBuy.Steps.Sum(step => step.Transactions.Count)} transactions!");
72+
73+
// // Sell - Get a quote for selling a specific amount of tokens
74+
// var sellQuote = await bridge.Sell_Quote(
75+
// originChainId: 324,
76+
// originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
77+
// destinationChainId: 1,
78+
// destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
79+
// sellAmountWei: BigInteger.Parse("0.01".ToWei())
80+
// );
81+
// Console.WriteLine($"Sell quote: {JsonConvert.SerializeObject(sellQuote, Formatting.Indented)}");
82+
83+
// // Sell - Get an executable set of transactions (alongside a quote) for selling a specific amount of tokens
84+
// var preparedSell = await bridge.Sell_Prepare(
85+
// originChainId: 324,
86+
// originTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // ETH on zkSync
87+
// destinationChainId: 1,
88+
// destinationTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
89+
// sellAmountWei: BigInteger.Parse("0.01".ToWei()),
90+
// sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
91+
// receiver: await myWallet.GetAddress()
92+
// );
93+
// Console.WriteLine($"Prepared Sell contains {preparedBuy.Steps.Count} steps(s) with a total of {preparedBuy.Steps.Sum(step => step.Transactions.Count)} transactions!");
94+
95+
// // Transfer - Get an executable transaction for transferring a specific amount of tokens
96+
// var preparedTransfer = await bridge.Transfer_Prepare(
97+
// chainId: 137,
98+
// tokenAddress: Constants.NATIVE_TOKEN_ADDRESS, // POL on Polygon
99+
// transferAmountWei: BigInteger.Parse("0.01".ToWei()),
100+
// sender: await Utils.GetAddressFromENS(client, "vitalik.eth"),
101+
// receiver: await myWallet.GetAddress()
102+
// );
103+
// Console.WriteLine($"Prepared Transfer: {JsonConvert.SerializeObject(preparedTransfer, Formatting.Indented)}");
104+
105+
// // You may use our extensions to execute yourself...
106+
// var myTx = await preparedTransfer.Transactions[0].ToThirdwebTransaction(myWallet);
107+
// var myHash = await ThirdwebTransaction.Send(myTx);
108+
109+
// // ...and poll for the status...
110+
// var status = await bridge.Status(transactionHash: myHash, chainId: 1);
111+
// var isComplete = status.StatusType == StatusType.COMPLETED;
112+
// Console.WriteLine($"Status: {JsonConvert.SerializeObject(status, Formatting.Indented)}");
113+
114+
// // Or use our Execute extensions directly to handle everything for you!
115+
116+
// // Execute a prepared Buy
117+
// var buyResult = await bridge.Execute(myWallet, preparedBuy);
118+
// var buyHashes = buyResult.Select(receipt => receipt.TransactionHash).ToList();
119+
// Console.WriteLine($"Buy hashes: {JsonConvert.SerializeObject(buyHashes, Formatting.Indented)}");
120+
121+
// // Execute a prepared Sell
122+
// var sellResult = await bridge.Execute(myWallet, preparedSell);
123+
// var sellHashes = sellResult.Select(receipt => receipt.TransactionHash).ToList();
124+
// Console.WriteLine($"Sell hashes: {JsonConvert.SerializeObject(sellHashes, Formatting.Indented)}");
125+
126+
// // Execute a prepared Transfer
127+
// var transferResult = await bridge.Execute(myWallet, preparedTransfer);
128+
// var transferHashes = transferResult.Select(receipt => receipt.TransactionHash).ToList();
129+
// Console.WriteLine($"Transfer hashes: {JsonConvert.SerializeObject(transferHashes, Formatting.Indented)}");
130+
131+
// // Onramp - Get a quote for buying crypto with Fiat
132+
// var preparedOnramp = await bridge.Onramp_Prepare(
133+
// onramp: OnrampProvider.Coinbase,
134+
// chainId: 8453,
135+
// tokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
136+
// amount: "10000000",
137+
// receiver: await myWallet.GetAddress()
138+
// );
139+
// Console.WriteLine($"Onramp link: {preparedOnramp.Link}");
140+
// Console.WriteLine($"Full onramp quote and steps data: {JsonConvert.SerializeObject(preparedOnramp, Formatting.Indented)}");
141+
142+
// while (true)
143+
// {
144+
// var onrampStatus = await bridge.Onramp_Status(id: preparedOnramp.Id);
145+
// Console.WriteLine($"Full Onramp Status: {JsonConvert.SerializeObject(onrampStatus, Formatting.Indented)}");
146+
// if (onrampStatus.StatusType is StatusType.COMPLETED or StatusType.FAILED)
147+
// {
148+
// break;
149+
// }
150+
// await ThirdwebTask.Delay(5000);
151+
// }
152+
153+
// if (preparedOnramp.IsSwapRequiredPostOnramp())
154+
// {
155+
// // Execute additional steps that are required post-onramp to get to your token, manually or via the Execute extension
156+
// var receipts = await bridge.Execute(myWallet, preparedOnramp);
157+
// Console.WriteLine($"Onramp receipts: {JsonConvert.SerializeObject(receipts, Formatting.Indented)}");
158+
// }
159+
// else
160+
// {
161+
// Console.WriteLine("No additional steps required post-onramp, you can use the tokens directly!");
162+
// }
165163

166164
#endregion
167165

@@ -763,68 +761,6 @@
763761

764762
#endregion
765763

766-
#region Buy with Fiat
767-
768-
// // Supported currencies
769-
// var supportedCurrencies = await ThirdwebPay.GetBuyWithFiatCurrencies(client);
770-
// Console.WriteLine($"Supported currencies: {JsonConvert.SerializeObject(supportedCurrencies, Formatting.Indented)}");
771-
772-
// // Get a Buy with Fiat quote
773-
// var fiatQuoteParamsWithProvider = new BuyWithFiatQuoteParams(fromCurrencySymbol: "USD", toAddress: walletAddress, toChainId: "137", toTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, toAmount: "20", preferredProvider: "STRIPE");
774-
// var fiatQuoteParams = new BuyWithFiatQuoteParams(fromCurrencySymbol: "USD", toAddress: walletAddress, toChainId: "137", toTokenAddress: Constants.NATIVE_TOKEN_ADDRESS, toAmount: "20");
775-
// var fiatOnrampQuote = await ThirdwebPay.GetBuyWithFiatQuote(client, fiatQuoteParams);
776-
// Console.WriteLine($"Fiat onramp quote: {JsonConvert.SerializeObject(fiatOnrampQuote, Formatting.Indented)}");
777-
778-
// // Get a Buy with Fiat link
779-
// var onRampLink = ThirdwebPay.BuyWithFiat(fiatOnrampQuote);
780-
// Console.WriteLine($"Fiat onramp link: {onRampLink}");
781-
782-
// // Open onramp link to start the process (use your framework's version of this)
783-
// var psi = new ProcessStartInfo { FileName = onRampLink, UseShellExecute = true };
784-
// _ = Process.Start(psi);
785-
786-
// // Poll for status
787-
// var currentOnRampStatus = OnRampStatus.NONE;
788-
// while (currentOnRampStatus is not OnRampStatus.ON_RAMP_TRANSFER_COMPLETED and not OnRampStatus.ON_RAMP_TRANSFER_FAILED)
789-
// {
790-
// var onRampStatus = await ThirdwebPay.GetBuyWithFiatStatus(client, fiatOnrampQuote.IntentId);
791-
// currentOnRampStatus = Enum.Parse<OnRampStatus>(onRampStatus.Status);
792-
// Console.WriteLine($"Fiat onramp status: {JsonConvert.SerializeObject(onRampStatus, Formatting.Indented)}");
793-
// await Task.Delay(5000);
794-
// }
795-
796-
#endregion
797-
798-
#region Buy with Crypto
799-
800-
// // Swap Polygon MATIC to Base ETH
801-
// var swapQuoteParams = new BuyWithCryptoQuoteParams(
802-
// fromAddress: walletAddress,
803-
// fromChainId: 137,
804-
// fromTokenAddress: Constants.NATIVE_TOKEN_ADDRESS,
805-
// toTokenAddress: Constants.NATIVE_TOKEN_ADDRESS,
806-
// toChainId: 8453,
807-
// toAmount: "0.1"
808-
// );
809-
// var swapQuote = await ThirdwebPay.GetBuyWithCryptoQuote(client, swapQuoteParams);
810-
// Console.WriteLine($"Swap quote: {JsonConvert.SerializeObject(swapQuote, Formatting.Indented)}");
811-
812-
// // Initiate swap
813-
// var txHash3 = await ThirdwebPay.BuyWithCrypto(wallet: privateKeyWallet, buyWithCryptoQuote: swapQuote);
814-
// Console.WriteLine($"Swap transaction hash: {txHash3}");
815-
816-
// // Poll for status
817-
// var currentSwapStatus = SwapStatus.NONE;
818-
// while (currentSwapStatus is not SwapStatus.COMPLETED and not SwapStatus.FAILED)
819-
// {
820-
// var swapStatus = await ThirdwebPay.GetBuyWithCryptoStatus(client, txHash3);
821-
// currentSwapStatus = Enum.Parse<SwapStatus>(swapStatus.Status);
822-
// Console.WriteLine($"Swap status: {JsonConvert.SerializeObject(swapStatus, Formatting.Indented)}");
823-
// await Task.Delay(5000);
824-
// }
825-
826-
#endregion
827-
828764
#region Storage Actions
829765

830766
// // Will download from IPFS or normal urls

0 commit comments

Comments
 (0)