thirdweb 5.43.2 → 5.43.3-nightly-baefa5e9c7d72fd8645b0e33452a83fc0ef229d4-20240804000345

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 (132) hide show
  1. package/dist/cjs/extensions/marketplace/direct-listings/utils.js +1 -0
  2. package/dist/cjs/extensions/marketplace/direct-listings/utils.js.map +1 -1
  3. package/dist/cjs/extensions/marketplace/english-auctions/utils.js +1 -0
  4. package/dist/cjs/extensions/marketplace/english-auctions/utils.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/contract/useContractEvents.js +32 -2
  6. package/dist/cjs/react/core/hooks/contract/useContractEvents.js.map +1 -1
  7. package/dist/cjs/react/core/hooks/contract/useReadContract.js.map +1 -1
  8. package/dist/cjs/react/core/hooks/others/useWalletBalance.js +17 -2
  9. package/dist/cjs/react/core/hooks/others/useWalletBalance.js.map +1 -1
  10. package/dist/cjs/react/core/hooks/wallets/useActiveAccount.js +1 -0
  11. package/dist/cjs/react/core/hooks/wallets/useActiveAccount.js.map +1 -1
  12. package/dist/cjs/react/core/utils/wallet.js +19 -1
  13. package/dist/cjs/react/core/utils/wallet.js.map +1 -1
  14. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +74 -4
  15. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  16. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +17 -2
  17. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  18. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +15 -0
  19. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  20. package/dist/cjs/react/web/ui/PayEmbed.js +8 -9
  21. package/dist/cjs/react/web/ui/PayEmbed.js.map +1 -1
  22. package/dist/cjs/transaction/actions/send-transaction.js +76 -5
  23. package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
  24. package/dist/cjs/transaction/prepare-contract-call.js +18 -13
  25. package/dist/cjs/transaction/prepare-contract-call.js.map +1 -1
  26. package/dist/cjs/transaction/read-contract.js +39 -6
  27. package/dist/cjs/transaction/read-contract.js.map +1 -1
  28. package/dist/cjs/utils/fetch.js +12 -1
  29. package/dist/cjs/utils/fetch.js.map +1 -1
  30. package/dist/cjs/version.js +1 -1
  31. package/dist/cjs/version.js.map +1 -1
  32. package/dist/cjs/wallets/in-app/web/in-app.js +4 -1
  33. package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
  34. package/dist/cjs/wallets/in-app/web/lib/auth/index.js +1 -0
  35. package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
  36. package/dist/esm/extensions/marketplace/direct-listings/utils.js +1 -0
  37. package/dist/esm/extensions/marketplace/direct-listings/utils.js.map +1 -1
  38. package/dist/esm/extensions/marketplace/english-auctions/utils.js +1 -0
  39. package/dist/esm/extensions/marketplace/english-auctions/utils.js.map +1 -1
  40. package/dist/esm/react/core/hooks/contract/useContractEvents.js +32 -2
  41. package/dist/esm/react/core/hooks/contract/useContractEvents.js.map +1 -1
  42. package/dist/esm/react/core/hooks/contract/useReadContract.js.map +1 -1
  43. package/dist/esm/react/core/hooks/others/useWalletBalance.js +17 -2
  44. package/dist/esm/react/core/hooks/others/useWalletBalance.js.map +1 -1
  45. package/dist/esm/react/core/hooks/wallets/useActiveAccount.js +1 -0
  46. package/dist/esm/react/core/hooks/wallets/useActiveAccount.js.map +1 -1
  47. package/dist/esm/react/core/utils/wallet.js +19 -1
  48. package/dist/esm/react/core/utils/wallet.js.map +1 -1
  49. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +74 -4
  50. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  51. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +17 -2
  52. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  53. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +15 -0
  54. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  55. package/dist/esm/react/web/ui/PayEmbed.js +8 -9
  56. package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
  57. package/dist/esm/transaction/actions/send-transaction.js +76 -5
  58. package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
  59. package/dist/esm/transaction/prepare-contract-call.js +18 -13
  60. package/dist/esm/transaction/prepare-contract-call.js.map +1 -1
  61. package/dist/esm/transaction/read-contract.js +39 -6
  62. package/dist/esm/transaction/read-contract.js.map +1 -1
  63. package/dist/esm/utils/fetch.js +12 -1
  64. package/dist/esm/utils/fetch.js.map +1 -1
  65. package/dist/esm/version.js +1 -1
  66. package/dist/esm/version.js.map +1 -1
  67. package/dist/esm/wallets/in-app/web/in-app.js +4 -1
  68. package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
  69. package/dist/esm/wallets/in-app/web/lib/auth/index.js +1 -0
  70. package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
  71. package/dist/types/extensions/marketplace/direct-listings/types.d.ts +1 -0
  72. package/dist/types/extensions/marketplace/direct-listings/types.d.ts.map +1 -1
  73. package/dist/types/extensions/marketplace/direct-listings/utils.d.ts.map +1 -1
  74. package/dist/types/extensions/marketplace/english-auctions/types.d.ts +1 -0
  75. package/dist/types/extensions/marketplace/english-auctions/types.d.ts.map +1 -1
  76. package/dist/types/extensions/marketplace/english-auctions/utils.d.ts.map +1 -1
  77. package/dist/types/react/core/hooks/contract/useContractEvents.d.ts +32 -2
  78. package/dist/types/react/core/hooks/contract/useContractEvents.d.ts.map +1 -1
  79. package/dist/types/react/core/hooks/contract/useReadContract.d.ts +28 -6
  80. package/dist/types/react/core/hooks/contract/useReadContract.d.ts.map +1 -1
  81. package/dist/types/react/core/hooks/others/useWalletBalance.d.ts +17 -2
  82. package/dist/types/react/core/hooks/others/useWalletBalance.d.ts.map +1 -1
  83. package/dist/types/react/core/hooks/wallets/useActiveAccount.d.ts +1 -0
  84. package/dist/types/react/core/hooks/wallets/useActiveAccount.d.ts.map +1 -1
  85. package/dist/types/react/core/utils/wallet.d.ts +19 -1
  86. package/dist/types/react/core/utils/wallet.d.ts.map +1 -1
  87. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts +74 -4
  88. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  89. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts +17 -2
  90. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  91. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts +15 -0
  92. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
  93. package/dist/types/react/web/ui/PayEmbed.d.ts +1 -0
  94. package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
  95. package/dist/types/transaction/actions/send-transaction.d.ts +76 -5
  96. package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
  97. package/dist/types/transaction/prepare-contract-call.d.ts +18 -13
  98. package/dist/types/transaction/prepare-contract-call.d.ts.map +1 -1
  99. package/dist/types/transaction/read-contract.d.ts +39 -6
  100. package/dist/types/transaction/read-contract.d.ts.map +1 -1
  101. package/dist/types/utils/fetch.d.ts.map +1 -1
  102. package/dist/types/version.d.ts +1 -1
  103. package/dist/types/version.d.ts.map +1 -1
  104. package/dist/types/wallets/in-app/web/in-app.d.ts +4 -1
  105. package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
  106. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +1 -0
  107. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
  108. package/package.json +4 -3
  109. package/src/extensions/marketplace/direct-listings/types.ts +1 -0
  110. package/src/extensions/marketplace/direct-listings/utils.ts +1 -0
  111. package/src/extensions/marketplace/english-auctions/types.ts +1 -0
  112. package/src/extensions/marketplace/english-auctions/utils.ts +1 -0
  113. package/src/react/core/hooks/contract/useContractEvents.ts +32 -2
  114. package/src/react/core/hooks/contract/useReadContract.ts +28 -6
  115. package/src/react/core/hooks/others/useWalletBalance.ts +17 -2
  116. package/src/react/core/hooks/wallets/useActiveAccount.ts +1 -0
  117. package/src/react/core/utils/wallet.ts +19 -1
  118. package/src/react/web/hooks/transaction/useSendTransaction.tsx +74 -4
  119. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +17 -2
  120. package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +15 -0
  121. package/src/react/web/ui/PayEmbed-disconnected.test.tsx +5 -3
  122. package/src/react/web/ui/PayEmbed.test.tsx +17 -16
  123. package/src/react/web/ui/PayEmbed.tsx +9 -4
  124. package/src/transaction/actions/send-transaction.ts +76 -5
  125. package/src/transaction/prepare-contract-call.ts +18 -13
  126. package/src/transaction/read-contract.ts +39 -6
  127. package/src/utils/encoding/hex.test.ts +11 -0
  128. package/src/utils/fetch.ts +12 -1
  129. package/src/version.ts +1 -1
  130. package/src/wallets/in-app/web/in-app.ts +4 -1
  131. package/src/wallets/in-app/web/lib/auth/index.ts +1 -0
  132. package/src/wallets/smart/smart-wallet-integration.test.ts +6 -0
