|
1 | 1 | # thirdweb
|
2 | 2 |
|
| 3 | +## 5.93.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- [#6464](https://github.com/thirdweb-dev/js/pull/6464) [`654f879`](https://github.com/thirdweb-dev/js/commit/654f8795b45f6a14f5e4808e71f2d6143ef46171) Thanks [@gregfromstl](https://github.com/gregfromstl)! - Adds a new `Bridge` module to the thirdweb SDK to access the Universal Bridge. |
| 8 | + |
| 9 | + ## Features |
| 10 | + |
| 11 | + ### Buy & Sell Operations |
| 12 | + |
| 13 | + The Bridge module makes it easy to buy and sell tokens across chains: |
| 14 | + |
| 15 | + - `Bridge.Buy` - For specifying the destination amount you want to receive |
| 16 | + - `Bridge.Sell` - For specifying the origin amount you want to send |
| 17 | + |
| 18 | + Each operation provides two functions: |
| 19 | + |
| 20 | + 1. `quote` - Get an estimate without connecting a wallet |
| 21 | + 2. `prepare` - Get a finalized quote with transaction data |
| 22 | + |
| 23 | + #### Buy Example |
| 24 | + |
| 25 | + ```typescript |
| 26 | + import { Bridge, toWei, NATIVE_TOKEN_ADDRESS } from "thirdweb"; |
| 27 | + |
| 28 | + // First, get a quote to see approximately how much you'll pay |
| 29 | + const buyQuote = await Bridge.Buy.quote({ |
| 30 | + originChainId: 1, // Ethereum |
| 31 | + originTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 32 | + destinationChainId: 10, // Optimism |
| 33 | + destinationTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 34 | + buyAmountWei: toWei("0.01"), // I want to receive 0.01 ETH on Optimism |
| 35 | + client: thirdwebClient, |
| 36 | + }); |
| 37 | + |
| 38 | + console.log( |
| 39 | + `To get ${buyQuote.destinationAmount} wei on destination chain, you need to pay ${buyQuote.originAmount} wei`, |
| 40 | + ); |
| 41 | + |
| 42 | + // When ready to execute, prepare the transaction |
| 43 | + const preparedBuy = await Bridge.Buy.prepare({ |
| 44 | + originChainId: 1, |
| 45 | + originTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 46 | + destinationChainId: 10, |
| 47 | + destinationTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 48 | + buyAmountWei: toWei("0.01"), |
| 49 | + sender: "0x...", // Your wallet address |
| 50 | + receiver: "0x...", // Recipient address (can be the same as sender) |
| 51 | + client: thirdwebClient, |
| 52 | + }); |
| 53 | + |
| 54 | + // The prepared quote contains the transactions you need to execute |
| 55 | + console.log(`Transactions to execute: ${preparedBuy.transactions.length}`); |
| 56 | + ``` |
| 57 | + |
| 58 | + #### Sell Example |
| 59 | + |
| 60 | + ```typescript |
| 61 | + import { Bridge, toWei } from "thirdweb"; |
| 62 | + |
| 63 | + // First, get a quote to see approximately how much you'll receive |
| 64 | + const sellQuote = await Bridge.Sell.quote({ |
| 65 | + originChainId: 1, // Ethereum |
| 66 | + originTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 67 | + destinationChainId: 10, // Optimism |
| 68 | + destinationTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 69 | + sellAmountWei: toWei("0.01"), // I want to sell 0.01 ETH from Ethereum |
| 70 | + client: thirdwebClient, |
| 71 | + }); |
| 72 | + |
| 73 | + console.log( |
| 74 | + `If you send ${sellQuote.originAmount} wei, you'll receive approximately ${sellQuote.destinationAmount} wei`, |
| 75 | + ); |
| 76 | + |
| 77 | + // When ready to execute, prepare the transaction |
| 78 | + const preparedSell = await Bridge.Sell.prepare({ |
| 79 | + originChainId: 1, |
| 80 | + originTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 81 | + destinationChainId: 10, |
| 82 | + destinationTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 83 | + sellAmountWei: toWei("0.01"), |
| 84 | + sender: "0x...", // Your wallet address |
| 85 | + receiver: "0x...", // Recipient address (can be the same as sender) |
| 86 | + client: thirdwebClient, |
| 87 | + }); |
| 88 | + |
| 89 | + // Execute the transactions in sequence |
| 90 | + for (const tx of preparedSell.transactions) { |
| 91 | + // Send the transaction using your wallet |
| 92 | + // Wait for it to be mined |
| 93 | + } |
| 94 | + ``` |
| 95 | + |
| 96 | + ### Bridge Routes |
| 97 | + |
| 98 | + You can discover available bridge routes using the `routes` function: |
| 99 | + |
| 100 | + ```typescript |
| 101 | + import { Bridge, NATIVE_TOKEN_ADDRESS } from "thirdweb"; |
| 102 | + |
| 103 | + // Get all available routes |
| 104 | + const allRoutes = await Bridge.routes({ |
| 105 | + client: thirdwebClient, |
| 106 | + }); |
| 107 | + |
| 108 | + // Filter routes for a specific token or chain |
| 109 | + const filteredRoutes = await Bridge.routes({ |
| 110 | + originChainId: 1, // From Ethereum |
| 111 | + originTokenAddress: NATIVE_TOKEN_ADDRESS, |
| 112 | + destinationChainId: 10, // To Optimism |
| 113 | + client: thirdwebClient, |
| 114 | + }); |
| 115 | + |
| 116 | + // Paginate through routes |
| 117 | + const paginatedRoutes = await Bridge.routes({ |
| 118 | + limit: 10, |
| 119 | + offset: 0, |
| 120 | + client: thirdwebClient, |
| 121 | + }); |
| 122 | + ``` |
| 123 | + |
| 124 | + ### Bridge Transaction Status |
| 125 | + |
| 126 | + After executing bridge transactions, you can check their status: |
| 127 | + |
| 128 | + ```typescript |
| 129 | + import { Bridge } from "thirdweb"; |
| 130 | + |
| 131 | + // Check the status of a bridge transaction |
| 132 | + const bridgeStatus = await Bridge.status({ |
| 133 | + transactionHash: |
| 134 | + "0xe199ef82a0b6215221536e18ec512813c1aa10b4f5ed0d4dfdfcd703578da56d", |
| 135 | + chainId: 8453, // The chain ID where the transaction was initiated |
| 136 | + client: thirdwebClient, |
| 137 | + }); |
| 138 | + |
| 139 | + // The status will be one of: "COMPLETED", "PENDING", "FAILED", or "NOT_FOUND" |
| 140 | + if (bridgeStatus.status === "completed") { |
| 141 | + console.log(` |
| 142 | + Bridge completed! |
| 143 | + Sent: ${bridgeStatus.originAmount} wei on chain ${bridgeStatus.originChainId} |
| 144 | + Received: ${bridgeStatus.destinationAmount} wei on chain ${bridgeStatus.destinationChainId} |
| 145 | + `); |
| 146 | + } else if (bridgeStatus.status === "pending") { |
| 147 | + console.log("Bridge transaction is still pending..."); |
| 148 | + } else { |
| 149 | + console.log("Bridge transaction failed"); |
| 150 | + } |
| 151 | + ``` |
| 152 | + |
| 153 | + ## Error Handling |
| 154 | + |
| 155 | + The Bridge module provides consistent error handling with descriptive error messages: |
| 156 | + |
| 157 | + ```typescript |
| 158 | + try { |
| 159 | + await Bridge.Buy.quote({ |
| 160 | + // ...params |
| 161 | + }); |
| 162 | + } catch (error) { |
| 163 | + // Errors will have the format: "ErrorCode | Error message details" |
| 164 | + console.error(error.message); // e.g. "AmountTooHigh | The provided amount is too high for the requested route." |
| 165 | + } |
| 166 | + ``` |
| 167 | + |
| 168 | + ## Types |
| 169 | + |
| 170 | + The Bridge module exports the following TypeScript types: |
| 171 | + |
| 172 | + - `Route` - Describes a bridge route between chains and tokens |
| 173 | + - `Status` - Represents the status of a bridge transaction |
| 174 | + - `Quote` - Contains quote information for a bridge transaction |
| 175 | + - `PreparedQuote` - Extends Quote with transaction data |
| 176 | + |
| 177 | + ## Integration |
| 178 | + |
| 179 | + The Bridge module is accessible as a top-level export: |
| 180 | + |
| 181 | + ```typescript |
| 182 | + import { Bridge } from "thirdweb"; |
| 183 | + ``` |
| 184 | + |
| 185 | + Use `Bridge.Buy`, `Bridge.Sell`, `Bridge.routes`, and `Bridge.status` to access the corresponding functionality. |
| 186 | + |
| 187 | +### Patch Changes |
| 188 | + |
| 189 | +- [#6503](https://github.com/thirdweb-dev/js/pull/6503) [`47f8cd6`](https://github.com/thirdweb-dev/js/commit/47f8cd6d8d855bd01c4512098d7d4f0fbb44677e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - UI cleanup for multistep swaps in PayEmbed |
| 190 | + |
| 191 | +- [#6506](https://github.com/thirdweb-dev/js/pull/6506) [`d854021`](https://github.com/thirdweb-dev/js/commit/d8540216f1da8be67aee55f5583f9a019caf18c1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Pass along chainId to internal 1193 provider when connecting |
| 192 | + |
| 193 | +- [#6505](https://github.com/thirdweb-dev/js/pull/6505) [`7890145`](https://github.com/thirdweb-dev/js/commit/78901457cfb282f33cc7fb78895ea9c225e455bd) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix requireApproval option not enforced for wallet connection |
| 194 | + |
3 | 195 | ## 5.92.3
|
4 | 196 |
|
5 | 197 | ### Patch Changes
|
|
0 commit comments