thirdweb 5.98.2 → 5.99.0

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 (148) hide show
  1. package/dist/cjs/exports/react.js +11 -8
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/exports/react.native.js +11 -8
  4. package/dist/cjs/exports/react.native.js.map +1 -1
  5. package/dist/cjs/exports/wallets/eip5792.js +7 -3
  6. package/dist/cjs/exports/wallets/eip5792.js.map +1 -1
  7. package/dist/cjs/react/core/hooks/wallets/useCapabilities.js +5 -6
  8. package/dist/cjs/react/core/hooks/wallets/useCapabilities.js.map +1 -1
  9. package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js +99 -0
  10. package/dist/cjs/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
  11. package/dist/cjs/react/core/hooks/wallets/useSendCalls.js +32 -40
  12. package/dist/cjs/react/core/hooks/wallets/useSendCalls.js.map +1 -1
  13. package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js +38 -0
  14. package/dist/cjs/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
  15. package/dist/cjs/react/core/providers/thirdweb-provider.js +4 -3
  16. package/dist/cjs/react/core/providers/thirdweb-provider.js.map +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/wallets/coinbase/coinbase-web.js +2 -85
  19. package/dist/cjs/wallets/coinbase/coinbase-web.js.map +1 -1
  20. package/dist/cjs/wallets/eip5792/get-calls-status.js +54 -15
  21. package/dist/cjs/wallets/eip5792/get-calls-status.js.map +1 -1
  22. package/dist/cjs/wallets/eip5792/get-capabilities.js +21 -8
  23. package/dist/cjs/wallets/eip5792/get-capabilities.js.map +1 -1
  24. package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js +41 -0
  25. package/dist/cjs/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
  26. package/dist/cjs/wallets/eip5792/send-calls.js +27 -14
  27. package/dist/cjs/wallets/eip5792/send-calls.js.map +1 -1
  28. package/dist/cjs/wallets/eip5792/show-calls-status.js +8 -7
  29. package/dist/cjs/wallets/eip5792/show-calls-status.js.map +1 -1
  30. package/dist/cjs/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +23 -10
  31. package/dist/cjs/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
  32. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
  33. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
  34. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
  35. package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
  36. package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
  37. package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
  38. package/dist/esm/exports/react.js +5 -3
  39. package/dist/esm/exports/react.js.map +1 -1
  40. package/dist/esm/exports/react.native.js +5 -3
  41. package/dist/esm/exports/react.native.js.map +1 -1
  42. package/dist/esm/exports/wallets/eip5792.js +3 -1
  43. package/dist/esm/exports/wallets/eip5792.js.map +1 -1
  44. package/dist/esm/react/core/hooks/wallets/useCapabilities.js +5 -6
  45. package/dist/esm/react/core/hooks/wallets/useCapabilities.js.map +1 -1
  46. package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js +96 -0
  47. package/dist/esm/react/core/hooks/wallets/useSendAndConfirmCalls.js.map +1 -0
  48. package/dist/esm/react/core/hooks/wallets/useSendCalls.js +32 -40
  49. package/dist/esm/react/core/hooks/wallets/useSendCalls.js.map +1 -1
  50. package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js +35 -0
  51. package/dist/esm/react/core/hooks/wallets/useWaitForCallsReceipt.js.map +1 -0
  52. package/dist/esm/react/core/providers/thirdweb-provider.js +4 -3
  53. package/dist/esm/react/core/providers/thirdweb-provider.js.map +1 -1
  54. package/dist/esm/version.js +1 -1
  55. package/dist/esm/wallets/coinbase/coinbase-web.js +2 -81
  56. package/dist/esm/wallets/coinbase/coinbase-web.js.map +1 -1
  57. package/dist/esm/wallets/eip5792/get-calls-status.js +54 -15
  58. package/dist/esm/wallets/eip5792/get-calls-status.js.map +1 -1
  59. package/dist/esm/wallets/eip5792/get-capabilities.js +22 -9
  60. package/dist/esm/wallets/eip5792/get-capabilities.js.map +1 -1
  61. package/dist/esm/wallets/eip5792/send-and-confirm-calls.js +38 -0
  62. package/dist/esm/wallets/eip5792/send-and-confirm-calls.js.map +1 -0
  63. package/dist/esm/wallets/eip5792/send-calls.js +28 -15
  64. package/dist/esm/wallets/eip5792/send-calls.js.map +1 -1
  65. package/dist/esm/wallets/eip5792/show-calls-status.js +9 -8
  66. package/dist/esm/wallets/eip5792/show-calls-status.js.map +1 -1
  67. package/dist/esm/wallets/eip5792/{wait-for-bundle.js → wait-for-calls-receipt.js} +22 -9
  68. package/dist/esm/wallets/eip5792/wait-for-calls-receipt.js.map +1 -0
  69. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js +15 -10
  70. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +1 -1
  71. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +13 -3
  72. package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +1 -1
  73. package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js +4 -2
  74. package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js.map +1 -1
  75. package/dist/types/exports/react.d.ts +4 -3
  76. package/dist/types/exports/react.d.ts.map +1 -1
  77. package/dist/types/exports/react.native.d.ts +4 -3
  78. package/dist/types/exports/react.native.d.ts.map +1 -1
  79. package/dist/types/exports/wallets/eip5792.d.ts +3 -1
  80. package/dist/types/exports/wallets/eip5792.d.ts.map +1 -1
  81. package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts +1 -0
  82. package/dist/types/react/core/hooks/wallets/useCapabilities.d.ts.map +1 -1
  83. package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts +66 -0
  84. package/dist/types/react/core/hooks/wallets/useSendAndConfirmCalls.d.ts.map +1 -0
  85. package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts +8 -11
  86. package/dist/types/react/core/hooks/wallets/useSendCalls.d.ts.map +1 -1
  87. package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts +32 -0
  88. package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts.map +1 -0
  89. package/dist/types/react/core/providers/thirdweb-provider.d.ts.map +1 -1
  90. package/dist/types/version.d.ts +1 -1
  91. package/dist/types/wallets/coinbase/coinbase-web.d.ts +2 -30
  92. package/dist/types/wallets/coinbase/coinbase-web.d.ts.map +1 -1
  93. package/dist/types/wallets/eip5792/get-calls-status.d.ts +5 -6
  94. package/dist/types/wallets/eip5792/get-calls-status.d.ts.map +1 -1
  95. package/dist/types/wallets/eip5792/get-capabilities.d.ts +2 -1
  96. package/dist/types/wallets/eip5792/get-capabilities.d.ts.map +1 -1
  97. package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts +39 -0
  98. package/dist/types/wallets/eip5792/send-and-confirm-calls.d.ts.map +1 -0
  99. package/dist/types/wallets/eip5792/send-calls.d.ts +12 -5
  100. package/dist/types/wallets/eip5792/send-calls.d.ts.map +1 -1
  101. package/dist/types/wallets/eip5792/show-calls-status.d.ts +2 -2
  102. package/dist/types/wallets/eip5792/show-calls-status.d.ts.map +1 -1
  103. package/dist/types/wallets/eip5792/types.d.ts +33 -4
  104. package/dist/types/wallets/eip5792/types.d.ts.map +1 -1
  105. package/dist/types/wallets/eip5792/{wait-for-bundle.d.ts → wait-for-calls-receipt.d.ts} +21 -9
  106. package/dist/types/wallets/eip5792/wait-for-calls-receipt.d.ts.map +1 -0
  107. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts +3 -3
  108. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts.map +1 -1
  109. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts +3 -3
  110. package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts.map +1 -1
  111. package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts +2 -2
  112. package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts.map +1 -1
  113. package/package.json +1 -1
  114. package/src/exports/react.native.ts +6 -3
  115. package/src/exports/react.ts +6 -3
  116. package/src/exports/wallets/eip5792.ts +5 -3
  117. package/src/react/core/hooks/wallets/useCapabilities.ts +6 -6
  118. package/src/react/core/hooks/wallets/useSendAndConfirmCalls.ts +114 -0
  119. package/src/react/core/hooks/wallets/useSendCalls.ts +33 -50
  120. package/src/react/core/hooks/wallets/useWaitForCallsReceipt.ts +43 -0
  121. package/src/react/core/providers/thirdweb-provider.tsx +4 -3
  122. package/src/version.ts +1 -1
  123. package/src/wallets/coinbase/coinbase-web.ts +6 -117
  124. package/src/wallets/eip5792/get-calls-status.test.ts +27 -33
  125. package/src/wallets/eip5792/get-calls-status.ts +68 -19
  126. package/src/wallets/eip5792/get-capabilities.test.ts +10 -10
  127. package/src/wallets/eip5792/get-capabilities.ts +33 -11
  128. package/src/wallets/eip5792/send-and-confirm-calls.ts +48 -0
  129. package/src/wallets/eip5792/send-calls.test.ts +7 -7
  130. package/src/wallets/eip5792/send-calls.ts +43 -21
  131. package/src/wallets/eip5792/show-calls-status.test.ts +3 -3
  132. package/src/wallets/eip5792/show-calls-status.ts +13 -12
  133. package/src/wallets/eip5792/types.ts +43 -4
  134. package/src/wallets/eip5792/{wait-for-bundle.test.ts → wait-for-calls-receipt.test.ts} +19 -9
  135. package/src/wallets/eip5792/{wait-for-bundle.ts → wait-for-calls-receipt.ts} +26 -16
  136. package/src/wallets/in-app/core/eip5972/in-app-wallet-calls.ts +17 -16
  137. package/src/wallets/in-app/core/eip5972/in-app-wallet-capabilities.ts +14 -3
  138. package/src/wallets/smart/lib/smart-wallet-capabilities.ts +5 -2
  139. package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js +0 -41
  140. package/dist/cjs/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
  141. package/dist/cjs/wallets/eip5792/wait-for-bundle.js.map +0 -1
  142. package/dist/esm/react/core/hooks/wallets/useCallsStatus.js +0 -38
  143. package/dist/esm/react/core/hooks/wallets/useCallsStatus.js.map +0 -1
  144. package/dist/esm/wallets/eip5792/wait-for-bundle.js.map +0 -1
  145. package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts +0 -26
  146. package/dist/types/react/core/hooks/wallets/useCallsStatus.d.ts.map +0 -1
  147. package/dist/types/wallets/eip5792/wait-for-bundle.d.ts.map +0 -1
  148. package/src/react/core/hooks/wallets/useCallsStatus.ts +0 -48
