thirdweb 5.35.0-nightly-39b329a56e9eb031e1799524d827fdf69a92c854-20240717000718 → 5.35.1-nightly-0a5af48f70a76fc060909b853e20c927328c31c3-20240717194138

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 (170) hide show
  1. package/dist/cjs/chains/utils.js +9 -0
  2. package/dist/cjs/chains/utils.js.map +1 -1
  3. package/dist/cjs/exports/wallets/smart.js +4 -1
  4. package/dist/cjs/exports/wallets/smart.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  6. package/dist/cjs/react/core/utils/defaultTokens.js +8 -0
  7. package/dist/cjs/react/core/utils/defaultTokens.js.map +1 -1
  8. package/dist/cjs/react/native/ui/connect/ConnectButton.js +8 -0
  9. package/dist/cjs/react/native/ui/connect/ConnectButton.js.map +1 -1
  10. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +2 -2
  11. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  12. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +8 -0
  13. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  14. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -1
  15. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  16. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +8 -0
  17. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  18. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +9 -7
  19. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  20. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js +3 -3
  21. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js.map +1 -1
  22. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.js +1 -1
  23. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.js.map +1 -1
  24. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +1 -1
  25. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
  26. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js +3 -3
  27. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js.map +1 -1
  28. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js +2 -2
  29. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js.map +1 -1
  30. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js.map +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.js +2 -2
  33. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.js.map +1 -1
  34. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
  35. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
  36. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.js +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.js.map +1 -1
  38. package/dist/cjs/react/web/ui/PayEmbed.js +9 -1
  39. package/dist/cjs/react/web/ui/PayEmbed.js.map +1 -1
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/wallets/smart/index.js +71 -1
  42. package/dist/cjs/wallets/smart/index.js.map +1 -1
  43. package/dist/cjs/wallets/smart/lib/bundler.js +32 -7
  44. package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
  45. package/dist/cjs/wallets/smart/lib/paymaster.js +16 -2
  46. package/dist/cjs/wallets/smart/lib/paymaster.js.map +1 -1
  47. package/dist/cjs/wallets/smart/lib/userop.js +4 -1
  48. package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
  49. package/dist/cjs/wallets/smart/types.js +41 -0
  50. package/dist/cjs/wallets/smart/types.js.map +1 -1
  51. package/dist/esm/chains/utils.js +8 -0
  52. package/dist/esm/chains/utils.js.map +1 -1
  53. package/dist/esm/exports/wallets/smart.js +2 -1
  54. package/dist/esm/exports/wallets/smart.js.map +1 -1
  55. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  56. package/dist/esm/react/core/utils/defaultTokens.js +8 -0
  57. package/dist/esm/react/core/utils/defaultTokens.js.map +1 -1
  58. package/dist/esm/react/native/ui/connect/ConnectButton.js +8 -0
  59. package/dist/esm/react/native/ui/connect/ConnectButton.js.map +1 -1
  60. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +2 -2
  61. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  62. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +8 -0
  63. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  64. package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -1
  65. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  66. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +8 -0
  67. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  68. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +9 -7
  69. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  70. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js +3 -3
  71. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.js.map +1 -1
  72. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.js +1 -1
  73. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.js.map +1 -1
  74. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +1 -1
  75. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
  76. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js +3 -3
  77. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js.map +1 -1
  78. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js +2 -2
  79. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js.map +1 -1
  80. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  81. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js.map +1 -1
  82. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.js +2 -2
  83. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.js.map +1 -1
  84. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js +1 -1
  85. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.js.map +1 -1
  86. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.js +1 -1
  87. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.js.map +1 -1
  88. package/dist/esm/react/web/ui/PayEmbed.js +9 -1
  89. package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
  90. package/dist/esm/version.js +1 -1
  91. package/dist/esm/wallets/smart/index.js +72 -2
  92. package/dist/esm/wallets/smart/index.js.map +1 -1
  93. package/dist/esm/wallets/smart/lib/bundler.js +31 -7
  94. package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
  95. package/dist/esm/wallets/smart/lib/paymaster.js +16 -2
  96. package/dist/esm/wallets/smart/lib/paymaster.js.map +1 -1
  97. package/dist/esm/wallets/smart/lib/userop.js +4 -1
  98. package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
  99. package/dist/esm/wallets/smart/types.js +40 -1
  100. package/dist/esm/wallets/smart/types.js.map +1 -1
  101. package/dist/types/chains/utils.d.ts +4 -0
  102. package/dist/types/chains/utils.d.ts.map +1 -1
  103. package/dist/types/exports/wallets/smart.d.ts +2 -1
  104. package/dist/types/exports/wallets/smart.d.ts.map +1 -1
  105. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +3 -0
  106. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  107. package/dist/types/react/core/utils/defaultTokens.d.ts.map +1 -1
  108. package/dist/types/react/native/ui/connect/ConnectButton.d.ts.map +1 -1
  109. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  110. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  111. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  112. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
  113. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.d.ts +1 -0
  114. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.d.ts.map +1 -1
  115. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.d.ts +1 -0
  116. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.d.ts.map +1 -1
  117. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.d.ts +1 -0
  118. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.d.ts.map +1 -1
  119. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.d.ts +1 -0
  120. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.d.ts.map +1 -1
  121. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.d.ts +1 -0
  122. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.d.ts.map +1 -1
  123. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.d.ts +1 -0
  124. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.d.ts.map +1 -1
  125. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.d.ts +1 -0
  126. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.d.ts.map +1 -1
  127. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.d.ts +1 -0
  128. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.d.ts.map +1 -1
  129. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts +1 -0
  130. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.d.ts.map +1 -1
  131. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.d.ts.map +1 -1
  132. package/dist/types/react/web/ui/PayEmbed.d.ts +6 -0
  133. package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
  134. package/dist/types/version.d.ts +1 -1
  135. package/dist/types/wallets/smart/index.d.ts.map +1 -1
  136. package/dist/types/wallets/smart/lib/bundler.d.ts +20 -1
  137. package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
  138. package/dist/types/wallets/smart/lib/paymaster.d.ts +16 -2
  139. package/dist/types/wallets/smart/lib/paymaster.d.ts.map +1 -1
  140. package/dist/types/wallets/smart/lib/userop.d.ts +4 -1
  141. package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
  142. package/dist/types/wallets/smart/types.d.ts +18 -0
  143. package/dist/types/wallets/smart/types.d.ts.map +1 -1
  144. package/package.json +2 -2
  145. package/src/chains/utils.ts +9 -0
  146. package/src/exports/wallets/smart.ts +3 -0
  147. package/src/react/core/hooks/transaction/useSendTransaction.ts +3 -0
  148. package/src/react/core/utils/defaultTokens.ts +8 -0
  149. package/src/react/native/ui/connect/ConnectButton.tsx +10 -0
  150. package/src/react/web/hooks/transaction/useSendTransaction.tsx +3 -0
  151. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +10 -0
  152. package/src/react/web/ui/ConnectWallet/Details.tsx +1 -0
  153. package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +10 -0
  154. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +13 -3
  155. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatFlow.tsx +4 -0
  156. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatStatusScreen.tsx +2 -1
  157. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx +2 -1
  158. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.tsx +4 -2
  159. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.tsx +3 -0
  160. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx +2 -1
  161. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapFlow.tsx +3 -0
  162. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/SwapStatusScreen.tsx +2 -1
  163. package/src/react/web/ui/ConnectWallet/screens/Buy/tx-history/FiatDetailsScreen.tsx +1 -0
  164. package/src/react/web/ui/PayEmbed.tsx +18 -0
  165. package/src/version.ts +1 -1
  166. package/src/wallets/smart/index.ts +87 -1
  167. package/src/wallets/smart/lib/bundler.ts +47 -13
  168. package/src/wallets/smart/lib/paymaster.ts +16 -2
  169. package/src/wallets/smart/lib/userop.ts +4 -1
  170. package/src/wallets/smart/types.ts +64 -0
