thirdweb 5.105.40 → 5.105.42-nightly-2d76cf904079cc74809f571b67ac746fad7aa04f-20250909000351

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 (189) hide show
  1. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/Executed.js +4 -2
  2. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/Executed.js.map +1 -1
  3. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.js +3 -2
  4. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.js.map +1 -1
  5. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.js +32 -0
  6. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.js.map +1 -0
  7. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/eip712Domain.js +7 -7
  8. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/eip712Domain.js.map +1 -1
  9. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getCallPoliciesForSigner.js +20 -20
  10. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getCallPoliciesForSigner.js.map +1 -1
  11. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getSessionExpirationForSigner.js +1 -1
  12. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getSessionExpirationForSigner.js.map +1 -1
  13. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getSessionStateForSigner.js +20 -20
  14. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getSessionStateForSigner.js.map +1 -1
  15. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getTransferPoliciesForSigner.js +9 -9
  16. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/getTransferPoliciesForSigner.js.map +1 -1
  17. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/isWildcardSigner.js +1 -1
  18. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/read/isWildcardSigner.js.map +1 -1
  19. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/createSessionWithSig.js +45 -45
  20. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/createSessionWithSig.js.map +1 -1
  21. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/execute.js +14 -14
  22. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/execute.js.map +1 -1
  23. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/executeWithSig.js +18 -18
  24. package/dist/cjs/extensions/erc7702/__generated__/MinimalAccount/write/executeWithSig.js.map +1 -1
  25. package/dist/cjs/gas/fee-data.js +1 -1
  26. package/dist/cjs/gas/fee-data.js.map +1 -1
  27. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.js +1 -0
  28. package/dist/cjs/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.js.map +1 -1
  29. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  30. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +1 -1
  31. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  32. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +2 -2
  33. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  34. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +1 -1
  35. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  36. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js +1 -1
  37. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  38. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js +1 -1
  39. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  40. package/dist/cjs/react/web/ui/Bridge/payment-selection/FiatProviderSelection.js +2 -1
  41. package/dist/cjs/react/web/ui/Bridge/payment-selection/FiatProviderSelection.js.map +1 -1
  42. package/dist/cjs/react/web/ui/Bridge/payment-selection/PaymentSelection.js +2 -2
  43. package/dist/cjs/react/web/ui/Bridge/payment-selection/PaymentSelection.js.map +1 -1
  44. package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +2 -6
  45. package/dist/cjs/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
  46. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js +1 -1
  47. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js.map +1 -1
  48. package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js +1 -1
  49. package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
  50. package/dist/cjs/react/web/wallets/in-app/WalletAuth.js +1 -1
  51. package/dist/cjs/react/web/wallets/in-app/WalletAuth.js.map +1 -1
  52. package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js +1 -0
  53. package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js.map +1 -1
  54. package/dist/cjs/stories/Bridge/PaymentSelection.stories.js +1 -0
  55. package/dist/cjs/stories/Bridge/PaymentSelection.stories.js.map +1 -1
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/cjs/version.js.map +1 -1
  58. package/dist/cjs/wallets/in-app/core/eip7702/minimal-account.js +117 -10
  59. package/dist/cjs/wallets/in-app/core/eip7702/minimal-account.js.map +1 -1
  60. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/Executed.js +4 -2
  61. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/Executed.js.map +1 -1
  62. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.js +3 -2
  63. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.js.map +1 -1
  64. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.js +29 -0
  65. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.js.map +1 -0
  66. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/eip712Domain.js +7 -7
  67. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/eip712Domain.js.map +1 -1
  68. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getCallPoliciesForSigner.js +20 -20
  69. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getCallPoliciesForSigner.js.map +1 -1
  70. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getSessionExpirationForSigner.js +1 -1
  71. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getSessionExpirationForSigner.js.map +1 -1
  72. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getSessionStateForSigner.js +20 -20
  73. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getSessionStateForSigner.js.map +1 -1
  74. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getTransferPoliciesForSigner.js +9 -9
  75. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/getTransferPoliciesForSigner.js.map +1 -1
  76. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/isWildcardSigner.js +1 -1
  77. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/read/isWildcardSigner.js.map +1 -1
  78. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/createSessionWithSig.js +45 -45
  79. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/createSessionWithSig.js.map +1 -1
  80. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/execute.js +14 -14
  81. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/execute.js.map +1 -1
  82. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/executeWithSig.js +18 -18
  83. package/dist/esm/extensions/erc7702/__generated__/MinimalAccount/write/executeWithSig.js.map +1 -1
  84. package/dist/esm/gas/fee-data.js +1 -1
  85. package/dist/esm/gas/fee-data.js.map +1 -1
  86. package/dist/esm/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.js +1 -0
  87. package/dist/esm/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.js.map +1 -1
  88. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  89. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +1 -1
  90. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  91. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +2 -2
  92. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  93. package/dist/esm/react/web/ui/Bridge/BuyWidget.js +1 -1
  94. package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  95. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js +1 -1
  96. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  97. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js +1 -1
  98. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  99. package/dist/esm/react/web/ui/Bridge/payment-selection/FiatProviderSelection.js +2 -1
  100. package/dist/esm/react/web/ui/Bridge/payment-selection/FiatProviderSelection.js.map +1 -1
  101. package/dist/esm/react/web/ui/Bridge/payment-selection/PaymentSelection.js +2 -2
  102. package/dist/esm/react/web/ui/Bridge/payment-selection/PaymentSelection.js.map +1 -1
  103. package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js +2 -6
  104. package/dist/esm/react/web/ui/ConnectWallet/Modal/AllWalletsUI.js.map +1 -1
  105. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js +1 -1
  106. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectModalContent.js.map +1 -1
  107. package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js +1 -1
  108. package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
  109. package/dist/esm/react/web/wallets/in-app/WalletAuth.js +1 -1
  110. package/dist/esm/react/web/wallets/in-app/WalletAuth.js.map +1 -1
  111. package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js +1 -0
  112. package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js.map +1 -1
  113. package/dist/esm/stories/Bridge/PaymentSelection.stories.js +1 -0
  114. package/dist/esm/stories/Bridge/PaymentSelection.stories.js.map +1 -1
  115. package/dist/esm/version.js +1 -1
  116. package/dist/esm/version.js.map +1 -1
  117. package/dist/esm/wallets/in-app/core/eip7702/minimal-account.js +117 -10
  118. package/dist/esm/wallets/in-app/core/eip7702/minimal-account.js.map +1 -1
  119. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/Executed.d.ts +25 -8
  120. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/Executed.d.ts.map +1 -1
  121. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.d.ts +14 -4
  122. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.d.ts.map +1 -1
  123. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.d.ts +54 -0
  124. package/dist/types/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.d.ts.map +1 -0
  125. package/dist/types/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.d.ts +4 -0
  126. package/dist/types/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.d.ts.map +1 -1
  127. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +4 -0
  128. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  129. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  130. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +5 -1
  131. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  132. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +4 -0
  133. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
  134. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts +4 -0
  135. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts.map +1 -1
  136. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts +2 -0
  137. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts.map +1 -1
  138. package/dist/types/react/web/ui/Bridge/payment-selection/FiatProviderSelection.d.ts +2 -1
  139. package/dist/types/react/web/ui/Bridge/payment-selection/FiatProviderSelection.d.ts.map +1 -1
  140. package/dist/types/react/web/ui/Bridge/payment-selection/PaymentSelection.d.ts +5 -1
  141. package/dist/types/react/web/ui/Bridge/payment-selection/PaymentSelection.d.ts.map +1 -1
  142. package/dist/types/react/web/ui/ConnectWallet/Modal/AllWalletsUI.d.ts +0 -1
  143. package/dist/types/react/web/ui/ConnectWallet/Modal/AllWalletsUI.d.ts.map +1 -1
  144. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectModalContent.d.ts.map +1 -1
  145. package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts +1 -0
  146. package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts.map +1 -1
  147. package/dist/types/react/web/wallets/in-app/WalletAuth.d.ts.map +1 -1
  148. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts +1 -0
  149. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts.map +1 -1
  150. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts +1 -0
  151. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts.map +1 -1
  152. package/dist/types/version.d.ts +1 -1
  153. package/dist/types/version.d.ts.map +1 -1
  154. package/dist/types/wallets/in-app/core/eip7702/minimal-account.d.ts +64 -0
  155. package/dist/types/wallets/in-app/core/eip7702/minimal-account.d.ts.map +1 -1
  156. package/package.json +1 -1
  157. package/src/extensions/erc7702/__generated__/MinimalAccount/events/Executed.ts +17 -4
  158. package/src/extensions/erc7702/__generated__/MinimalAccount/events/SessionCreated.ts +11 -5
  159. package/src/extensions/erc7702/__generated__/MinimalAccount/events/ValueReceived.ts +47 -0
  160. package/src/extensions/erc7702/__generated__/MinimalAccount/read/eip712Domain.ts +7 -7
  161. package/src/extensions/erc7702/__generated__/MinimalAccount/read/getCallPoliciesForSigner.ts +20 -20
  162. package/src/extensions/erc7702/__generated__/MinimalAccount/read/getSessionExpirationForSigner.ts +1 -1
  163. package/src/extensions/erc7702/__generated__/MinimalAccount/read/getSessionStateForSigner.ts +20 -20
  164. package/src/extensions/erc7702/__generated__/MinimalAccount/read/getTransferPoliciesForSigner.ts +9 -9
  165. package/src/extensions/erc7702/__generated__/MinimalAccount/read/isWildcardSigner.ts +1 -1
  166. package/src/extensions/erc7702/__generated__/MinimalAccount/write/createSessionWithSig.ts +47 -47
  167. package/src/extensions/erc7702/__generated__/MinimalAccount/write/execute.ts +16 -16
  168. package/src/extensions/erc7702/__generated__/MinimalAccount/write/executeWithSig.ts +20 -20
  169. package/src/extensions/erc7702/account/sessionkey.test.ts +2 -4
  170. package/src/gas/fee-data.ts +1 -1
  171. package/src/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.ts +5 -0
  172. package/src/react/core/hooks/transaction/useSendTransaction.ts +4 -0
  173. package/src/react/web/hooks/transaction/useSendTransaction.tsx +1 -0
  174. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +7 -0
  175. package/src/react/web/ui/Bridge/BuyWidget.tsx +6 -0
  176. package/src/react/web/ui/Bridge/CheckoutWidget.tsx +6 -0
  177. package/src/react/web/ui/Bridge/TransactionWidget.tsx +4 -0
  178. package/src/react/web/ui/Bridge/payment-selection/FiatProviderSelection.tsx +3 -0
  179. package/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx +7 -0
  180. package/src/react/web/ui/ConnectWallet/Modal/AllWalletsUI.tsx +5 -12
  181. package/src/react/web/ui/ConnectWallet/Modal/ConnectModalContent.tsx +0 -1
  182. package/src/react/web/ui/TransactionButton/TransactionModal.tsx +2 -0
  183. package/src/react/web/wallets/in-app/WalletAuth.tsx +0 -1
  184. package/src/stories/Bridge/BridgeOrchestrator.stories.tsx +1 -0
  185. package/src/stories/Bridge/PaymentSelection.stories.tsx +1 -0
  186. package/src/version.ts +1 -1
  187. package/src/wallets/in-app/core/eip7702/minimal-account.ts +149 -10
  188. package/src/wallets/in-app/web/lib/in-app-gateway.test.ts +87 -103
  189. package/src/wallets/in-app/web/lib/in-app-integration.test.ts +1 -2