@@ -14,18 +14,89 @@ export type SendTransactionOptions = {
14
14
  };
15
15
 
16
16
  /**
17
- * Sends a transaction using the provided wallet.
17
+ * Sends a transaction using the provided account.
18
+ *
19
+ * You can send a transaction with a [prepared contract call](https://portal.thirdweb.com/references/typescript/v5/prepareContractCall), a [prepared transaction](https://portal.thirdweb.com/references/typescript/v5/prepareTransaction), or using a write [Extension](https://portal.thirdweb.com/typescript/v5/extensions/use).
18
20
  * @param options - The options for sending the transaction.
19
- * @returns A promise that resolves to the transaction hash.
20
- * @throws An error if the wallet is not connected.
21
+ * @returns A promise that resolves to the transaction result.
22
+ * @throws An error if the transaction reverts.
21
23
  * @transaction
22
24
  * @example
25
+ *
26
+ * ### Using a prepared contract call
27
+ *
28
+ * ```ts
29
+ * import { sendTransaction, getContract, prepareContractCall } from "thirdweb";
30
+ * import { sepolia } from "thirdweb/chains";
31
+ *
32
+ * const contract = getContract({
33
+ * address: "0x...",
34
+ * chain: sepolia,
35
+ * client,
36
+ * });
37
+ *
38
+ * const transaction = prepareContractCall({
39
+ * contract,
40
+ * method: "function transfer(address to, uint256 value)",
41
+ * params: [to, value],
42
+ * });
43
+ *
44
+ * const { transactionHash } = await sendTransaction({
45
+ * account,
46
+ * transaction,
47
+ * });
48
+ * ```
49
+ *
50
+ * ### Using a write extension
51
+ *
23
52
  * ```ts
24
- * import { sendTransaction } from "thirdweb";
53
+ * import { sendTransaction, getContract } from "thirdweb";
54
+ * import { sepolia } from "thirdweb/chains";
55
+ * import { mintTo } from "thirdweb/extensions/erc721";
56
+ *
57
+ * const contract = getContract({
58
+ * address: "0x...",
59
+ * chain: sepolia,
60
+ * client,
61
+ * });
62
+ *
63
+ * const transaction = mintTo({
64
+ * contract,
65
+ * to: "0x...",
66
+ * nft: {
67
+ * name: "NFT Name",
68
+ * description: "NFT Description",
69
+ * image: "https://example.com/image.png",
70
+ * },
71
+ * });
72
+ *
73
+ * const { transactionHash } = await sendTransaction({
74
+ * account,
75
+ * transaction,
76
+ * });
77
+ * ```
78
+ *
79
+ * ### Using a prepared transaction
80
+ *
81
+ * ```ts
82
+ * import { sendTransaction, getContract, prepareTransaction } from "thirdweb";
83
+ * import { sepolia } from "thirdweb/chains";
84
+ *
85
+ * const contract = getContract({
86
+ * address: "0x...",
87
+ * chain: sepolia,
88
+ * client,
89
+ * });
90
+ *
91
+ * const transaction = prepareTransaction({
92
+ * contract,
93
+ * to: "0x...",
94
+ * value: toWei("0.1"),
95
+ * });
25
96
  *
26
97
  * const { transactionHash } = await sendTransaction({
27
98
  * account,
28
- * transaction
99
+ * transaction,
29
100
  * });
30
101
  * ```
31
102
  */
