|
| 1 | +--- |
| 2 | +"thirdweb": minor |
| 3 | +--- |
| 4 | + |
| 5 | +Adds Bridge.Transfer module for direct token transfers: |
| 6 | + |
| 7 | +```typescript |
| 8 | +import { Bridge, NATIVE_TOKEN_ADDRESS } from "thirdweb"; |
| 9 | + |
| 10 | +const quote = await Bridge.Transfer.prepare({ |
| 11 | + chainId: 1, |
| 12 | + tokenAddress: NATIVE_TOKEN_ADDRESS, |
| 13 | + amount: toWei("0.01"), |
| 14 | + sender: "0x...", |
| 15 | + receiver: "0x...", |
| 16 | + client: thirdwebClient, |
| 17 | +}); |
| 18 | +``` |
| 19 | + |
| 20 | +This will return a quote that might look like: |
| 21 | +```typescript |
| 22 | +{ |
| 23 | + originAmount: 10000026098875381n, |
| 24 | + destinationAmount: 10000000000000000n, |
| 25 | + blockNumber: 22026509n, |
| 26 | + timestamp: 1741730936680, |
| 27 | + estimatedExecutionTimeMs: 1000 |
| 28 | + steps: [ |
| 29 | + { |
| 30 | + originToken: { |
| 31 | + chainId: 1, |
| 32 | + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", |
| 33 | + symbol: "ETH", |
| 34 | + name: "Ethereum", |
| 35 | + decimals: 18, |
| 36 | + priceUsd: 2000, |
| 37 | + iconUri: "https://..." |
| 38 | + }, |
| 39 | + destinationToken: { |
| 40 | + chainId: 1, |
| 41 | + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", |
| 42 | + symbol: "ETH", |
| 43 | + name: "Ethereum", |
| 44 | + decimals: 18, |
| 45 | + priceUsd: 2000, |
| 46 | + iconUri: "https://..." |
| 47 | + }, |
| 48 | + originAmount: 10000026098875381n, |
| 49 | + destinationAmount: 10000000000000000n, |
| 50 | + estimatedExecutionTimeMs: 1000 |
| 51 | + transactions: [ |
| 52 | + { |
| 53 | + action: "approval", |
| 54 | + id: "0x", |
| 55 | + to: "0x...", |
| 56 | + data: "0x...", |
| 57 | + chainId: 1, |
| 58 | + type: "eip1559" |
| 59 | + }, |
| 60 | + { |
| 61 | + action: "transfer", |
| 62 | + to: "0x...", |
| 63 | + value: 10000026098875381n, |
| 64 | + data: "0x...", |
| 65 | + chainId: 1, |
| 66 | + type: "eip1559" |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | + ], |
| 71 | + expiration: 1741730936680, |
| 72 | + intent: { |
| 73 | + chainId: 1, |
| 74 | + tokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", |
| 75 | + amount: 10000000000000000n, |
| 76 | + sender: "0x...", |
| 77 | + receiver: "0x..." |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## Sending the transactions |
| 83 | +The `transactions` array is a series of [ox](https://oxlib.sh) EIP-1559 transactions that must be executed one after the other in order to fulfill the complete route. There are a few things to keep in mind when executing these transactions: |
| 84 | + - Approvals will have the `approval` action specified. You can perform approvals with `sendAndConfirmTransaction`, then proceed to the next transaction. |
| 85 | + - All transactions are assumed to be executed by the `sender` address, regardless of which chain they are on. The final transaction will use the `receiver` as the recipient address. |
| 86 | + - If an `expiration` timestamp is provided, all transactions must be executed before that time to guarantee successful execution at the specified price. |
| 87 | + |
| 88 | +NOTE: To get the status of each non-approval transaction, use `Bridge.status` rather than checking for transaction inclusion. This function will ensure full completion of the transfer. |
| 89 | + |
| 90 | +You can include arbitrary data to be included on any webhooks and status responses with the `purchaseData` option: |
| 91 | + |
| 92 | +```ts |
| 93 | +const quote = await Bridge.Transfer.prepare({ |
| 94 | + chainId: 1, |
| 95 | + tokenAddress: NATIVE_TOKEN_ADDRESS, |
| 96 | + amount: toWei("0.01"), |
| 97 | + sender: "0x...", |
| 98 | + receiver: "0x...", |
| 99 | + purchaseData: { |
| 100 | + reference: "payment-123", |
| 101 | + metadata: { |
| 102 | + note: "Transfer to Alice" |
| 103 | + } |
| 104 | + }, |
| 105 | + client: thirdwebClient, |
| 106 | +}); |
| 107 | +``` |
| 108 | + |
| 109 | +## Fees |
| 110 | +There may be fees associated with the transfer. These fees are paid by the `feePayer` address, which defaults to the `sender` address. You can specify a different address with the `feePayer` option. If you do not specify an option or explicitly specify `sender`, the fees will be added to the input amount. If you specify the `receiver` as the fee payer the fees will be subtracted from the destination amount. |
| 111 | + |
| 112 | +For example, if you were to request a transfer with `feePayer` set to `receiver`: |
| 113 | +```typescript |
| 114 | +const quote = await Bridge.Transfer.prepare({ |
| 115 | + chainId: 1, |
| 116 | + tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC |
| 117 | + amount: 100_000_000n, // 100 USDC |
| 118 | + sender: "0x...", |
| 119 | + receiver: "0x...", |
| 120 | + feePayer: "receiver", |
| 121 | + client: thirdwebClient, |
| 122 | +}); |
| 123 | +``` |
| 124 | + |
| 125 | +The returned quote might look like: |
| 126 | +```typescript |
| 127 | +{ |
| 128 | + originAmount: 100_000_000n, // 100 USDC |
| 129 | + destinationAmount: 99_970_000n, // 99.97 USDC |
| 130 | + ... |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +If you were to request a transfer with `feePayer` set to `sender`: |
| 135 | +```typescript |
| 136 | +const quote = await Bridge.Transfer.prepare({ |
| 137 | + chainId: 1, |
| 138 | + tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC |
| 139 | + amount: 100_000_000n, // 100 USDC |
| 140 | + sender: "0x...", |
| 141 | + receiver: "0x...", |
| 142 | + feePayer: "sender", |
| 143 | + client: thirdwebClient, |
| 144 | +}); |
| 145 | +``` |
| 146 | + |
| 147 | +The returned quote might look like: |
| 148 | +```typescript |
| 149 | +{ |
| 150 | + originAmount: 100_030_000n, // 100.03 USDC |
| 151 | + destinationAmount: 100_000_000n, // 100 USDC |
| 152 | + ... |
| 153 | +} |
| 154 | +``` |
0 commit comments