thirdweb 5.105.38 → 5.105.40-nightly-c331d189bbe6e1d3e0a9b9916d772686bb716ad3-20250830000346

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/cjs/bridge/Token.js +4 -1
  2. package/dist/cjs/bridge/Token.js.map +1 -1
  3. package/dist/cjs/exports/react.js +4 -4
  4. package/dist/cjs/exports/react.js.map +1 -1
  5. package/dist/cjs/exports/react.native.js +1 -1
  6. package/dist/cjs/exports/react.native.js.map +1 -1
  7. package/dist/cjs/exports/tokens.js +2 -2
  8. package/dist/cjs/exports/tokens.js.map +1 -1
  9. package/dist/cjs/react/core/hooks/transaction/useSendAndConfirmTransaction.js +2 -2
  10. package/dist/cjs/react/core/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -1
  11. package/dist/cjs/react/web/hooks/transaction/useSendAndConfirmTransaction.js +81 -0
  12. package/dist/cjs/react/web/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -0
  13. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +26 -0
  14. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  15. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  16. package/dist/cjs/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  17. package/dist/cjs/react/web/ui/Bridge/FundWallet.js.map +1 -1
  18. package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  19. package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +9 -2
  20. package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -1
  21. package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +9 -2
  22. package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
  23. package/dist/cjs/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.js +9 -2
  24. package/dist/cjs/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.js.map +1 -1
  25. package/dist/cjs/stories/Bridge/fixtures.js.map +1 -1
  26. package/dist/cjs/tokens/create-token.js +2 -30
  27. package/dist/cjs/tokens/create-token.js.map +1 -1
  28. package/dist/cjs/version.js +1 -1
  29. package/dist/cjs/version.js.map +1 -1
  30. package/dist/esm/bridge/Token.js +4 -1
  31. package/dist/esm/bridge/Token.js.map +1 -1
  32. package/dist/esm/exports/react.js +1 -1
  33. package/dist/esm/exports/react.js.map +1 -1
  34. package/dist/esm/exports/react.native.js +1 -1
  35. package/dist/esm/exports/react.native.js.map +1 -1
  36. package/dist/esm/exports/tokens.js +1 -1
  37. package/dist/esm/exports/tokens.js.map +1 -1
  38. package/dist/esm/react/core/hooks/transaction/useSendAndConfirmTransaction.js +1 -1
  39. package/dist/esm/react/core/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -1
  40. package/dist/esm/react/web/hooks/transaction/useSendAndConfirmTransaction.js +78 -0
  41. package/dist/esm/react/web/hooks/transaction/useSendAndConfirmTransaction.js.map +1 -0
  42. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +26 -0
  43. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  44. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  45. package/dist/esm/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  46. package/dist/esm/react/web/ui/Bridge/FundWallet.js.map +1 -1
  47. package/dist/esm/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  48. package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +9 -2
  49. package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -1
  50. package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +9 -2
  51. package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
  52. package/dist/esm/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.js +9 -2
  53. package/dist/esm/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.js.map +1 -1
  54. package/dist/esm/stories/Bridge/fixtures.js.map +1 -1
  55. package/dist/esm/tokens/create-token.js +1 -29
  56. package/dist/esm/tokens/create-token.js.map +1 -1
  57. package/dist/esm/version.js +1 -1
  58. package/dist/esm/version.js.map +1 -1
  59. package/dist/types/bridge/Onramp.d.ts +2 -2
  60. package/dist/types/bridge/Onramp.d.ts.map +1 -1
  61. package/dist/types/bridge/Token.d.ts +7 -5
  62. package/dist/types/bridge/Token.d.ts.map +1 -1
  63. package/dist/types/bridge/index.d.ts +1 -1
  64. package/dist/types/bridge/index.d.ts.map +1 -1
  65. package/dist/types/bridge/types/Route.d.ts +7 -7
  66. package/dist/types/bridge/types/Route.d.ts.map +1 -1
  67. package/dist/types/bridge/types/Token.d.ts +2 -0
  68. package/dist/types/bridge/types/Token.d.ts.map +1 -1
  69. package/dist/types/exports/react.d.ts +1 -1
  70. package/dist/types/exports/react.d.ts.map +1 -1
  71. package/dist/types/exports/react.native.d.ts +1 -1
  72. package/dist/types/exports/react.native.d.ts.map +1 -1
  73. package/dist/types/exports/tokens.d.ts +1 -1
  74. package/dist/types/exports/tokens.d.ts.map +1 -1
  75. package/dist/types/pay/convert/get-token.d.ts +2 -2
  76. package/dist/types/pay/convert/get-token.d.ts.map +1 -1
  77. package/dist/types/react/core/hooks/transaction/useSendAndConfirmTransaction.d.ts +1 -1
  78. package/dist/types/react/core/hooks/transaction/useSendAndConfirmTransaction.d.ts.map +1 -1
  79. package/dist/types/react/core/hooks/usePaymentMethods.d.ts.map +1 -1
  80. package/dist/types/react/core/hooks/useTransactionDetails.d.ts +2 -2
  81. package/dist/types/react/core/hooks/useTransactionDetails.d.ts.map +1 -1
  82. package/dist/types/react/core/machines/paymentMachine.d.ts +4 -4
  83. package/dist/types/react/core/machines/paymentMachine.d.ts.map +1 -1
  84. package/dist/types/react/web/hooks/transaction/useSendAndConfirmTransaction.d.ts +86 -0
  85. package/dist/types/react/web/hooks/transaction/useSendAndConfirmTransaction.d.ts.map +1 -0
  86. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts +26 -0
  87. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  88. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +3 -3
  89. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  90. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts +2 -2
  91. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts.map +1 -1
  92. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts +2 -2
  93. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts.map +1 -1
  94. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts +2 -2
  95. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts.map +1 -1
  96. package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts.map +1 -1
  97. package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts.map +1 -1
  98. package/dist/types/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.d.ts.map +1 -1
  99. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts +1 -1
  100. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts.map +1 -1
  101. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts +2 -2
  102. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts.map +1 -1
  103. package/dist/types/stories/Bridge/FundWallet.stories.d.ts +2 -2
  104. package/dist/types/stories/Bridge/FundWallet.stories.d.ts.map +1 -1
  105. package/dist/types/stories/Bridge/PaymentDetails.stories.d.ts +1 -1
  106. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts +1 -1
  107. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts +1 -1
  108. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts.map +1 -1
  109. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts +1 -1
  110. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts.map +1 -1
  111. package/dist/types/stories/Bridge/fixtures.d.ts +4 -4
  112. package/dist/types/stories/Bridge/fixtures.d.ts.map +1 -1
  113. package/dist/types/stories/TokenBalanceRow.stories.d.ts +1 -1
  114. package/dist/types/tokens/create-token.d.ts +2 -1
  115. package/dist/types/tokens/create-token.d.ts.map +1 -1
  116. package/dist/types/version.d.ts +1 -1
  117. package/dist/types/version.d.ts.map +1 -1
  118. package/package.json +1 -1
  119. package/src/bridge/Onramp.ts +2 -2
  120. package/src/bridge/Token.test.ts +20 -2
  121. package/src/bridge/Token.ts +25 -9
  122. package/src/bridge/index.ts +1 -1
  123. package/src/bridge/types/Route.ts +7 -7
  124. package/src/bridge/types/Token.ts +3 -0
  125. package/src/exports/react.native.ts +1 -1
  126. package/src/exports/react.ts +1 -2
  127. package/src/exports/tokens.ts +4 -1
  128. package/src/pay/convert/get-token.ts +2 -2
  129. package/src/react/core/hooks/transaction/useSendAndConfirmTransaction.ts +1 -1
  130. package/src/react/core/hooks/usePaymentMethods.ts +2 -2
  131. package/src/react/core/hooks/useTransactionDetails.ts +2 -2
  132. package/src/react/core/machines/paymentMachine.ts +4 -4
  133. package/src/react/web/hooks/transaction/useSendAndConfirmTransaction.tsx +104 -0
  134. package/src/react/web/hooks/transaction/useSendTransaction.tsx +26 -0
  135. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +4 -4
  136. package/src/react/web/ui/Bridge/DirectPayment.tsx +6 -2
  137. package/src/react/web/ui/Bridge/FundWallet.tsx +6 -2
  138. package/src/react/web/ui/Bridge/TransactionPayment.tsx +6 -2
  139. package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.tsx +10 -2
  140. package/src/react/web/ui/prebuilt/thirdweb/ClaimButton/index.tsx +10 -2
  141. package/src/react/web/ui/prebuilt/thirdweb/CreateDirectListingButton/index.tsx +10 -2
  142. package/src/stories/Bridge/fixtures.ts +4 -4
  143. package/src/tokens/create-token.ts +2 -35
  144. package/src/version.ts +1 -1