@@ -63,36 +63,41 @@ export type PrepareContractCallOptions<
63
63
  * @returns A promise that resolves to the prepared transaction.
64
64
  * @transaction
65
65
  * @example
66
- * Usage with a human-readable method signature:
66
+ *
67
+ * ### Usage with a human-readable method signature:
68
+ *
67
69
  * ```ts
68
70
  * import { prepareContractCall } from "thirdweb";
69
71
  *
70
- * const transaction = await prepareContractCall({
72
+ * const transaction = prepareContractCall({
71
73
  * contract,
72
74
  * method: "function transfer(address to, uint256 value)",
73
75
  * params: [to, value],
74
76
  * });
75
77
  * ```
76
- * @example
77
- * Usage with explicit gas price and/or value:
78
+ *
79
+ * ### Usage with explicit gas price and/or value:
80
+ *
78
81
  * ```ts
79
82
  * import { prepareContractCall } from "thirdweb";
83
+ * import { toWei } from "thirdweb/utils";
80
84
  *
81
- * const transaction = await prepareContractCall({
85
+ * const transaction = prepareContractCall({
82
86
  * contract,
83
87
  * method: "function transfer(address to, uint256 value)",
84
88
  * params: [to, value],
85
89
  * maxFeePerGas: 30n,
86
90
  * maxPriorityFeePerGas: 1n,
87
- * value: 100000n,
91
+ * value: toWei("0.01"),
88
92
  * });
89
93
  * ```