@@ -4,10 +4,14 @@ import {
4
4
  type TypedDataDefinition,
5
5
  type TypedDataDomain,
6
6
  hashTypedData,
7
+ maxUint96,
7
8
  } from "viem";
8
9
  import type { Chain } from "../../chains/types.js";
9
10
  import { getCachedChain } from "../../chains/utils.js";
10
11
  import { type ThirdwebContract, getContract } from "../../contract/contract.js";
12
+ import { allowance } from "../../extensions/erc20/__generated__/IERC20/read/allowance.js";
13
+ import { approve } from "../../extensions/erc20/write/approve.js";
14
+ import { toSerializableTransaction } from "../../transaction/actions/to-serializable-transaction.js";
11
15
  import type { WaitForReceiptOptions } from "../../transaction/actions/wait-for-tx-receipt.js";
12
16
  import {
13
17
  populateEip712Transaction,
@@ -15,6 +19,8 @@ import {
15
19
  } from "../../transaction/actions/zksync/send-eip712-transaction.js";
16
20
  import type { PreparedTransaction } from "../../transaction/prepare-transaction.js";
17
21
  import { getAddress } from "../../utils/address.js";
22
+ import { concatHex } from "../../utils/encoding/helpers/concat-hex.js";
23
+ import type { Hex } from "../../utils/encoding/hex.js";
18
24
  import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
19
25
  import type {
20
26
  Account,
@@ -44,9 +50,11 @@ import {
44
50
  } from "./lib/userop.js";
45
51
  import { isNativeAAChain } from "./lib/utils.js";
46
52
  import type {
53
+ PaymasterResult,
47
54
  SmartAccountOptions,
48
55
  SmartWalletConnectionOptions,
49
56
  SmartWalletOptions,
57
+ UserOperation,
50
58
  } from "./types.js";
51
59
 
52
60
  /**
@@ -170,6 +178,27 @@ async function createSmartAccount(
170
178
  const account: Account = {
171
179
  address: getAddress(accountContract.address),
172
180
  async sendTransaction(transaction: SendTransactionOption) {
181
+ // if erc20 paymaster - check allowance and approve if needed
182
+ const erc20Paymaster = options.overrides?.erc20Paymaster;
183
+ let paymasterOverride:
184
+ | undefined
185
+ | ((userOp: UserOperation) => Promise<PaymasterResult>) = undefined;
186
+ if (erc20Paymaster) {
187
+ await approveERC20({
188
+ accountContract,
189
+ erc20Paymaster,
190
+ options,
191
+ });
192
+ const paymasterCallback = async (): Promise<PaymasterResult> => {
193
+ return {
194
+ paymasterAndData: concatHex([
195
+ erc20Paymaster.address as Hex,
196
+ erc20Paymaster?.token as Hex,
197
+ ]),
198
+ };
199
+ };
200
+ paymasterOverride = options.overrides?.paymaster || paymasterCallback;
201
+ }
173
202
  const executeTx = prepareExecute({
174
203
  accountContract,
175
204
  transaction,
@@ -177,7 +206,13 @@ async function createSmartAccount(
177
206
  });
178
207
  return _sendUserOp({
179
208
  executeTx,
180
- options,
209
+ options: {
210
+ ...options,
211
+ overrides: {
212
+ ...options.overrides,
213
+ paymaster: paymasterOverride,
214
+ },
215
+ },
181
216
  });
182
217
  },
183
218
  async sendBatchTransaction(transactions: SendTransactionOption[]) {
@@ -362,6 +397,57 @@ async function createSmartAccount(
362
397
  return account;
363
398
  }
364
399
 
400
+ async function approveERC20(args: {
401
+ accountContract: ThirdwebContract;
402
+ options: SmartAccountOptions;
403
+ erc20Paymaster: {
404
+ address: string;
405
+ token: string;
406
+ };
407
+ }) {
408
+ const { accountContract, erc20Paymaster, options } = args;
409
+ const tokenAddress = erc20Paymaster.token;
410
+ const tokenContract = getContract({
411
+ address: tokenAddress,
412
+ chain: accountContract.chain,
413
+ client: accountContract.client,
414
+ });
415
+ const accountAllowance = await allowance({
416
+ contract: tokenContract,
417
+ owner: accountContract.address,
418
+ spender: erc20Paymaster.address,
419
+ });
420
+
421
+ if (accountAllowance > 0n) {
422
+ return;
423
+ }
424
+
425
+ const approveTx = approve({
426
+ contract: tokenContract,
427
+ spender: erc20Paymaster.address,
428
+ amountWei: maxUint96 - 1n,
429
+ });
430
+ const transaction = await toSerializableTransaction({
431
+ transaction: approveTx,
432
+ from: accountContract.address,
433
+ });
434
+ const executeTx = prepareExecute({
435
+ accountContract,
436
+ transaction,
437
+ executeOverride: options.overrides?.execute,
438
+ });
439
+ await _sendUserOp({
440
+ executeTx,
441
+ options: {
442
+ ...options,
443
+ overrides: {
444
+ ...options.overrides,
445
+ erc20Paymaster: undefined,
446
+ },
447
+ },
448
+ });
449
+ }
450
+
365
451
  function createZkSyncAccount(args: {
366
452
  creationOptions: SmartWalletOptions;
367
453
  connectionOptions: SmartWalletConnectionOptions;
@@ -5,12 +5,14 @@ import type { TransactionReceipt } from "../../../transaction/types.js";
5
5
  import { type Hex, hexToBigInt } from "../../../utils/encoding/hex.js";
6
6
  import { getClientFetch } from "../../../utils/fetch.js";
7
7
  import { stringify } from "../../../utils/json.js";
8
- import type {
9
- BundlerOptions,
10
- EstimationResult,
11
- GasPriceResult,
12
- PmTransactionData,
13
- UserOperation,
8
+ import {
9
+ type BundlerOptions,
10
+ type EstimationResult,
11
+ type GasPriceResult,
12
+ type PmTransactionData,
13
+ type UserOperation,
14
+ type UserOperationReceipt,
15
+ formatUserOperationReceipt,
14
16
  } from "../types.js";
15
17
  import {
16
18
  DEBUG,
@@ -136,14 +138,12 @@ export async function getUserOpReceipt(
136
138
  userOpHash: Hex;
137
139
  },
138
140
  ): Promise<TransactionReceipt | undefined> {
139
- const res = await sendBundlerRequest({
140
- options: args,
141
- operation: "eth_getUserOperationReceipt",
142
- params: [args.userOpHash],
143
- });
141
+ const res = await getUserOpReceiptRaw(args);
142
+
144
143
  if (!res) {
145
144
  return undefined;
146
145
  }
146
+
147
147
  if (res.success === false) {
148
148
  // parse revert reason
149
149
  const logs = parseEventLogs({
@@ -152,20 +152,54 @@ export async function getUserOpReceipt(
152
152
  });
153
153
  const revertReason = logs[0]?.args?.revertReason;
154
154
  if (!revertReason) {
155
- throw new Error(`UserOp failed at txHash: ${res.transactionHash}`);
155
+ throw new Error(
156
+ `UserOp failed at txHash: ${res.receipt.transactionHash}`,
157
+ );
156
158
  }
157
159
  const revertMsg = decodeErrorResult({
158
160
  data: revertReason,
159
161
  });
160
162
  throw new Error(
161
163
  `UserOp failed with reason: '${revertMsg.args.join(",")}' at txHash: ${
162
- res.transactionHash
164
+ res.receipt.transactionHash
163
165
  }`,
164
166
  );
165
167
  }
166
168
  return res.receipt;
167
169
  }
168
170
 
171
+ /**
172
+ * Get the receipt of a user operation.
173
+ * @param args - The options for getting the receipt of a user operation.
174
+ * @returns The raw receipt of the user operation.
175
+ * @example
176
+ * ```ts
177
+ * import { getUserOpReceiptRaw } from "thirdweb/wallets/smart";
178
+ *
179
+ * const receipt = await getUserOpReceiptRaw({
180
+ * client,
181
+ * chain,
182
+ * userOpHash,
183
+ * });
184
+ * ```
185
+ * @walletUtils
186
+ */
187
+ export async function getUserOpReceiptRaw(
188
+ args: BundlerOptions & {
189
+ userOpHash: Hex;
190
+ },
191
+ ): Promise<UserOperationReceipt | undefined> {
192
+ const res = await sendBundlerRequest({
193
+ options: args,
194
+ operation: "eth_getUserOperationReceipt",
195
+ params: [args.userOpHash],
196
+ });
197
+ if (!res) {
198
+ return undefined;
199
+ }
200
+ return formatUserOperationReceipt(res as UserOperationReceipt);
201
+ }
202
+
169
203
  /**
170
204
  * @internal
171
205
  */
@@ -11,8 +11,22 @@ import {
11
11
  import { hexlifyUserOp } from "./utils.js";
12
12
 
13
13
  /**
14
- * TODO Docs
15
- * @internal
14
+ * Get paymaster and data details for a user operation.
15
+ * @param args - The userOp and options
16
+ * @returns - The paymaster and data details for the user operation.
17
+ * @example
18
+ * ```ts
19
+ * import { getPaymasterAndData } from "thirdweb/wallets/smart";
20
+ *
21
+ * const userOp = createUnsignedUserOp(...);
22
+ *
23
+ * const paymasterAndData = await getPaymasterAndData({
24
+ * userOp,
25
+ * client,
26
+ * chain,
27
+ * });
28
+ * ```
29
+ * @walletUtils
16
30
  */
17
31
  export async function getPaymasterAndData(args: {
18
32
  userOp: UserOperation;
@@ -81,7 +81,9 @@ export async function waitForUserOpReceipt(
81
81
  *
82
82
  * const userOp = await createUnsignedUserOp({
83
83
  * transaction,
84
+ * factoryContract,
84
85
  * accountContract,
86
+ * adminAddress,
85
87
  * sponsorGas,
86
88
  * overrides,
87
89
  * });
@@ -246,7 +248,8 @@ export async function createUnsignedUserOp(args: {
246
248
  *
247
249
  * const signedUserOp = await signUserOp({
248
250
  * userOp,
249
- * options,
251
+ * chain,
252
+ * adminAccount,
250
253
  * });
251
254
  * ```
252
255
  * @walletUtils
@@ -3,6 +3,7 @@ import type { Chain } from "../../chains/types.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import type { ThirdwebContract } from "../../contract/contract.js";
5
5
  import type { PreparedTransaction } from "../../transaction/prepare-transaction.js";
6
+ import type { TransactionReceipt } from "../../transaction/types.js";
6
7
  import type { Hex } from "../../utils/encoding/hex.js";
7
8
  import type { Prettify } from "../../utils/type-utils.js";
8
9
  import type { Account, SendTransactionOption } from "../interfaces/wallet.js";
@@ -16,6 +17,10 @@ export type SmartWalletOptions = Prettify<
16
17
  accountAddress?: string;
17
18
  accountSalt?: string;
18
19
  entrypointAddress?: string;
20
+ erc20Paymaster?: {
21
+ address: string;
22
+ token: string;
23
+ };
19
24
  paymaster?: (userOp: UserOperation) => Promise<PaymasterResult>;
20
25
  predictAddress?: (factoryContract: ThirdwebContract) => Promise<string>;
21
26
  createAccount?: (
@@ -119,3 +124,62 @@ export type PmTransactionData = {
119
124
  paymaster: Address;
120
125
  paymasterInput: Hex;
121
126
  };
127
+
128
+ export type UserOperationReceipt = {
129
+ receipt: TransactionReceipt;
130
+ logs: TransactionReceipt["logs"];
131
+ userOpHash: Hex;
132
+ entryPoint: Address;
133
+ sender: Address;
134
+ nonce: bigint;
135
+ paymaster: Address;
136
+ actualGasUsed: bigint;
137
+ actualGasCost: bigint;
138
+ success: boolean;
139
+ };
140
+
141
+ export function formatUserOperationReceipt(
142
+ userOpReceiptRaw: UserOperationReceipt,
143
+ ) {
144
+ const { receipt: transactionReceipt } = userOpReceiptRaw;
145
+
146
+ const receipt = {
147
+ ...transactionReceipt,
148
+ transactionHash: transactionReceipt.transactionHash,
149
+ blockNumber: transactionReceipt.blockNumber
150
+ ? BigInt(transactionReceipt.blockNumber)
151
+ : null,
152
+ contractAddress: transactionReceipt.contractAddress
153
+ ? transactionReceipt.contractAddress
154
+ : null,
155
+ cumulativeGasUsed: transactionReceipt.cumulativeGasUsed
156
+ ? BigInt(transactionReceipt.cumulativeGasUsed)
157
+ : null,
158
+ effectiveGasPrice: transactionReceipt.effectiveGasPrice
159
+ ? BigInt(transactionReceipt.effectiveGasPrice)
160
+ : null,
161
+ gasUsed: transactionReceipt.gasUsed
162
+ ? BigInt(transactionReceipt.gasUsed)
163
+ : null,
164
+ logs: transactionReceipt.logs,
165
+ to: transactionReceipt.to ? transactionReceipt.to : null,
166
+ transactionIndex: transactionReceipt.transactionIndex,
167
+ status: transactionReceipt.status,
168
+ type: transactionReceipt.type,
169
+ } as TransactionReceipt;
170
+
171
+ if (transactionReceipt.blobGasPrice)
172
+ receipt.blobGasPrice = BigInt(transactionReceipt.blobGasPrice);
173
+ if (transactionReceipt.blobGasUsed)
174
+ receipt.blobGasUsed = BigInt(transactionReceipt.blobGasUsed);
175
+
176
+ const userOpReceipt = {
177
+ ...userOpReceiptRaw,
178
+ receipt,
179
+ userOpHash: userOpReceiptRaw.userOpHash,
180
+ actualGasCost: BigInt(userOpReceiptRaw.actualGasCost),
181
+ actualGasUsed: BigInt(userOpReceiptRaw.actualGasUsed),
182
+ nonce: BigInt(userOpReceiptRaw.nonce),
183
+ } as UserOperationReceipt;
184
+ return userOpReceipt;
185
+ }