@@ -14,6 +14,9 @@ import type { SignedAuthorization } from "../../../../transaction/actions/eip770
14
14
  import { toSerializableTransaction } from "../../../../transaction/actions/to-serializable-transaction.js";
15
15
  import type { SendTransactionResult } from "../../../../transaction/types.js";
16
16
  import { getAddress } from "../../../../utils/address.js";
17
+ import { getClientFetch } from "../../../../utils/fetch.js";
18
+ import { stringify } from "../../../../utils/json.js";
19
+ import { withCache } from "../../../../utils/promise/withCache.js";
17
20
  import { randomBytesHex } from "../../../../utils/random.js";
18
21
  import type {
19
22
  Account,
@@ -23,11 +26,140 @@ import {
23
26
  executeWithSignature,
24
27
  getQueuedTransactionHash,
25
28
  } from "../../../smart/lib/bundler.js";
29
+ import { getDefaultBundlerUrl } from "../../../smart/lib/constants.js";
26
30
  import type { BundlerOptions } from "../../../smart/types.js";
27
31
 
28
- const MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS =
29
- "0xD6999651Fc0964B9c6B444307a0ab20534a66560";
32
+ interface DelegationContractResponse {
33
+ id: string;
34
+ jsonrpc: string;
35
+ result: {
36
+ delegationContract: string;
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Fetches the delegation contract address from the bundler using the tw_getDelegationContract RPC method
42
+ * @internal
43
+ */
44
+ async function getDelegationContractAddress(args: {
45
+ client: ThirdwebClient;
46
+ chain: Chain;
47
+ bundlerUrl?: string;
48
+ }): Promise<string> {
49
+ const { client, chain, bundlerUrl } = args;
50
+ const url = bundlerUrl ?? getDefaultBundlerUrl(chain);
51
+
52
+ // Create a cache key based on the bundler URL to ensure we cache per chain/bundler
53
+ const cacheKey = `delegation-contract:${url}`;
54
+
55
+ return withCache(
56
+ async () => {
57
+ const fetchWithHeaders = getClientFetch(client);
58
+
59
+ const response = await fetchWithHeaders(url, {
60
+ useAuthToken: true,
61
+ body: stringify({
62
+ id: 1,
63
+ jsonrpc: "2.0",
64
+ method: "tw_getDelegationContract",
65
+ params: [],
66
+ }),
67
+ headers: {
68
+ "Content-Type": "application/json",
69
+ },
70
+ method: "POST",
71
+ });
72
+
73
+ if (!response.ok) {
74
+ throw new Error(
75
+ `Failed to fetch delegation contract: ${response.status} ${response.statusText}`,
76
+ );
77
+ }
30
78
 
79
+ const result: DelegationContractResponse = await response.json();
80
+
81
+ if ((result as any).error) {
82
+ throw new Error(
83
+ `Delegation contract RPC error: ${JSON.stringify((result as any).error)}`,
84
+ );
85
+ }
86
+
87
+ if (!result.result?.delegationContract) {
88
+ throw new Error(
89
+ "Invalid response: missing delegationContract in result",
90
+ );
91
+ }
92
+
93
+ return result.result.delegationContract;
94
+ },
95
+ { cacheKey, cacheTime: 24 * 60 * 60 * 1000 }, // cache for 24 hours
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Creates an EIP-7702 account that enables EOA (Externally Owned Account) delegation
101
+ * to smart contract functionality. This allows an EOA to delegate its code execution
102
+ * to a minimal account contract, enabling features like batch transactions and sponsored gas.
103
+ *
104
+ * The minimal account leverages EIP-7702 authorization to delegate the EOA's code to a
105
+ * MinimalAccount contract, allowing the EOA to execute smart contract functions while
106
+ * maintaining its original address and private key control.
107
+ *
108
+ * @param args - Configuration object for creating the minimal account
109
+ * @param args.client - The thirdweb client instance for blockchain interactions
110
+ * @param args.adminAccount - The EOA account that will be delegated to the minimal account contract
111
+ * @param args.sponsorGas - Optional flag to enable sponsored gas transactions via bundler
112
+ *
113
+ * @returns An Account object with enhanced capabilities including batch transactions and EIP-5792 support
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * import { createThirdwebClient, sendBatchTransaction } from "thirdweb";
118
+ * import { privateKeyToAccount } from "thirdweb/wallets";
119
+ * import { create7702MinimalAccount } from "thirdweb/wallets/in-app";
120
+ * import { sepolia } from "thirdweb/chains";
121
+ *
122
+ * // Create a client
123
+ * const client = createThirdwebClient({
124
+ * clientId: "your-client-id"
125
+ * });
126
+ *
127
+ * // Create an EOA account
128
+ * const adminAccount = privateKeyToAccount({
129
+ * client,
130
+ * privateKey: "0x..."
131
+ * });
132
+ *
133
+ * // Wrap it with a EIP-7702 account
134
+ * const minimal7702Account = create7702MinimalAccount({
135
+ * client,
136
+ * adminAccount,
137
+ * sponsorGas: true // Enable sponsored transactions
138
+ * });
139
+ *
140
+ * // Send a batch of transactions
141
+ * const result = await sendBatchTransaction({
142
+ * account: minimal7702Account,
143
+ * transactions: [
144
+ * {
145
+ * to: "0x...",
146
+ * data: "0x...",
147
+ * value: 0n,
148
+ * chainId: sepolia.id
149
+ * },
150
+ * {
151
+ * to: "0x...",
152
+ * data: "0x...",
153
+ * value: 0n,
154
+ * chainId: sepolia.id
155
+ * }
156
+ * ]});
157
+ *
158
+ * console.log("Batch transaction hash:", result.transactionHash);
159
+ * ```
160
+ *
161
+ * @wallet
162
+ */
31
163
  export const create7702MinimalAccount = (args: {
32
164
  client: ThirdwebClient;
33
165
  adminAccount: Account;
@@ -49,7 +181,14 @@ export const create7702MinimalAccount = (args: {
49
181
  });
50
182
  // check if account has been delegated already
51
183
  let authorization: SignedAuthorization | undefined;
52
- const isMinimalAccount = await is7702MinimalAccount(eoaContract);
184
+ const delegationContractAddress = await getDelegationContractAddress({
185
+ client,
186
+ chain,
187
+ });
188
+ const isMinimalAccount = await is7702MinimalAccount(
189
+ eoaContract,
190
+ delegationContractAddress,
191
+ );
53
192
  if (!isMinimalAccount) {
54
193
  // if not, sign authorization
55
194
  let nonce = firstTx.nonce
@@ -58,12 +197,12 @@ export const create7702MinimalAccount = (args: {
58
197
  await getNonce({
59
198
  client,
60
199
  address: adminAccount.address,
61
- chain: getCachedChain(firstTx.chainId),
200
+ chain,
62
201
  }),
63
202
  );
64
203
  nonce += sponsorGas ? 0n : 1n;
65
204
  const auth = await adminAccount.signAuthorization?.({
66
- address: MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS,
205
+ address: getAddress(delegationContractAddress),
67
206
  chainId: firstTx.chainId,
68
207
  nonce,
69
208
  });
@@ -76,7 +215,7 @@ export const create7702MinimalAccount = (args: {
76
215
  // send transaction from executor, needs signature
77
216
  const wrappedCalls = {
78
217
  calls: txs.map((tx) => ({
79
- data: tx.data ?? "0x", // will throw if undefined address
218
+ data: tx.data ?? "0x",
80
219
  target: getAddress(tx.to ?? ""),
81
220
  value: tx.value ?? 0n,
82
221
  })),
@@ -131,7 +270,7 @@ export const create7702MinimalAccount = (args: {
131
270
  const executeTx = execute({
132
271
  calls: txs.map((tx) => ({
133
272
  data: tx.data ?? "0x",
134
- target: tx.to ?? "",
273
+ target: getAddress(tx.to ?? ""),
135
274
  value: tx.value ?? 0n,
136
275
  })),
137
276
  contract: eoaContract,
@@ -228,7 +367,7 @@ async function getNonce(args: {
228
367
  "../../../../rpc/actions/eth_getTransactionCount.js"
229
368
  ).then(({ eth_getTransactionCount }) =>
230
369
  eth_getTransactionCount(rpcRequest, {
231
- address,
370
+ address: getAddress(address),
232
371
  blockTag: "pending",
233
372
  }),
234
373
  );
@@ -238,14 +377,14 @@ async function getNonce(args: {
238
377
  async function is7702MinimalAccount(
239
378
  // biome-ignore lint/suspicious/noExplicitAny: TODO properly type tw contract
240
379
  eoaContract: ThirdwebContract<any>,
380
+ delegationContractAddress: string,
241
381
  ): Promise<boolean> {
242
382
  const code = await getBytecode(eoaContract);
243
383
  const isDelegated = code.length > 0 && code.startsWith("0xef0100");
244
384
  const target = `0x${code.slice(8, 48)}`;
245
385
  return (
246
386
  isDelegated &&
247
- target.toLowerCase() ===
248
- MINIMAL_ACCOUNT_IMPLEMENTATION_ADDRESS.toLowerCase()
387
+ target.toLowerCase() === delegationContractAddress.toLowerCase()
249
388
  );
250
389
  }
251
390
 
@@ -1,126 +1,110 @@
1
- import { sendTransaction, signMessage } from "@thirdweb-dev/engine";
1
+ import {
2
+ configure,
3
+ isSuccessResponse,
4
+ sendTransaction,
5
+ signMessage,
6
+ } from "@thirdweb-dev/engine";
2
7
  import { beforeAll, describe, expect, it } from "vitest";
3
8
  import { TEST_CLIENT } from "~test/test-clients.js";
4
9
  import { sepolia } from "../../../../chains/chain-definitions/sepolia.js";
5
- import { createThirdwebClient } from "../../../../client/client.js";
6
10
  import { waitForTransactionHash } from "../../../../engine/wait-for-tx-hash.js";
7
- import {
8
- getThirdwebBaseUrl,
9
- setThirdwebDomains,
10
- } from "../../../../utils/domains.js";
11
- import { getClientFetch } from "../../../../utils/fetch.js";
12
11
  import { stringify } from "../../../../utils/json.js";
13
12
  import type { Account } from "../../../interfaces/wallet.js";
14
13
  import { inAppWallet } from "../in-app.js";
15
14
 
16
- // TODO: productionize this test
17
- describe
18
- .runIf(process.env.TW_SECRET_KEY)
19
- .skip("InAppWallet Gateway Tests", () => {
20
- let account: Account;
21
- let authToken: string | null | undefined;
22
- const clientIdFetch = getClientFetch(
23
- createThirdwebClient({
24
- clientId: TEST_CLIENT.clientId,
25
- }),
26
- );
15
+ describe.runIf(process.env.TW_SECRET_KEY)("InAppWallet Gateway Tests", () => {
16
+ let account: Account;
17
+ let authToken: string | null | undefined;
27
18
 
28
- beforeAll(async () => {
29
- setThirdwebDomains({
30
- bundler: "bundler.thirdweb-dev.com",
31
- engineCloud: "engine.thirdweb-dev.com",
32
- inAppWallet: "embedded-wallet.thirdweb-dev.com",
33
- rpc: "rpc.thirdweb-dev.com",
34
- });
35
- const wallet = inAppWallet();
36
- account = await wallet.connect({
37
- client: TEST_CLIENT,
38
- strategy: "backend",
39
- walletSecret: "test-secret",
40
- });
41
- authToken = wallet.getAuthToken();
42
- expect(authToken).toBeDefined();
19
+ beforeAll(async () => {
20
+ configure({
21
+ clientId: TEST_CLIENT.clientId,
22
+ secretKey: TEST_CLIENT.secretKey,
43
23
  });
24
+ const wallet = inAppWallet();
25
+ account = await wallet.connect({
26
+ client: TEST_CLIENT,
27
+ strategy: "backend",
28
+ walletSecret: "test-secret",
29
+ });
30
+ authToken = wallet.getAuthToken?.();
31
+ expect(authToken).toBeDefined();
32
+ });
44
33
 
45
- it("should sign a message with backend strategy", async () => {
46
- const rawSignature = await account.signMessage({
47
- message: "Hello, world!",
48
- });
49
-
50
- // sign via api
51
- const signResult = await signMessage({
52
- baseUrl: getThirdwebBaseUrl("engineCloud"),
53
- body: {
54
- params: [
55
- {
56
- format: "text",
57
- message: "Hello, world!",
58
- },
59
- ],
60
- signingOptions: {
61
- from: account.address,
62
- type: "EOA",
63
- },
64
- },
65
- bodySerializer: stringify,
66
- fetch: clientIdFetch,
67
- headers: {
68
- "x-wallet-access-token": authToken,
69
- },
70
- });
71
-
72
- const signatureResult = signResult.data?.result[0];
73
- if (signatureResult && "result" in signatureResult) {
74
- expect(signatureResult.result.signature).toEqual(rawSignature);
75
- } else {
76
- throw new Error(
77
- `Failed to sign message: ${stringify(signatureResult?.error) || "Unknown error"}`,
78
- );
79
- }
34
+ it("should sign a message with backend strategy", async () => {
35
+ const rawSignature = await account.signMessage({
36
+ message: "Hello, world!",
80
37
  });
81
38
 
82
- it("should queue a 7702 transaction", async () => {
83
- const body = {
84
- executionOptions: {
85
- chainId: sepolia.id,
86
- from: account.address,
87
- type: "auto" as const,
88
- },
39
+ // sign via api
40
+ const signResult = await signMessage({
41
+ body: {
89
42
  params: [
90
43
  {
91
- data: "0x",
92
- to: account.address,
93
- value: "0",
44
+ format: "text",
45
+ message: "Hello, world!",
94
46
  },
95
47
  ],
96
- };
97
- const result = await sendTransaction({
98
- baseUrl: getThirdwebBaseUrl("engineCloud"),
99
- body,
100
- bodySerializer: stringify,
101
- fetch: clientIdFetch,
102
- headers: {
103
- "x-wallet-access-token": authToken,
48
+ signingOptions: {
49
+ from: account.address,
50
+ type: "EOA",
104
51
  },
105
- });
106
- if (result.error) {
107
- throw new Error(
108
- `Error sending transaction: ${stringify(result.error)}`,
109
- );
110
- }
52
+ },
53
+ headers: {
54
+ "x-wallet-access-token": authToken,
55
+ },
56
+ });
111
57
 
112
- const txId = result.data?.result.transactions[0]?.id;
113
- console.log(txId);
114
- if (!txId) {
115
- throw new Error("No transaction ID found");
116
- }
58
+ if (signResult.error) {
59
+ throw new Error(`Error signing message: ${stringify(signResult.error)}`);
60
+ }
117
61
 
118
- const tx = await waitForTransactionHash({
119
- client: TEST_CLIENT,
120
- transactionId: txId,
121
- });
62
+ const signatureResult = signResult.data?.result?.[0];
63
+ if (signatureResult && isSuccessResponse(signatureResult)) {
64
+ expect(signatureResult.result.signature).toEqual(rawSignature);
65
+ } else {
66
+ throw new Error(
67
+ `Failed to sign message: ${stringify(signatureResult?.error) || "Unknown error"}`,
68
+ );
69
+ }
70
+ });
122
71
 
123
- console.log(tx.transactionHash);
124
- expect(tx.transactionHash).toBeDefined();
72
+ it("should queue a 4337 transaction", async () => {
73
+ const body = {
74
+ executionOptions: {
75
+ chainId: sepolia.id,
76
+ from: account.address,
77
+ type: "auto" as const,
78
+ },
79
+ params: [
80
+ {
81
+ data: "0x",
82
+ to: account.address,
83
+ value: "0",
84
+ },
85
+ ],
86
+ };
87
+ const result = await sendTransaction({
88
+ body,
89
+ headers: {
90
+ "x-wallet-access-token": authToken,
91
+ },
125
92
  });
93
+ if (result.error) {
94
+ throw new Error(`Error sending transaction: ${stringify(result.error)}`);
95
+ }
96
+
97
+ const txId = result.data?.result.transactions[0]?.id;
98
+ if (!txId) {
99
+ throw new Error("No transaction ID found");
100
+ }
101
+
102
+ const tx = await waitForTransactionHash({
103
+ client: TEST_CLIENT,
104
+ transactionId: txId,
105
+ });
106
+
107
+ console.log(tx.transactionHash);
108
+ expect(tx.transactionHash).toBeDefined();
126
109
  });
110
+ });
@@ -73,8 +73,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
73
73
  if (!executedLog) {
74
74
  throw new Error("No executed log found");
75
75
  }
76
- expect(executedLog.args.to).toBe(account.address);
77
- expect(executedLog.args.value).toBe(0n);
76
+ expect(executedLog.args.user).toBe(account.address);
78
77
  });
79
78
 
80
79
  it("should sponsor gas for a 4337 smart account", async () => {