90
- * @example
91
- * Usage with a JSON ABI function object:
94
+ *
95
+ * ### Usage with a JSON ABI function object:
96
+ *
92
97
  * ```ts
93
98
  * import { prepareContractCall } from "thirdweb";
94
99
  *
95
- * const transaction = await prepareContractCall({
100
+ * const transaction = prepareContractCall({
96
101
  * contract,
97
102
  * method: {
98
103
  * name: "transfer",
@@ -107,8 +112,9 @@ export type PrepareContractCallOptions<
107
112
  * params: [to, value],
108
113
  * });
109
114
  * ```
110
- * @example
111
- * Usage with a the ABI defined on the contract:
115
+ *
116
+ * ### Usage with a the ABI defined on the contract:
117
+ *
112
118
  * ```ts
113
119
  * import { getContract, prepareContractCall } from "thirdweb";
114
120
  * const contract = getContract({
@@ -122,8 +128,7 @@ export type PrepareContractCallOptions<
122
128
  * });
123
129
  * ```
124
130
  *
125
- * @example
126
- * Passing extra call data to the transaction
131
+ * ### Passing extra call data to the transaction
127
132
  * ```ts
128
133
  * import { getContract, prepareContractCall } from "thirdweb";
129
134
  * const contract = getContract({
@@ -70,16 +70,49 @@ export type ReadContractOptions<
70
70
  >;
71
71
 
72
72
  /**
73
- * Reads data from a smart contract.
73
+ * Reads state from a deployed smart contract.
74
+ *
75
+ * You can use raw read calls or read [extensions](https://portal.thirdweb.com/typescript/v5/extensions/use) to read from a contract.
76
+ *
74
77
  * @param options - The transaction options.
75
- * @returns A promise that resolves with the result of the read transaction.
78
+ * @returns A promise that resolves with the result of the read call.
76
79
  * @transaction
77
80
  * @example
81
+ *
82
+ * ### Using a contract read extension
83
+ *
78
84
  * ```ts
79
- * import { readContract } from "thirdweb";
80
- * const result = await readContract({
81
- * contract,
82
- * method: "function totalSupply() view returns (uint256)",
85
+ * import { getContract } from "thirdweb";
86
+ * import { sepolia } from "thirdweb/chains";
87
+ * import { useReadContract } from "thirdweb/react";
88
+ * import { getOwnedNFTs } form "thirdweb/extensions/erc721";
89
+ *
90
+ * const contract = getContract({
91
+ * client,
92
+ * address: "0x...",
93
+ * chain: sepolia,
94
+ * });
95
+ *
96
+ * const { data, isLoading } = useReadContract(getOwnedNFTs, { contract, owner: address });
97
+ * ```
98
+ *
99
+ * ### Using a raw contract call
100
+ *
101
+ * ```ts
102
+ * import { getContract } from "thirdweb";
103
+ * import { sepolia } from "thirdweb/chains";
104
+ * import { useReadContract } from "thirdweb/react";
105
+ *
106
+ * const contract = getContract({
107
+ * client,
108
+ * address: "0x...",
109
+ * chain: sepolia,
110
+ * });
111
+ *
112
+ * const { data, isLoading } = useReadContract({
113
+ * contract,
114
+ * method: "function tokenURI(uint256 tokenId) returns (string)"});
115
+ * params: [1n],
83
116
  * });