@@ -2,7 +2,7 @@ import type { ThirdwebClient } from "../client/client.js";
2
2
  import { getThirdwebBaseUrl } from "../utils/domains.js";
3
3
  import { getClientFetch } from "../utils/fetch.js";
4
4
  import { ApiError } from "./types/Errors.js";
5
- import type { Token } from "./types/Token.js";
5
+ import type { Token, TokenWithPrices } from "./types/Token.js";
6
6
 
7
7
  /**
8
8
  * Retrieves supported Universal Bridge tokens based on the provided filters.
@@ -128,9 +128,20 @@ import type { Token } from "./types/Token.js";
128
128
  * @bridge
129
129
  * @beta
130
130
  */
131
- export async function tokens(options: tokens.Options): Promise<tokens.Result> {
132
- const { client, chainId, tokenAddress, symbol, name, limit, offset } =
133
- options;
131
+ export async function tokens<
132
+ IncludePrices extends boolean = true,
133
+ R extends Token | TokenWithPrices = TokenWithPrices,
134
+ >(options: tokens.Options<IncludePrices>): Promise<R[]> {
135
+ const {
136
+ client,
137
+ chainId,
138
+ tokenAddress,
139
+ symbol,
140
+ name,
141
+ limit,
142
+ offset,
143
+ includePrices,
144
+ } = options;
134
145
 
135
146
  const clientFetch = getClientFetch(client);
136
147
  const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/tokens`);
@@ -153,6 +164,9 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
153
164
  if (offset !== null && offset !== undefined) {
154
165
  url.searchParams.set("offset", offset.toString());
155
166
  }
167
+ if (includePrices !== undefined) {
168
+ url.searchParams.set("includePrices", includePrices.toString());
169
+ }
156
170
 
157
171
  const response = await clientFetch(url.toString());
158
172
  if (!response.ok) {
@@ -165,7 +179,7 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
165
179
  });
166
180
  }
167
181
 
168
- const { data }: { data: Token[] } = await response.json();
182
+ const { data }: { data: R[] } = await response.json();
169
183
  return data;
170
184
  }
171
185
 
@@ -173,7 +187,7 @@ export declare namespace tokens {
173
187
  /**
174
188
  * Input parameters for {@link tokens}.
175
189
  */
176
- type Options = {
190
+ type Options<IncludePrices extends boolean> = {
177
191
  /** Your {@link ThirdwebClient} instance. */
178
192
  client: ThirdwebClient;
179
193
  /** Filter by a specific chain ID. */
@@ -188,12 +202,14 @@ export declare namespace tokens {
188
202
  limit?: number;
189
203
  /** Number of tokens to skip (min: 0, default: 0). */
190
204
  offset?: number | null;
205
+ /** Whether or not to include prices for the tokens. Setting this to false will speed up the request. */
206
+ includePrices?: IncludePrices;
191
207
  };
192
208
 
193
209
  /**
194
210
  * The result returned from {@link Bridge.tokens}.
195
211
  */
196
- type Result = Token[];
212
+ type Result<T extends Token | TokenWithPrices> = T[];
197
213
  }
198
214
 
199
215
  /**
@@ -254,7 +270,7 @@ export async function add(options: add.Options): Promise<add.Result> {
254
270
  });
255
271
  }
256
272
 
257
- const { data }: { data: Token } = await response.json();
273
+ const { data }: { data: TokenWithPrices } = await response.json();
258
274
  return data;
259
275
  }
260
276
 
@@ -274,5 +290,5 @@ export declare namespace add {
274
290
  /**
275
291
  * The result returned from {@link Bridge.add}.
276
292
  */
277
- type Result = Token;
293
+ type Result = TokenWithPrices;
278
294
  }
@@ -17,7 +17,7 @@ export type {
17
17
  RouteTransaction,
18
18
  } from "./types/Route.js";
19
19
  export type { Status } from "./types/Status.js";
20
- export type { Token } from "./types/Token.js";
20
+ export type { Token, TokenWithPrices } from "./types/Token.js";
21
21
  export type { WebhookPayload } from "./Webhook.js";
22
22
  export * as Webhook from "./Webhook.js";
23
23
  export { parse } from "./Webhook.js";
@@ -2,24 +2,24 @@ import type { Hex as ox__Hex } from "ox";
2
2
  import type { Chain } from "../../chains/types.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import type { Action } from "./BridgeAction.js";
5
- import type { Token } from "./Token.js";
5
+ import type { TokenWithPrices } from "./Token.js";
6
6
 
7
7
  export type Route = {
8
- originToken: Token;
9
- destinationToken: Token;
8
+ originToken: TokenWithPrices;
9
+ destinationToken: TokenWithPrices;
10
10
  };
11
11
 
12
12
  export type RouteQuoteStep = {
13
- originToken: Token;
14
- destinationToken: Token;
13
+ originToken: TokenWithPrices;
14
+ destinationToken: TokenWithPrices;
15
15
  originAmount: bigint;
16
16
  destinationAmount: bigint;
17
17
  estimatedExecutionTimeMs: number;
18
18
  };
19
19
 
20
20
  export type RouteStep = {
21
- originToken: Token;
22
- destinationToken: Token;
21
+ originToken: TokenWithPrices;
22
+ destinationToken: TokenWithPrices;
23
23
  originAmount: bigint;
24
24
  destinationAmount: bigint;
25
25
  estimatedExecutionTimeMs: number;
@@ -7,5 +7,8 @@ export type Token = {
7
7
  symbol: string;
8
8
  name: string;
9
9
  iconUri?: string;
10
+ };
11
+
12
+ export type TokenWithPrices = Token & {
10
13
  prices: Record<string, number>;
11
14
  };
@@ -59,7 +59,7 @@ export {
59
59
  export type { TransactionButtonProps } from "../react/core/hooks/transaction/transaction-button-utils.js";
60
60
  export { useEstimateGas } from "../react/core/hooks/transaction/useEstimateGas.js";
61
61
  export { useEstimateGasCost } from "../react/core/hooks/transaction/useEstimateGasCost.js";
62
- export { useSendAndConfirmTransaction } from "../react/core/hooks/transaction/useSendAndConfirmTransaction.js";
62
+ export { useSendAndConfirmTransactionCore as useSendAndConfirmTransaction } from "../react/core/hooks/transaction/useSendAndConfirmTransaction.js";
63
63
  export { useSendBatchTransaction } from "../react/core/hooks/transaction/useSendBatchTransaction.js";
64
64
  // transaction
65
65
  export type {
@@ -66,7 +66,6 @@ export {
66
66
  export type { TransactionButtonProps } from "../react/core/hooks/transaction/transaction-button-utils.js";
67
67
  export { useEstimateGas } from "../react/core/hooks/transaction/useEstimateGas.js";
68
68
  export { useEstimateGasCost } from "../react/core/hooks/transaction/useEstimateGasCost.js";
69
- export { useSendAndConfirmTransaction } from "../react/core/hooks/transaction/useSendAndConfirmTransaction.js";
70
69
  export { useSendBatchTransaction } from "../react/core/hooks/transaction/useSendBatchTransaction.js";
71
70
  // transaction
72
71
  export type {
@@ -101,7 +100,6 @@ export { useConnectionManager } from "../react/core/providers/connection-manager
101
100
  // Social
102
101
  export { useSocialProfiles } from "../react/core/social/useSocialProfiles.js";
103
102
  export type { AccountBalanceInfo } from "../react/core/utils/account.js";
104
-
105
103
  // utils
106
104
  export { createContractQuery } from "../react/core/utils/createQuery.js";
107
105
  // tokens
@@ -126,6 +124,7 @@ export {
126
124
  WalletProvider,
127
125
  type WalletProviderProps,
128
126
  } from "../react/core/wallet/provider.js";
127
+ export { useSendAndConfirmTransaction } from "../react/web/hooks/transaction/useSendAndConfirmTransaction.js";
129
128
  export { useSendTransaction } from "../react/web/hooks/transaction/useSendTransaction.js";
130
129
  export { useAutoConnect } from "../react/web/hooks/wallets/useAutoConnect.js";
131
130
  export { useLinkProfile } from "../react/web/hooks/wallets/useLinkProfile.js";
@@ -6,7 +6,10 @@ export {
6
6
  DEFAULT_DEVELOPER_ADDRESS,
7
7
  DEFAULT_DEVELOPER_REWARD_BPS,
8
8
  } from "../tokens/constants.js";
9
- export { createToken, prepareCreateToken } from "../tokens/create-token.js";
9
+ export {
10
+ getTokenAddressFromReceipt,
11
+ prepareCreateToken,
12
+ } from "../tokens/create-token.js";
10
13
  export { distributeToken } from "../tokens/distribute-token.js";
11
14
  export {
12
15
  getDeployedContractFactory,
@@ -1,5 +1,5 @@
1
1
  import { add, tokens } from "../../bridge/Token.js";
2
- import type { Token } from "../../bridge/types/Token.js";
2
+ import type { TokenWithPrices } from "../../bridge/types/Token.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import { withCache } from "../../utils/promise/withCache.js";
5
5
 
@@ -7,7 +7,7 @@ export async function getToken(
7
7
  client: ThirdwebClient,
8
8
  tokenAddress: string,
9
9
  chainId: number,
10
- ): Promise<Token> {
10
+ ): Promise<TokenWithPrices> {
11
11
  return withCache(
12
12
  async () => {
13
13
  const result = await tokens({
@@ -54,7 +54,7 @@ type SendAndConfirmTransactionConfig = {
54
54
  * ```
55
55
  * @transaction
56
56
  */
57
- export function useSendAndConfirmTransaction(
57
+ export function useSendAndConfirmTransactionCore(
58
58
  config: SendAndConfirmTransactionConfig = {},
59
59
  ): UseMutationResult<
60
60
  TransactionReceipt,
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
2
  import type { Quote } from "../../../bridge/index.js";
3
3
  import { ApiError } from "../../../bridge/types/Errors.js";
4
- import type { Token } from "../../../bridge/types/Token.js";
4
+ import type { Token, TokenWithPrices } from "../../../bridge/types/Token.js";
5
5
  import type { ThirdwebClient } from "../../../client/client.js";
6
6
  import { getThirdwebBaseUrl } from "../../../utils/domains.js";
7
7
  import { getClientFetch } from "../../../utils/fetch.js";
@@ -82,7 +82,7 @@ export function usePaymentMethods(options: {
82
82
 
83
83
  const {
84
84
  data: allValidOriginTokens,
85
- }: { data: { quote: Quote; balance: string; token: Token }[] } =
85
+ }: { data: { quote: Quote; balance: string; token: TokenWithPrices }[] } =
86
86
  await response.json();
87
87
 
88
88
  // Sort by enough balance to pay THEN gross balance
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
2
  import type { AbiFunction } from "abitype";
3
3
  import { toFunctionSelector } from "viem";
4
- import type { Token } from "../../../bridge/index.js";
4
+ import type { TokenWithPrices } from "../../../bridge/index.js";
5
5
  import type { ThirdwebClient } from "../../../client/client.js";
6
6
  import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
7
7
  import type { CompilerMetadata } from "../../../contract/actions/compiler-metadata.js";
@@ -34,7 +34,7 @@ interface TransactionDetails {
34
34
  usdValueDisplay: string | null;
35
35
  txCostDisplay: string;
36
36
  gasCostDisplay: string | null;
37
- tokenInfo: Token | null;
37
+ tokenInfo: TokenWithPrices | null;
38
38
  costWei: bigint;
39
39
  gasCostWei: bigint | null;
40
40
  totalCost: string;
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useState } from "react";
2
2
  import type { Quote } from "../../../bridge/index.js";
3
- import type { Token } from "../../../bridge/types/Token.js";
3
+ import type { TokenWithPrices } from "../../../bridge/types/Token.js";
4
4
  import type { Address } from "../../../utils/address.js";
5
5
  import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
6
6
  import type { Wallet } from "../../../wallets/interfaces/wallet.js";
@@ -23,7 +23,7 @@ export type PaymentMethod =
23
23
  | {
24
24
  type: "wallet";
25
25
  payerWallet: Wallet;
26
- originToken: Token;
26
+ originToken: TokenWithPrices;
27
27
  balance: bigint;
28
28
  quote: Quote;
29
29
  }
@@ -43,7 +43,7 @@ export interface PaymentMachineContext {
43
43
 
44
44
  // Target requirements (resolved in init state)
45
45
  destinationAmount?: string;
46
- destinationToken?: Token;
46
+ destinationToken?: TokenWithPrices;
47
47
  receiverAddress?: Address;
48
48
 
49
49
  // User selections (set in methodSelection state)
@@ -73,7 +73,7 @@ export interface PaymentMachineContext {
73
73
  type PaymentMachineEvent =
74
74
  | {
75
75
  type: "DESTINATION_CONFIRMED";
76
- destinationToken: Token;
76
+ destinationToken: TokenWithPrices;
77
77
  destinationAmount: string;
78
78
  receiverAddress: Address;
79
79
  }
@@ -0,0 +1,104 @@
1
+ import { type UseMutationResult, useMutation } from "@tanstack/react-query";
2
+ import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
3
+ import type { SendTransactionOptions } from "../../../../transaction/actions/send-transaction.js";
4
+ import { waitForReceipt } from "../../../../transaction/actions/wait-for-tx-receipt.js";
5
+ import type { TransactionReceipt } from "../../../../transaction/types.js";
6
+ import type { SendTransactionPayModalConfig } from "../../../core/hooks/transaction/useSendTransaction.js";
7
+ import { useSendTransaction } from "./useSendTransaction.js";
8
+
9
+ /**
10
+ * Configuration for the `useSendAndConfirmTransaction` hook.
11
+ */
12
+ type SendAndConfirmTransactionConfig = {
13
+ /**
14
+ * Refer to [`SendTransactionPayModalConfig`](https://portal.thirdweb.com/references/typescript/v5/SendTransactionPayModalConfig) for more details.
15
+ */
16
+ payModal?: SendTransactionPayModalConfig;
17
+
18
+ /**
19
+ * Configuration for gasless transactions.
20
+ * Refer to [`GaslessOptions`](https://portal.thirdweb.com/references/typescript/v5/GaslessOptions) for more details.
21
+ */
22
+ gasless?: GaslessOptions;
23
+ };
24
+
25
+ /**
26
+ * A hook to send a transaction and confirm the transaction with users's connected wallet
27
+ * @returns A mutation object to send a transaction.
28
+ * @example
29
+ * ```jsx
30
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
31
+ * const { mutate: sendAndConfirmTx, data: transactionReceipt } = useSendAndConfirmTransaction();
32
+ *
33
+ * // later
34
+ * sendAndConfirmTx(tx);
35
+ * ```
36
+ *
37
+ *
38
+ * ### Gasless usage with [thirdweb Engine](https://portal.thirdweb.com/engine)
39
+ * ```tsx
40
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
41
+ * const mutation = useSendAndConfirmTransaction({
42
+ * gasless: {
43
+ * provider: "engine",
44
+ * relayerUrl: "https://thirdweb.engine-***.thirdweb.com/relayer/***",
45
+ * relayerForwarderAddress: "0x...",
46
+ * }
47
+ * });
48
+ * ```
49
+ *
50
+ * ### Gasless usage with OpenZeppelin
51
+ * ```tsx
52
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
53
+ * const mutation = useSendAndConfirmTransaction({
54
+ * gasless: {
55
+ * provider: "openzeppelin",
56
+ * relayerUrl: "https://...",
57
+ * relayerForwarderAddress: "0x...",
58
+ * }
59
+ * });
60
+ * ```
61
+ *
62
+ * ### Configuring the Pay Modal
63
+ *
64
+ * When the wallet does not have enough funds to send the transaction, a modal is shown to the user to buy the required funds and then continue with the transaction.
65
+ *
66
+ * You can configure the pay modal by passing a [`SendTransactionPayModalConfig`](https://portal.thirdweb.com/references/typescript/v5/SendTransactionPayModalConfig) object to the `payModal` config.
67
+ *
68
+ * ```tsx
69
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
70
+ *
71
+ * const sendAndConfirmTx = useSendAndConfirmTransaction({
72
+ * payModal: {
73
+ * theme: "light",
74
+ * },
75
+ * });
76
+ * ```
77
+ *
78
+ * By default, the pay modal is enabled. You can disable it by passing `payModal: false` to the config.
79
+ *
80
+ * ```tsx
81
+ * import { useSendAndConfirmTransaction } from "thirdweb/react";
82
+ *
83
+ * const sendAndConfirmTx = useSendAndConfirmTransaction({
84
+ * payModal: false,
85
+ * });
86
+ * ```
87
+ * @transaction
88
+ */
89
+ export function useSendAndConfirmTransaction(
90
+ config: SendAndConfirmTransactionConfig = {},
91
+ ): UseMutationResult<
92
+ TransactionReceipt,
93
+ Error,
94
+ SendTransactionOptions["transaction"]
95
+ > {
96
+ const sendTx = useSendTransaction(config);
97
+ return useMutation({
98
+ mutationFn: async (transaction) => {
99
+ const receipt = await sendTx.mutateAsync(transaction);
100
+ const confirmedReceipt = await waitForReceipt(receipt);
101
+ return confirmedReceipt;
102
+ },
103
+ });
104
+ }
@@ -93,6 +93,32 @@ import { TransactionModal } from "../../ui/TransactionButton/TransactionModal.js
93
93
  * };
94
94
  * ```
95
95
  *
96
+ * ### Configuring the Pay Modal
97
+ *
98
+ * When the wallet does not have enough funds to send the transaction, a modal is shown to the user to buy the required funds and then continue with the transaction.
99
+ *
100
+ * You can configure the pay modal by passing a [`SendTransactionPayModalConfig`](https://portal.thirdweb.com/references/typescript/v5/SendTransactionPayModalConfig) object to the `payModal` config.
101
+ *
102
+ * ```tsx
103
+ * import { useSendTransaction } from "thirdweb/react";
104
+ *
105
+ * const sendTx = useSendTransaction({
106
+ * payModal: {
107
+ * theme: "light",
108
+ * },
109
+ * });
110
+ * ```
111
+ *
112
+ * By default, the pay modal is enabled. You can disable it by passing `payModal: false` to the config.
113
+ *
114
+ * ```tsx
115
+ * import { useSendTransaction } from "thirdweb/react";
116
+ *
117
+ * const sendTx = useSendTransaction({
118
+ * payModal: false,
119
+ * });
120
+ * ```
121
+ *
96
122
  * @transaction
97
123
  */
98
124
  export function useSendTransaction(config: SendTransactionConfig = {}) {
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useCallback, useMemo } from "react";
3
- import type { Token } from "../../../../bridge/types/Token.js";
3
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
6
6
  import type { PurchaseData } from "../../../../pay/types.js";
@@ -46,7 +46,7 @@ export type UIOptions = Prettify<
46
46
  } & (
47
47
  | {
48
48
  mode: "fund_wallet";
49
- destinationToken: Token;
49
+ destinationToken: TokenWithPrices;
50
50
  initialAmount?: string;
51
51
  presetOptions?: [number, number, number];
52
52
  }
@@ -54,7 +54,7 @@ export type UIOptions = Prettify<
54
54
  mode: "direct_payment";
55
55
  paymentInfo: {
56
56
  sellerAddress: Address;
57
- token: Token;
57
+ token: TokenWithPrices;
58
58
  amount: string;
59
59
  feePayer?: "sender" | "receiver";
60
60
  };
@@ -235,7 +235,7 @@ export function BridgeOrchestrator({
235
235
 
236
236
  // Handle requirements resolved from FundWallet and DirectPayment
237
237
  const handleRequirementsResolved = useCallback(
238
- (amount: string, token: Token, receiverAddress: Address) => {
238
+ (amount: string, token: TokenWithPrices, receiverAddress: Address) => {
239
239
  send({
240
240
  destinationAmount: amount,
241
241
  destinationToken: token,
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import type { Token } from "../../../../bridge/types/Token.js";
2
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
3
3
  import { defineChain } from "../../../../chains/utils.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import type { Address } from "../../../../utils/address.js";
@@ -28,7 +28,11 @@ export interface DirectPaymentProps {
28
28
  /**
29
29
  * Called when user continues with the payment
30
30
  */
31
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
31
+ onContinue: (
32
+ amount: string,
33
+ token: TokenWithPrices,
34
+ receiverAddress: Address,
35
+ ) => void;
32
36
 
33
37
  /**
34
38
  * Whether to show thirdweb branding in the widget.
@@ -1,7 +1,7 @@
1
1
  /** biome-ignore-all lint/a11y/useSemanticElements: FIXME */
2
2
  "use client";
3
3
  import { useRef, useState } from "react";
4
- import type { Token } from "../../../../bridge/types/Token.js";
4
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
5
5
  import type { ThirdwebClient } from "../../../../client/client.js";
6
6
  import { type Address, getAddress } from "../../../../utils/address.js";
7
7
  import { numberToPlainString } from "../../../../utils/formatNumber.js";
@@ -46,7 +46,11 @@ export interface FundWalletProps {
46
46
  /**
47
47
  * Called when continue is clicked with the resolved requirements
48
48
  */
49
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
49
+ onContinue: (
50
+ amount: string,
51
+ token: TokenWithPrices,
52
+ receiverAddress: Address,
53
+ ) => void;
50
54
 
51
55
  /**
52
56
  * Quick buy amounts
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import type { Token } from "../../../../bridge/index.js";
3
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
6
6
  import {
@@ -46,7 +46,11 @@ export interface TransactionPaymentProps {
46
46
  /**
47
47
  * Called when user confirms transaction execution
48
48
  */
49
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
49
+ onContinue: (
50
+ amount: string,
51
+ token: TokenWithPrices,
52
+ receiverAddress: Address,
53
+ ) => void;
50
54
 
51
55
  /**
52
56
  * Request to execute the transaction immediately (skips funding flow)
@@ -8,8 +8,8 @@ import { getListing } from "../../../../../../extensions/marketplace/direct-list
8
8
  import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
9
9
  import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
10
10
  import type { TransactionButtonProps } from "../../../../../core/hooks/transaction/transaction-button-utils.js";
11
- import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
12
11
  import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
12
+ import { useSendAndConfirmTransaction } from "../../../../hooks/transaction/useSendAndConfirmTransaction.js";
13
13
  import { TransactionButton } from "../../../TransactionButton/index.js";
14
14
 
15
15
  export type BuyDirectListingButtonProps = Omit<
@@ -104,7 +104,15 @@ export function BuyDirectListingButton(props: BuyDirectListingButtonProps) {
104
104
  },
105
105
  });
106
106
 
107
- const { mutateAsync } = useSendAndConfirmTransaction();
107
+ const { mutateAsync } = useSendAndConfirmTransaction({
108
+ payModal:
109
+ typeof payModal === "object"
110
+ ? {
111
+ ...payModal,
112
+ metadata: payModal.metadata || payMetadata,
113
+ }
114
+ : payModal,
115
+ });
108
116
 
109
117
  const prepareBuyTransaction = useCallback(async () => {
110
118
  if (!account) {
@@ -10,8 +10,8 @@ import type { PreparedTransaction } from "../../../../../../transaction/prepare-
10
10
  import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
11
11
  import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
12
12
  import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
13
- import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
14
13
  import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
14
+ import { useSendAndConfirmTransaction } from "../../../../hooks/transaction/useSendAndConfirmTransaction.js";
15
15
  import { TransactionButton } from "../../../TransactionButton/index.js";
16
16
  import type {
17
17
  ClaimButtonProps,
@@ -126,7 +126,15 @@ export function ClaimButton(props: ClaimButtonProps) {
126
126
  tokenId: claimParams.type === "ERC1155" ? claimParams.tokenId : undefined,
127
127
  });
128
128
  const account = useActiveAccount();
129
- const { mutateAsync } = useSendAndConfirmTransaction();
129
+ const { mutateAsync } = useSendAndConfirmTransaction({
130
+ payModal:
131
+ typeof payModal === "object"
132
+ ? {
133
+ ...payModal,
134
+ metadata: payModal.metadata || payMetadata,
135
+ }
136
+ : payModal,
137
+ });
130
138
  return (
131
139
  <TransactionButton
132
140
  payModal={{
@@ -13,8 +13,8 @@ import {
13
13
  import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
14
14
  import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
15
15
  import type { TransactionButtonProps } from "../../../../../core/hooks/transaction/transaction-button-utils.js";
16
- import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
17
16
  import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
17
+ import { useSendAndConfirmTransaction } from "../../../../hooks/transaction/useSendAndConfirmTransaction.js";
18
18
  import { TransactionButton } from "../../../TransactionButton/index.js";
19
19
 
20
20
  export type CreateDirectListingButtonProps = Omit<
@@ -88,7 +88,15 @@ export function CreateDirectListingButton(
88
88
  },
89
89
  tokenId,
90
90
  });
91
- const { mutateAsync } = useSendAndConfirmTransaction();
91
+ const { mutateAsync } = useSendAndConfirmTransaction({
92
+ payModal:
93
+ typeof payModal === "object"
94
+ ? {
95
+ ...payModal,
96
+ metadata: payModal.metadata || payMetadata,
97
+ }
98
+ : payModal,
99
+ });
92
100
 
93
101
  const prepareTransaction = useCallback(async () => {
94
102
  if (!account) {
@@ -1,5 +1,5 @@
1
1
  import { stringify } from "viem";
2
- import type { Token } from "../../bridge/index.js";
2
+ import type { TokenWithPrices } from "../../bridge/types/Token.js";
3
3
  import { base } from "../../chains/chain-definitions/base.js";
4
4
  import { baseSepolia } from "../../chains/chain-definitions/base-sepolia.js";
5
5
  import { polygon } from "../../chains/chain-definitions/polygon.js";
@@ -19,7 +19,7 @@ import { toWei } from "../../utils/units.js";
19
19
  import type { Account, Wallet } from "../../wallets/interfaces/wallet.js";
20
20
  import { storyClient } from "../utils.js";
21
21
 
22
- export const ETH: Token = {
22
+ export const ETH: TokenWithPrices = {
23
23
  address: NATIVE_TOKEN_ADDRESS,
24
24
  chainId: 10,
25
25
  decimals: 18,
@@ -32,7 +32,7 @@ export const ETH: Token = {
32
32
  symbol: "ETH",
33
33
  };
34
34
 
35
- export const USDC: Token = {
35
+ export const USDC: TokenWithPrices = {
36
36
  address: getDefaultToken(base, "USDC")?.address ?? "",
37
37
  chainId: base.id,
38
38
  decimals: 6,
@@ -45,7 +45,7 @@ export const USDC: Token = {
45
45
  symbol: "USDC",
46
46
  };
47
47
 
48
- export const UNI: Token = {
48
+ export const UNI: TokenWithPrices = {
49
49
  address: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
50
50
  chainId: 10,
51
51
  decimals: 18,