@@ -1,8 +1,12 @@
1
1
  import { getAddress } from "../../utils/address.js";
2
2
  import type { Prettify } from "../../utils/type-utils.js";
3
- import { isCoinbaseSDKWallet } from "../coinbase/coinbase-web.js";
3
+ import {
4
+ type CoinbaseWalletCreationOptions,
5
+ isCoinbaseSDKWallet,
6
+ } from "../coinbase/coinbase-web.js";
4
7
  import { isInAppWallet } from "../in-app/core/wallet/index.js";
5
8
  import { getInjectedProvider } from "../injected/index.js";
9
+ import type { Ethereum } from "../interfaces/ethereum.js";
6
10
  import type { Wallet } from "../interfaces/wallet.js";
7
11
  import { isWalletConnect } from "../wallet-connect/controller.js";
8
12
  import type { WalletId } from "../wallet-types.js";
@@ -10,6 +14,7 @@ import type { WalletCapabilities, WalletCapabilitiesRecord } from "./types.js";
10
14
 
11
15
  export type GetCapabilitiesOptions<ID extends WalletId = WalletId> = {
12
16
  wallet: Wallet<ID>;
17
+ chainId?: number;
13
18
  };
14
19
 
15
20
  export type GetCapabilitiesResult = Prettify<
@@ -38,6 +43,7 @@ export type GetCapabilitiesResult = Prettify<
38
43
  */