84
117
  * ```
85
118
  */
@@ -0,0 +1,11 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { numberToHex } from "./hex.js";
3
+
4
+ describe("hex.ts", () => {
5
+ it("should convert", () => {
6
+ const result = numberToHex(100n, { size: 32, signed: false });
7
+ expect(result).toBe(
8
+ "0x0000000000000000000000000000000000000000000000000000000000000064",
9
+ );
10
+ });
11
+ });
@@ -43,7 +43,8 @@ export function getClientFetch(client: ThirdwebClient, ecosystem?: Ecosystem) {
43
43
  }
44
44
  const authToken = getTWAuthToken();
45
45
  // if we have an auth token set, use that (thirdweb.com/dashboard sets this for the user)
46
- if (authToken) {
46
+ // pay urls should never send the auth token, because we always want the "developer" to be the one making the request, not the "end user"
47
+ if (authToken && !isPayUrl(url)) {
47
48
  headers.set("authorization", `Bearer ${authToken}`);
48
49
  } else if (client.secretKey) {
49
50
  headers.set("x-secret-key", client.secretKey);
@@ -127,6 +128,16 @@ export function isThirdwebUrl(url: string): boolean {
127
128
  }
128
129
  }
129
130
 
131
+ function isPayUrl(url: string): boolean {
132
+ try {
133
+ const { hostname } = new URL(url);
134
+ // pay service hostname always starts with "pay."
135
+ return hostname.startsWith("pay.");
136
+ } catch {
137
+ return false;
138
+ }
139
+ }
140
+
130
141
  const SDK_NAME = "unified-sdk";
131
142
 
132
143
  let previousPlatform: [string, string][] | undefined;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.43.2";
1
+ export const version = "5.43.3-nightly-baefa5e9c7d72fd8645b0e33452a83fc0ef229d4-20240804000345";
@@ -39,7 +39,7 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
39
39
  *
40
40
  * [View all available social auth methods](https://portal.thirdweb.com/references/typescript/v5/InAppWalletSocialAuth)
41
41
  *
42
- * * ### Login with email
42
+ * ### Login with email
43
43
  *
44
44
  * ```ts
45
45
  * import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";
@@ -58,6 +58,7 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
58
58
  * client,
59
59
  * chain,
60
60
  * strategy: "email",
61
+ * email: "example@example.com",
61
62
  * verificationCode: "123456",
62
63
  * });
63
64
  * ```
@@ -80,8 +81,10 @@ import { createInAppWallet } from "../core/wallet/in-app-core.js";
80
81
  * client,
81
82
  * chain,
82
83
  * strategy: "phone",
84
+ * honeNumber: "+1234567890",
83
85
  * verificationCode: "123456",
84
86
  * });
87
+ * ```
85
88
  *
86
89
  * ### Login with passkey
87
90
  *
@@ -106,6 +106,7 @@ export async function getUserPhoneNumber(options: GetAuthenticatedUserParams) {
106
106
 
107
107
  /**
108
108
  * Pre-authenticates the user based on the provided authentication strategy.
109
+ * Use this function to send a verification code to the user's email or phone number.
109
110
  * @param args - The arguments required for pre-authentication.
110
111
  * @returns A promise that resolves to the pre-authentication result.
111
112
  * @throws An error if the provided authentication strategy doesn't require pre-authentication.
@@ -18,6 +18,7 @@ import { setContractURI } from "../../extensions/marketplace/__generated__/IMark
18
18
  import { estimateGasCost } from "../../transaction/actions/estimate-gas-cost.js";
19
19
  import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
20
20
  import { sendBatchTransaction } from "../../transaction/actions/send-batch-transaction.js";
21
+ import { waitForReceipt } from "../../transaction/actions/wait-for-tx-receipt.js";
21
22
  import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
22
23
  import type { Account, Wallet } from "../interfaces/wallet.js";
23
24
  import { generateAccount } from "../utils/generateAccount.js";
@@ -139,6 +140,11 @@ describe.runIf(process.env.TW_SECRET_KEY)(
139
140
  ],
140
141
  });
141
142
  expect(tx.transactionHash).toHaveLength(66);
143
+ await waitForReceipt({
144
+ client,
145
+ transactionHash: tx.transactionHash,
146
+ chain,
147
+ });
142
148
  const balance = await balanceOf({
143
149
  contract,
144
150
  owner: smartWalletAddress,