39
44
  export async function getCapabilities<const ID extends WalletId = WalletId>({
40
45
  wallet,
46
+ chainId,
41
47
  }: GetCapabilitiesOptions<ID>): Promise<GetCapabilitiesResult> {
42
48
  const account = wallet.getAccount();
43
49
  if (!account) {
@@ -60,13 +66,6 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
60
66
  return inAppWalletGetCapabilities({ wallet });
61
67
  }
62
68
 
63
- if (isCoinbaseSDKWallet(wallet)) {
64
- const { coinbaseSDKWalletGetCapabilities } = await import(
65
- "../coinbase/coinbase-web.js"
66
- );
67
- return coinbaseSDKWalletGetCapabilities({ wallet });
68
- }
69
-
70
69
  // TODO: Add Wallet Connect support
71
70
  if (isWalletConnect(wallet)) {
72
71
  return {
@@ -74,14 +73,37 @@ export async function getCapabilities<const ID extends WalletId = WalletId>({
74
73
  };
75
74
  }
76
75
 
77
- // Default to injected wallet
78
- const provider = getInjectedProvider(wallet.id);
76
+ let provider: Ethereum;
77
+ if (isCoinbaseSDKWallet(wallet)) {
78
+ const { getCoinbaseWebProvider } = await import(
79
+ "../coinbase/coinbase-web.js"
80
+ );
81
+ const config = wallet.getConfig() as CoinbaseWalletCreationOptions;
82
+ provider = (await getCoinbaseWebProvider(config)) as Ethereum;
83
+ } else {
84
+ provider = getInjectedProvider(wallet.id);
85
+ }
79
86
 
80
87
  try {
81
- return await provider.request({
88
+ const result = await provider.request({
82
89
  method: "wallet_getCapabilities",
83
90
  params: [getAddress(account.address)],
84
91
  });
92
+ const capabilities = {} as WalletCapabilitiesRecord<
93
+ WalletCapabilities,
94
+ number
95
+ >;
96
+ for (const [chainId, capabilities_] of Object.entries(result)) {
97
+ capabilities[Number(chainId)] = {};
98
+ const capabilitiesCopy = {} as WalletCapabilities;
99
+ for (const [key, value] of Object.entries(capabilities_)) {
100
+ capabilitiesCopy[key] = value;
101
+ }
102
+ capabilities[Number(chainId)] = capabilitiesCopy;
103
+ }
104
+ return (
105
+ typeof chainId === "number" ? capabilities[chainId] : capabilities
106
+ ) as never;
85
107
  } catch (error: unknown) {
86
108
  if (/unsupport|not support|not available/i.test((error as Error).message)) {
87
109
  return {
@@ -0,0 +1,48 @@
1
+ import type { WalletId } from "../wallet-types.js";
2
+ import { type SendCallsOptions, sendCalls } from "./send-calls.js";
3
+ import type { GetCallsStatusResponse } from "./types.js";
4
+ import { waitForCallsReceipt } from "./wait-for-calls-receipt.js";
5
+
6
+ /**
7
+ * Send and confirm calls in a single transaction.
8
+ *
9
+ * This is a convenience function that sends the calls with `sendCalls` and then waits for the receipts with `waitForCallsReceipt`.
10
+ *
11
+ * @param options - The options for sending and confirming calls.
12
+ * @returns The receipts of the calls.
13
+ * @example
14
+ * ```ts
15
+ * const call1 = approve({
16
+ * contract: USDT_CONTRACT,
17
+ * amount: 100,
18
+ * spender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
19
+ * });
20
+ * const call2 = transfer({
21
+ * contract: USDT_CONTRACT,
22
+ * to: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
23
+ * amount: 100,
24
+ * });
25
+ * const result = await sendAndConfirmCalls({
26
+ * calls: [call1, call2],
27
+ * wallet: wallet,
28
+ * });
29
+ * console.log("Transaction receipts:", result.receipts);
30
+ * ```
31
+ * @extension EIP5792
32
+ * @beta
33
+ */
34
+ export async function sendAndConfirmCalls<const ID extends WalletId>(
35
+ options: SendCallsOptions<ID> & {
36
+ /**
37
+ * The maximum number of blocks to wait for the calls to be confirmed.
38
+ * @defaultValue 100
39
+ */
40
+ maxBlocksWaitTime?: number;
41
+ },
42
+ ): Promise<GetCallsStatusResponse> {
43
+ const sendCallsResult = await sendCalls(options);
44
+ return waitForCallsReceipt({
45
+ ...sendCallsResult,
46
+ maxBlocksWaitTime: options.maxBlocksWaitTime,
47
+ });
48
+ }
@@ -111,7 +111,7 @@ describe.sequential("injected wallet", () => {
111
111
 
112
112
  const result = await sendCalls({ wallet, ...SEND_CALLS_OPTIONS });
113
113
 
114
- expect(result).toEqual("0x123456");
114
+ expect(result.id).toEqual("0x123456");
115
115
  expect(mocks.injectedRequest).toHaveBeenCalledWith({
116
116
  method: "wallet_sendCalls",
117
117
  params: [
@@ -132,7 +132,7 @@ describe.sequential("injected wallet", () => {
132
132
  capabilities: undefined,
133
133
  chainId: numberToHex(ANVIL_CHAIN.id),
134
134
  from: TEST_ACCOUNT_A.address,
135
- version: "1.0",
135
+ version: "2.0.0",
136
136
  },
137
137
  ],
138
138
  });
@@ -159,7 +159,7 @@ describe.sequential("injected wallet", () => {
159
159
  calls: [preparedTx, preparedTx2],
160
160
  });
161
161
 
162
- expect(result).toEqual("0x123456");
162
+ expect(result.id).toEqual("0x123456");
163
163
  expect(mocks.injectedRequest).toHaveBeenCalledWith({
164
164
  method: "wallet_sendCalls",
165
165
  params: [
@@ -180,7 +180,7 @@ describe.sequential("injected wallet", () => {
180
180
  capabilities: undefined,
181
181
  chainId: numberToHex(ANVIL_CHAIN.id),
182
182
  from: TEST_ACCOUNT_A.address,
183
- version: "1.0",
183
+ version: "2.0.0",
184
184
  },
185
185
  ],
186
186
  });
@@ -194,7 +194,7 @@ describe.sequential("injected wallet", () => {
194
194
  ...SEND_CALLS_OPTIONS,
195
195
  });
196
196
 
197
- expect(result).toEqual("0x123456");
197
+ expect(result.id).toEqual("0x123456");
198
198
  expect(mocks.injectedRequest).toHaveBeenCalledWith({
199
199
  method: "wallet_sendCalls",
200
200
  params: [
@@ -215,7 +215,7 @@ describe.sequential("injected wallet", () => {
215
215
  capabilities: undefined,
216
216
  chainId: numberToHex(sepolia.id),
217
217
  from: TEST_ACCOUNT_A.address,
218
- version: "1.0",
218
+ version: "2.0.0",
219
219
  },
220
220
  ],
221
221
  });
@@ -231,7 +231,7 @@ describe.sequential("injected wallet", () => {
231
231
  });
232
232
 
233
233
  await expect(promise).rejects.toMatchInlineSnapshot(
234
- "[Error: io.metamask does not support wallet_sendCalls, reach out to them directly to request EIP-5792 support.]",
234
+ `[Error: io.metamask errored calling wallet_sendCalls, with error: {"code":-32601,"message":"some nonsense the wallet sends us about not supporting"}]`,
235
235
  );
236
236
  });
237
237
  });
@@ -6,14 +6,19 @@ import { encode } from "../../transaction/actions/encode.js";
6
6
  import type { PreparedTransaction } from "../../transaction/prepare-transaction.js";
7
7
  import { type Address, getAddress } from "../../utils/address.js";
8
8
  import { type Hex, numberToHex } from "../../utils/encoding/hex.js";
9
+ import { stringify } from "../../utils/json.js";
9
10
  import {
10
11
  type PromisedObject,
11
12
  resolvePromisedValue,
12
13
  } from "../../utils/promise/resolve-promised-value.js";
13
- import type { OneOf } from "../../utils/type-utils.js";
14
- import { isCoinbaseSDKWallet } from "../coinbase/coinbase-web.js";
14
+ import type { OneOf, Prettify } from "../../utils/type-utils.js";
15
+ import {
16
+ type CoinbaseWalletCreationOptions,
17
+ isCoinbaseSDKWallet,
18
+ } from "../coinbase/coinbase-web.js";
15
19
  import { isInAppWallet } from "../in-app/core/wallet/index.js";
16
20
  import { getInjectedProvider } from "../injected/index.js";
21
+ import type { Ethereum } from "../interfaces/ethereum.js";
17
22
  import type { Wallet } from "../interfaces/wallet.js";
18
23
  import { isSmartWallet } from "../smart/index.js";
19
24
  import { isWalletConnect } from "../wallet-connect/controller.js";
@@ -44,16 +49,21 @@ export type SendCallsOptions<
44
49
  ID extends WalletId = WalletId,
45
50
  abi extends Abi = [],
46
51
  abiFunction extends AbiFunction = AbiFunction,
47
- > = {
52
+ > = Prettify<{
48
53
  wallet: Wallet<ID>;
49
54
  calls: PreparedSendCall<abi, abiFunction>[];
50
55
  capabilities?: WalletSendCallsParameters[number]["capabilities"];
51
56
  version?: WalletSendCallsParameters[number]["version"];
52
57
  chain?: Chain;
53
58
  atomicRequired?: boolean;
54
- };
59
+ }>;
55
60
 
56
- export type SendCallsResult = WalletSendCallsId;
61
+ export type SendCallsResult = Prettify<{
62
+ id: WalletSendCallsId;
63
+ client: ThirdwebClient;
64
+ chain: Chain;
65
+ wallet: Wallet;
66
+ }>;
57
67
 
58
68
  /**
59
69
  * Send [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) calls to a wallet.
@@ -81,6 +91,7 @@ export type SendCallsResult = WalletSendCallsId;
81
91
  *
82
92
  * const client = createThirdwebClient({ clientId: ... });
83
93
  * const wallet = createWallet("com.coinbase.wallet");
94
+ * await wallet.connect({ client });
84
95
  *
85
96
  * const sendTx1 = approve({
86
97
  contract: USDT_CONTRACT,
@@ -110,8 +121,9 @@ export type SendCallsResult = WalletSendCallsId;
110
121
  * }
111
122
  * }
112
123
  * });
113
- * We recommend proxying any paymaster calls via an API route you setup and control.
114
124
  * ```
125
+ * We recommend proxying any paymaster calls via an API route you setup and control.
126
+ *
115
127
  * @extension EIP5792
116
128
  */
117
129
  export async function sendCalls<const ID extends WalletId>(
@@ -121,7 +133,7 @@ export async function sendCalls<const ID extends WalletId>(
121
133
  wallet,
122
134
  calls,
123
135
  capabilities,
124
- version = "1.0",
136
+ version = "2.0.0",
125
137
  chain = wallet.getChain(),
126
138
  } = options;
127
139
 
@@ -138,12 +150,19 @@ export async function sendCalls<const ID extends WalletId>(
138
150
  );
139
151
  }
140
152
 
153
+ const firstCall = options.calls[0];
154
+ if (!firstCall) {
155
+ throw new Error("No calls to send");
156
+ }
157
+ const client = firstCall.client;
158
+
141
159
  // These conveniently operate the same
142
160
  if (isSmartWallet(wallet) || isInAppWallet(wallet)) {
143
161
  const { inAppWalletSendCalls } = await import(
144
162
  "../in-app/core/eip5972/in-app-wallet-calls.js"
145
163
  );
146
- return inAppWalletSendCalls({ account, calls });
164
+ const id = await inAppWalletSendCalls({ account, calls });
165
+ return { id, client, chain, wallet };
147
166
  }
148
167
 
149
168
  const preparedCalls: EIP5792Call[] = await Promise.all(
@@ -182,31 +201,34 @@ export async function sendCalls<const ID extends WalletId>(
182
201
  },
183
202
  ];
184
203
 
204
+ if (isWalletConnect(wallet)) {
205
+ throw new Error("sendCalls is not yet supported for Wallet Connect");
206
+ }
207
+
208
+ let provider: Ethereum;
185
209
  if (isCoinbaseSDKWallet(wallet)) {
186
- const { coinbaseSDKWalletSendCalls } = await import(
210
+ const { getCoinbaseWebProvider } = await import(
187
211
  "../coinbase/coinbase-web.js"
188
212
  );
189
- return coinbaseSDKWalletSendCalls({
190
- wallet,
191
- params: injectedWalletCallParams,
192
- });
193
- }
194
-
195
- if (isWalletConnect(wallet)) {
196
- throw new Error("sendCalls is not yet supported for Wallet Connect");
213
+ const config = wallet.getConfig() as CoinbaseWalletCreationOptions;
214
+ provider = (await getCoinbaseWebProvider(config)) as Ethereum;
215
+ } else {
216
+ provider = getInjectedProvider(wallet.id);
197
217
  }
198
218
 
199
- // Default to injected wallet
200
- const provider = getInjectedProvider(wallet.id);
201
219
  try {
202
- return await provider.request({
220
+ const callId = await provider.request({
203
221
  method: "wallet_sendCalls",
204
222
  params: injectedWalletCallParams as ViemWalletSendCallsParameters, // The viem type definition is slightly different
205
223
  });
224
+ if (typeof callId === "object" && "id" in callId) {
225
+ return { id: callId.id, client, chain, wallet };
226
+ }
227
+ return { id: callId, client, chain, wallet };
206
228
  } catch (error) {
207
229
  if (/unsupport|not support/i.test((error as Error).message)) {
208
230
  throw new Error(
209
- `${wallet.id} does not support wallet_sendCalls, reach out to them directly to request EIP-5792 support.`,
231
+ `${wallet.id} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`,
210
232
  );
211
233
  }
212
234
  throw error;
@@ -26,7 +26,7 @@ describe.sequential("injected wallet", async () => {
26
26
  const wallet: Wallet<typeof METAMASK> = createWallet(METAMASK);
27
27
 
28
28
  test("should run", async () => {
29
- await showCallsStatus({ wallet, bundleId: "test" });
29
+ await showCallsStatus({ wallet, id: "test" });
30
30
 
31
31
  expect(mocks.injectedRequest).toHaveBeenCalledWith({
32
32
  method: "wallet_showCallsStatus",
@@ -38,7 +38,7 @@ describe.sequential("injected wallet", async () => {
38
38
  mocks.injectedRequest.mockRejectedValue(RAW_UNSUPPORTED_ERROR);
39
39
  const promise = showCallsStatus({
40
40
  wallet: wallet as Wallet<InjectedSupportedWalletIds>,
41
- bundleId: "test",
41
+ id: "test",
42
42
  });
43
43
 
44
44
  await expect(promise).rejects.toMatchInlineSnapshot(
@@ -53,7 +53,7 @@ describe.sequential("other wallets", async () => {
53
53
  test("do not support", async () => {
54
54
  const promise = showCallsStatus({
55
55
  wallet: wallet as Wallet<InjectedSupportedWalletIds>,
56
- bundleId: "test",
56
+ id: "test",
57
57
  });
58
58
 
59
59
  await expect(promise).rejects.toMatchInlineSnapshot(
@@ -1,6 +1,10 @@
1
- import { isCoinbaseSDKWallet } from "../coinbase/coinbase-web.js";
1
+ import {
2
+ getCoinbaseWebProvider,
3
+ isCoinbaseSDKWallet,
4
+ } from "../coinbase/coinbase-web.js";
2
5
  import { isInAppWallet } from "../in-app/core/wallet/index.js";
3
6
  import { getInjectedProvider } from "../injected/index.js";
7
+ import type { Ethereum } from "../interfaces/ethereum.js";
4
8
  import type { Wallet } from "../interfaces/wallet.js";
5
9
  import { isSmartWallet } from "../smart/index.js";
6
10
  import { isWalletConnect } from "../wallet-connect/controller.js";
@@ -8,7 +12,7 @@ import type { WalletSendCallsId } from "./types.js";
8
12
 
9
13
  type ShowCallsStatusOptions = {
10
14
  wallet: Wallet;
11
- bundleId: WalletSendCallsId;
15
+ id: WalletSendCallsId;
12
16
  };
13
17
 
14
18
  /**
@@ -37,7 +41,7 @@ type ShowCallsStatusOptions = {
37
41
  */
38
42
  export async function showCallsStatus({
39
43
  wallet,
40
- bundleId,
44
+ id,
41
45
  }: ShowCallsStatusOptions): Promise<void> {
42
46
  if (
43
47
  isSmartWallet(wallet) ||
@@ -49,21 +53,18 @@ export async function showCallsStatus({
49
53
  );
50
54
  }
51
55
 
56
+ let provider: Ethereum;
52
57
  if (isCoinbaseSDKWallet(wallet)) {
53
- const { coinbaseSDKWalletShowCallsStatus } = await import(
54
- "../coinbase/coinbase-web.js"
55
- );
56
- await coinbaseSDKWalletShowCallsStatus({ wallet, bundleId });
57
- return;
58
+ provider = (await getCoinbaseWebProvider(wallet.getConfig())) as Ethereum;
59
+ } else {
60
+ // Default to injected wallet
61
+ provider = getInjectedProvider(wallet.id);
58
62
  }
59
63
 
60
- // Default to injected wallet
61
- const provider = getInjectedProvider(wallet.id);
62
-
63
64
  try {
64
65
  return await provider.request({
65
66
  method: "wallet_showCallsStatus",
66
- params: [bundleId],
67
+ params: [id],
67
68
  });
68
69
  } catch (error: unknown) {
69
70
  if (/unsupport|not support/i.test((error as Error).message)) {
@@ -1,6 +1,6 @@
1
1
  import type { Address } from "../../utils/address.js";
2
2
  import type { Hex } from "../../utils/encoding/hex.js";
3
- import type { OneOf } from "../../utils/type-utils.js";
3
+ import type { OneOf, Prettify } from "../../utils/type-utils.js";
4
4
 
5
5
  export type WalletCapabilities = {
6
6
  [capability: string]: unknown;
@@ -42,9 +42,48 @@ export type EIP5792Call = OneOf<
42
42
  }
43
43
  >;
44
44
 
45
- export type GetCallsStatusResponse = {
46
- status: "PENDING" | "CONFIRMED";
47
- receipts: WalletCallReceipt<bigint, "success" | "reverted">[];
45
+ type WalletGetCallsStatusReturnType<
46
+ numberType = Hex,
47
+ bigintType = Hex,
48
+ receiptStatus = Hex,
49
+ > = Prettify<{
50
+ atomic: boolean;
51
+ chainId: numberType;
52
+ id: string;
53
+ receipts?: WalletCallReceipt<bigintType, receiptStatus>[] | undefined;
54
+ status: number;
55
+ version: string;
56
+ }>;
57
+
58
+ export type GetCallsStatusResponse = Prettify<
59
+ Omit<
60
+ WalletGetCallsStatusReturnType<number, bigint, "success" | "reverted">,
61
+ "status"
62
+ > & {
63
+ statusCode: number;
64
+ status: "pending" | "success" | "failure" | undefined;
65
+ }
66
+ >;
67
+
68
+ export type GetCallsStatusRawResponse = {
69
+ version: string;
70
+ id: `0x${string}`;
71
+ chainId: `0x${string}`;
72
+ status: number; // See "Status Codes"
73
+ atomic: boolean;
74
+ receipts?: {
75
+ logs: {
76
+ address: `0x${string}`;
77
+ data: `0x${string}`;
78
+ topics: `0x${string}`[];
79
+ }[];
80
+ status: `0x${string}`; // Hex 1 or 0 for success or failure, respectively
81
+ blockHash: `0x${string}`;
82
+ blockNumber: `0x${string}`;
83
+ gasUsed: `0x${string}`;
84
+ transactionHash: `0x${string}`;
85
+ }[];
86
+ capabilities?: Record<string, unknown>;
48
87
  };
49
88
 
50
89
  export type WalletCallReceipt<quantity = Hex, status = Hex> = {
@@ -3,16 +3,16 @@ import { ANVIL_CHAIN } from "../../../test/src/chains.js";
3
3
  import { TEST_CLIENT } from "../../../test/src/test-clients.js";
4
4
  import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
5
5
  import * as watchBlockNumberExports from "../../rpc/watchBlockNumber.js";
6
- import * as getCallsStatusExports from "../../wallets/eip5792/get-calls-status.js";
7
6
  import { METAMASK } from "../constants.js";
8
7
  import { createWallet } from "../create-wallet.js";
8
+ import * as getCallsStatusExports from "./get-calls-status.js";
9
9
  import type { GetCallsStatusResponse } from "./types.js";
10
- import { waitForBundle } from "./wait-for-bundle.js";
10
+ import { waitForCallsReceipt } from "./wait-for-calls-receipt.js";
11
11
 
12
- const MOCK_BUNDLE_ID = "0x1234567890abcdef";
12
+ const MOCK_CALL_ID = "0x1234567890abcdef";
13
13
 
14
14
  const MOCK_SUCCESS_RECEIPT: GetCallsStatusResponse = {
15
- status: "CONFIRMED",
15
+ status: "success",
16
16
  receipts: [
17
17
  {
18
18
  logs: [],
@@ -25,11 +25,21 @@ const MOCK_SUCCESS_RECEIPT: GetCallsStatusResponse = {
25
25
  gasUsed: 12345n,
26
26
  },
27
27
  ],
28
+ atomic: false,
29
+ chainId: 1,
30
+ id: MOCK_CALL_ID,
31
+ version: "2.0.0",
32
+ statusCode: 200,
28
33
  };
29
34
 
30
35
  const MOCK_PENDING_RECEIPT: GetCallsStatusResponse = {
31
- status: "PENDING",
36
+ status: "pending",
32
37
  receipts: [],
38
+ atomic: false,
39
+ chainId: 1,
40
+ id: MOCK_CALL_ID,
41
+ version: "2.0.0",
42
+ statusCode: 100,
33
43
  };
34
44
 
35
45
  const mockGetCallsStatus = vi.spyOn(getCallsStatusExports, "getCallsStatus");
@@ -61,10 +71,10 @@ describe("waitForBundle", () => {
61
71
  mockGetCallsStatus.mockResolvedValueOnce(MOCK_SUCCESS_RECEIPT);
62
72
 
63
73
  // can't `await` here because we still need to be able to increment the block number below
64
- const res = waitForBundle({
74
+ const res = waitForCallsReceipt({
65
75
  chain: ANVIL_CHAIN,
66
76
  client: TEST_CLIENT,
67
- bundleId: MOCK_BUNDLE_ID,
77
+ id: MOCK_CALL_ID,
68
78
  wallet,
69
79
  });
70
80
 
@@ -76,10 +86,10 @@ describe("waitForBundle", () => {
76
86
  it("should reject with an error when bundle is not complete after waiting 10 blocks", async () => {
77
87
  mockGetCallsStatus.mockRejectedValue(MOCK_PENDING_RECEIPT);
78
88
 
79
- const result = waitForBundle({
89
+ const result = waitForCallsReceipt({
80
90
  chain: ANVIL_CHAIN,
81
91
  client: TEST_CLIENT,
82
- bundleId: MOCK_BUNDLE_ID,
92
+ id: MOCK_CALL_ID,
83
93
  wallet,
84
94
  maxBlocksWaitTime: 10,
85
95
  });
@@ -4,20 +4,18 @@ import { watchBlockNumber } from "../../rpc/watchBlockNumber.js";
4
4
  import type { Prettify } from "../../utils/type-utils.js";
5
5
  import type { Wallet } from "../interfaces/wallet.js";
6
6
  import { getCallsStatus } from "./get-calls-status.js";
7
- import type { GetCallsStatusResponse, WalletSendCallsId } from "./types.js";
8
-
7
+ import type { GetCallsStatusResponse } from "./types.js";
9
8
  const DEFAULT_MAX_BLOCKS_WAIT_TIME = 100;
10
9
 
11
10
  const map = new Map<string, Promise<GetCallsStatusResponse>>();
12
11
 
13
- export type WaitForBundleOptions = Prettify<{
14
- bundleId: WalletSendCallsId;
15
- wallet: Wallet;
12
+ export type WaitForCallsReceiptOptions = Prettify<{
13
+ id: string;
16
14
  client: ThirdwebClient;
17
15
  chain: Chain;
16
+ wallet: Wallet;
18
17
  maxBlocksWaitTime?: number;
19
18
  }>;
20
-
21
19
  /**
22
20
  * Waits for the [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) bundle to be confirmed.
23
21
  *
@@ -30,23 +28,35 @@ export type WaitForBundleOptions = Prettify<{
30
28
  * @beta
31
29
  * @example
32
30
  * ```ts
33
- * import { waitForBundle } from "thirdweb/wallets/eip5792";
34
- * const result = await waitForBundle({
31
+ * import { waitForCallsReceipt } from "thirdweb/wallets/eip5792";
32
+ * const result = await waitForCallsReceipt({
33
+ * client,
34
+ * chain,
35
+ * wallet,
36
+ * id: "0x123...",
37
+ * });
38
+ * ```
39
+ *
40
+ * Example with useSendCalls:
41
+ * ```ts
42
+ * const sendResult = await sendCalls({
35
43
  * client,
36
44
  * chain,
37
45
  * wallet,
38
- * bundleId: "0x123...",
46
+ * calls: [...],
39
47
  * });
48
+ * const confirmResult = await waitForCallsReceipt(sendResult);
49
+ * console.log("Transaction confirmed: ", confirmResult.receipts?.[0].transactionHash);
40
50
  * ```
41
51
  * @extension EIP5792
42
52
  */
43
- export function waitForBundle(
44
- options: WaitForBundleOptions,
53
+ export function waitForCallsReceipt(
54
+ options: WaitForCallsReceiptOptions,
45
55
  ): Promise<GetCallsStatusResponse> {
46
- const { bundleId, chain, wallet, client } = options;
56
+ const { id, chain, wallet, client } = options;
47
57
 
48
58
  const chainId = chain.id;
49
- const key = `${chainId}:calls_${bundleId}`;
59
+ const key = `${chainId}:calls_${id}`;
50
60
  const maxBlocksWaitTime =
51
61
  options.maxBlocksWaitTime ?? DEFAULT_MAX_BLOCKS_WAIT_TIME;
52
62
 
@@ -74,14 +84,14 @@ export function waitForBundle(
74
84
  const result = await getCallsStatus({
75
85
  wallet,
76
86
  client,
77
- bundleId,
87
+ id,
78
88
  });
79
-
80
- if (result.status === "CONFIRMED") {
89
+ if (result.status === "success" || result.status === "failure") {
81
90
  // stop the polling
82
91
  unwatch();
83
92
  // resolve the top level promise with the result
84
93
  resolve(result);
94
+ return;
85
95
  }
86
96
  } catch {
87
97
  // noop, we'll try again on the next blocks