wagmi 1.4.1 → 2.0.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 (293) hide show
  1. package/dist/esm/context.js +16 -0
  2. package/dist/esm/context.js.map +1 -0
  3. package/dist/esm/errors/base.js +20 -0
  4. package/dist/esm/errors/base.js.map +1 -0
  5. package/dist/esm/errors/context.js +13 -0
  6. package/dist/esm/errors/context.js.map +1 -0
  7. package/dist/esm/exports/actions.js +4 -0
  8. package/dist/esm/exports/actions.js.map +1 -0
  9. package/dist/esm/exports/chains.js +4 -0
  10. package/dist/esm/exports/chains.js.map +1 -0
  11. package/dist/esm/exports/connectors.js +4 -0
  12. package/dist/esm/exports/connectors.js.map +1 -0
  13. package/dist/esm/exports/index.js +63 -0
  14. package/dist/esm/exports/index.js.map +1 -0
  15. package/dist/esm/exports/query.js +4 -0
  16. package/dist/esm/exports/query.js.map +1 -0
  17. package/dist/esm/hooks/useAccount.js +10 -0
  18. package/dist/esm/hooks/useAccount.js.map +1 -0
  19. package/dist/esm/hooks/useAccountEffect.js +29 -0
  20. package/dist/esm/hooks/useAccountEffect.js.map +1 -0
  21. package/dist/esm/hooks/useBalance.js +19 -0
  22. package/dist/esm/hooks/useBalance.js.map +1 -0
  23. package/dist/esm/hooks/useBlockNumber.js +37 -0
  24. package/dist/esm/hooks/useBlockNumber.js.map +1 -0
  25. package/dist/esm/hooks/useChainId.js +10 -0
  26. package/dist/esm/hooks/useChainId.js.map +1 -0
  27. package/dist/esm/hooks/useClient.js +10 -0
  28. package/dist/esm/hooks/useClient.js.map +1 -0
  29. package/dist/esm/hooks/useConfig.js +13 -0
  30. package/dist/esm/hooks/useConfig.js.map +1 -0
  31. package/dist/esm/hooks/useConnect.js +22 -0
  32. package/dist/esm/hooks/useConnect.js.map +1 -0
  33. package/dist/esm/hooks/useConnections.js +10 -0
  34. package/dist/esm/hooks/useConnections.js.map +1 -0
  35. package/dist/esm/hooks/useConnectorClient.js +40 -0
  36. package/dist/esm/hooks/useConnectorClient.js.map +1 -0
  37. package/dist/esm/hooks/useContractRead.js +26 -0
  38. package/dist/esm/hooks/useContractRead.js.map +1 -0
  39. package/dist/esm/hooks/useContractReads.js +38 -0
  40. package/dist/esm/hooks/useContractReads.js.map +1 -0
  41. package/dist/esm/hooks/useContractSimulate.js +24 -0
  42. package/dist/esm/hooks/useContractSimulate.js.map +1 -0
  43. package/dist/esm/hooks/useContractWrite.js +20 -0
  44. package/dist/esm/hooks/useContractWrite.js.map +1 -0
  45. package/dist/esm/hooks/useDisconnect.js +23 -0
  46. package/dist/esm/hooks/useDisconnect.js.map +1 -0
  47. package/dist/esm/hooks/useEnsAddress.js +19 -0
  48. package/dist/esm/hooks/useEnsAddress.js.map +1 -0
  49. package/dist/esm/hooks/useEnsAvatar.js +19 -0
  50. package/dist/esm/hooks/useEnsAvatar.js.map +1 -0
  51. package/dist/esm/hooks/useEnsName.js +19 -0
  52. package/dist/esm/hooks/useEnsName.js.map +1 -0
  53. package/dist/esm/hooks/useEnsResolver.js +19 -0
  54. package/dist/esm/hooks/useEnsResolver.js.map +1 -0
  55. package/dist/esm/hooks/useEstimateFeesPerGas.js +19 -0
  56. package/dist/esm/hooks/useEstimateFeesPerGas.js.map +1 -0
  57. package/dist/esm/hooks/useEstimateGas.js +25 -0
  58. package/dist/esm/hooks/useEstimateGas.js.map +1 -0
  59. package/dist/esm/hooks/usePublicClient.js +10 -0
  60. package/dist/esm/hooks/usePublicClient.js.map +1 -0
  61. package/dist/esm/hooks/useReconnect.js +22 -0
  62. package/dist/esm/hooks/useReconnect.js.map +1 -0
  63. package/dist/esm/hooks/useSendTransaction.js +20 -0
  64. package/dist/esm/hooks/useSendTransaction.js.map +1 -0
  65. package/dist/esm/hooks/useSignMessage.js +21 -0
  66. package/dist/esm/hooks/useSignMessage.js.map +1 -0
  67. package/dist/esm/hooks/useSignTypedData.js +20 -0
  68. package/dist/esm/hooks/useSignTypedData.js.map +1 -0
  69. package/dist/esm/hooks/useSwitchAccount.js +22 -0
  70. package/dist/esm/hooks/useSwitchAccount.js.map +1 -0
  71. package/dist/esm/hooks/useSwitchChain.js +21 -0
  72. package/dist/esm/hooks/useSwitchChain.js.map +1 -0
  73. package/dist/esm/hooks/useSyncExternalStoreWithTracked.js +40 -0
  74. package/dist/esm/hooks/useSyncExternalStoreWithTracked.js.map +1 -0
  75. package/dist/esm/hooks/useToken.js +19 -0
  76. package/dist/esm/hooks/useToken.js.map +1 -0
  77. package/dist/esm/hooks/useTransaction.js +19 -0
  78. package/dist/esm/hooks/useTransaction.js.map +1 -0
  79. package/dist/esm/hooks/useWaitForTransactionReceipt.js +19 -0
  80. package/dist/esm/hooks/useWaitForTransactionReceipt.js.map +1 -0
  81. package/dist/esm/hooks/useWalletClient.js +42 -0
  82. package/dist/esm/hooks/useWalletClient.js.map +1 -0
  83. package/dist/esm/hooks/useWatchBlockNumber.js +25 -0
  84. package/dist/esm/hooks/useWatchBlockNumber.js.map +1 -0
  85. package/dist/esm/hooks/useWatchContractEvent.js +25 -0
  86. package/dist/esm/hooks/useWatchContractEvent.js.map +1 -0
  87. package/dist/esm/hooks/useWatchPendingTransactions.js +25 -0
  88. package/dist/esm/hooks/useWatchPendingTransactions.js.map +1 -0
  89. package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
  90. package/dist/esm/types/properties.js +2 -0
  91. package/dist/esm/types/properties.js.map +1 -0
  92. package/dist/esm/utils/getVersion.js +3 -0
  93. package/dist/esm/utils/getVersion.js.map +1 -0
  94. package/dist/esm/utils/query.js +21 -0
  95. package/dist/esm/utils/query.js.map +1 -0
  96. package/dist/esm/version.js +2 -0
  97. package/dist/esm/version.js.map +1 -0
  98. package/dist/types/context.d.ts +11 -0
  99. package/dist/types/context.d.ts.map +1 -0
  100. package/dist/types/errors/base.d.ts +7 -0
  101. package/dist/types/errors/base.d.ts.map +1 -0
  102. package/dist/types/errors/context.d.ts +6 -0
  103. package/dist/types/errors/context.d.ts.map +1 -0
  104. package/dist/types/exports/actions.d.ts +2 -0
  105. package/dist/types/exports/actions.d.ts.map +1 -0
  106. package/dist/types/exports/chains.d.ts +2 -0
  107. package/dist/types/exports/chains.d.ts.map +1 -0
  108. package/dist/types/exports/connectors.d.ts +2 -0
  109. package/dist/types/exports/connectors.d.ts.map +1 -0
  110. package/dist/types/exports/index.d.ts +46 -0
  111. package/dist/types/exports/index.d.ts.map +1 -0
  112. package/dist/types/exports/query.d.ts +2 -0
  113. package/dist/types/exports/query.d.ts.map +1 -0
  114. package/dist/types/hooks/useAccount.d.ts +7 -0
  115. package/dist/types/hooks/useAccount.d.ts.map +1 -0
  116. package/dist/types/hooks/useAccountEffect.d.ts +14 -0
  117. package/dist/types/hooks/useAccountEffect.d.ts.map +1 -0
  118. package/dist/types/hooks/useBalance.d.ts +13 -0
  119. package/dist/types/hooks/useBalance.d.ts.map +1 -0
  120. package/dist/types/hooks/useBlockNumber.d.ts +14 -0
  121. package/dist/types/hooks/useBlockNumber.d.ts.map +1 -0
  122. package/dist/types/hooks/useChainId.d.ts +7 -0
  123. package/dist/types/hooks/useChainId.d.ts.map +1 -0
  124. package/dist/types/hooks/useClient.d.ts +8 -0
  125. package/dist/types/hooks/useClient.d.ts.map +1 -0
  126. package/dist/types/hooks/useConfig.d.ts +7 -0
  127. package/dist/types/hooks/useConfig.d.ts.map +1 -0
  128. package/dist/types/hooks/useConnect.d.ts +16 -0
  129. package/dist/types/hooks/useConnect.d.ts.map +1 -0
  130. package/dist/types/hooks/useConnections.d.ts +7 -0
  131. package/dist/types/hooks/useConnections.d.ts.map +1 -0
  132. package/dist/types/hooks/useConnectorClient.d.ts +12 -0
  133. package/dist/types/hooks/useConnectorClient.d.ts.map +1 -0
  134. package/dist/types/hooks/useContractRead.d.ts +13 -0
  135. package/dist/types/hooks/useContractRead.d.ts.map +1 -0
  136. package/dist/types/hooks/useContractReads.d.ts +13 -0
  137. package/dist/types/hooks/useContractReads.d.ts.map +1 -0
  138. package/dist/types/hooks/useContractSimulate.d.ts +12 -0
  139. package/dist/types/hooks/useContractSimulate.d.ts.map +1 -0
  140. package/dist/types/hooks/useContractWrite.d.ts +15 -0
  141. package/dist/types/hooks/useContractWrite.d.ts.map +1 -0
  142. package/dist/types/hooks/useDisconnect.d.ts +16 -0
  143. package/dist/types/hooks/useDisconnect.d.ts.map +1 -0
  144. package/dist/types/hooks/useEnsAddress.d.ts +12 -0
  145. package/dist/types/hooks/useEnsAddress.d.ts.map +1 -0
  146. package/dist/types/hooks/useEnsAvatar.d.ts +12 -0
  147. package/dist/types/hooks/useEnsAvatar.d.ts.map +1 -0
  148. package/dist/types/hooks/useEnsName.d.ts +12 -0
  149. package/dist/types/hooks/useEnsName.d.ts.map +1 -0
  150. package/dist/types/hooks/useEnsResolver.d.ts +12 -0
  151. package/dist/types/hooks/useEnsResolver.d.ts.map +1 -0
  152. package/dist/types/hooks/useEstimateFeesPerGas.d.ts +13 -0
  153. package/dist/types/hooks/useEstimateFeesPerGas.d.ts.map +1 -0
  154. package/dist/types/hooks/useEstimateGas.d.ts +11 -0
  155. package/dist/types/hooks/useEstimateGas.d.ts.map +1 -0
  156. package/dist/types/hooks/usePublicClient.d.ts +8 -0
  157. package/dist/types/hooks/usePublicClient.d.ts.map +1 -0
  158. package/dist/types/hooks/useReconnect.d.ts +16 -0
  159. package/dist/types/hooks/useReconnect.d.ts.map +1 -0
  160. package/dist/types/hooks/useSendTransaction.d.ts +15 -0
  161. package/dist/types/hooks/useSendTransaction.d.ts.map +1 -0
  162. package/dist/types/hooks/useSignMessage.d.ts +15 -0
  163. package/dist/types/hooks/useSignMessage.d.ts.map +1 -0
  164. package/dist/types/hooks/useSignTypedData.d.ts +15 -0
  165. package/dist/types/hooks/useSignTypedData.d.ts.map +1 -0
  166. package/dist/types/hooks/useSwitchAccount.d.ts +16 -0
  167. package/dist/types/hooks/useSwitchAccount.d.ts.map +1 -0
  168. package/dist/types/hooks/useSwitchChain.d.ts +16 -0
  169. package/dist/types/hooks/useSwitchChain.d.ts.map +1 -0
  170. package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts +2 -0
  171. package/dist/types/hooks/useSyncExternalStoreWithTracked.d.ts.map +1 -0
  172. package/dist/types/hooks/useToken.d.ts +12 -0
  173. package/dist/types/hooks/useToken.d.ts.map +1 -0
  174. package/dist/types/hooks/useTransaction.d.ts +12 -0
  175. package/dist/types/hooks/useTransaction.d.ts.map +1 -0
  176. package/dist/types/hooks/useWaitForTransactionReceipt.d.ts +12 -0
  177. package/dist/types/hooks/useWaitForTransactionReceipt.d.ts.map +1 -0
  178. package/dist/types/hooks/useWalletClient.d.ts +12 -0
  179. package/dist/types/hooks/useWalletClient.d.ts.map +1 -0
  180. package/dist/types/hooks/useWatchBlockNumber.d.ts +8 -0
  181. package/dist/types/hooks/useWatchBlockNumber.d.ts.map +1 -0
  182. package/dist/types/hooks/useWatchContractEvent.d.ts +9 -0
  183. package/dist/types/hooks/useWatchContractEvent.d.ts.map +1 -0
  184. package/dist/types/hooks/useWatchPendingTransactions.d.ts +8 -0
  185. package/dist/types/hooks/useWatchPendingTransactions.d.ts.map +1 -0
  186. package/dist/types/types/properties.d.ts +8 -0
  187. package/dist/types/types/properties.d.ts.map +1 -0
  188. package/dist/types/utils/getVersion.d.ts +2 -0
  189. package/dist/types/utils/getVersion.d.ts.map +1 -0
  190. package/dist/types/utils/query.d.ts +15 -0
  191. package/dist/types/utils/query.d.ts.map +1 -0
  192. package/dist/types/version.d.ts +2 -0
  193. package/dist/types/version.d.ts.map +1 -0
  194. package/package.json +65 -103
  195. package/src/context.ts +27 -0
  196. package/src/errors/base.ts +13 -0
  197. package/src/errors/context.ts +8 -0
  198. package/src/exports/actions.ts +4 -0
  199. package/src/exports/chains.ts +4 -0
  200. package/src/exports/connectors.ts +4 -0
  201. package/src/exports/index.ts +284 -0
  202. package/src/exports/query.ts +4 -0
  203. package/src/hooks/useAccount.ts +27 -0
  204. package/src/hooks/useAccountEffect.ts +55 -0
  205. package/src/hooks/useBalance.ts +65 -0
  206. package/src/hooks/useBlockNumber.ts +97 -0
  207. package/src/hooks/useChainId.ts +31 -0
  208. package/src/hooks/useClient.ts +43 -0
  209. package/src/hooks/useConfig.ts +22 -0
  210. package/src/hooks/useConnect.ts +80 -0
  211. package/src/hooks/useConnections.ts +27 -0
  212. package/src/hooks/useConnectorClient.ts +95 -0
  213. package/src/hooks/useContractRead.ts +107 -0
  214. package/src/hooks/useContractReads.ts +98 -0
  215. package/src/hooks/useContractSimulate.ts +117 -0
  216. package/src/hooks/useContractWrite.ts +83 -0
  217. package/src/hooks/useDisconnect.ts +68 -0
  218. package/src/hooks/useEnsAddress.ts +61 -0
  219. package/src/hooks/useEnsAvatar.ts +59 -0
  220. package/src/hooks/useEnsName.ts +61 -0
  221. package/src/hooks/useEnsResolver.ts +61 -0
  222. package/src/hooks/useEstimateFeesPerGas.ts +69 -0
  223. package/src/hooks/useEstimateGas.ts +72 -0
  224. package/src/hooks/usePublicClient.ts +45 -0
  225. package/src/hooks/useReconnect.ts +67 -0
  226. package/src/hooks/useSendTransaction.ts +79 -0
  227. package/src/hooks/useSignMessage.ts +65 -0
  228. package/src/hooks/useSignTypedData.ts +66 -0
  229. package/src/hooks/useSwitchAccount.ts +82 -0
  230. package/src/hooks/useSwitchChain.ts +77 -0
  231. package/src/hooks/useSyncExternalStoreWithTracked.ts +67 -0
  232. package/src/hooks/useToken.ts +63 -0
  233. package/src/hooks/useTransaction.ts +68 -0
  234. package/src/hooks/useWaitForTransactionReceipt.ts +74 -0
  235. package/src/hooks/useWalletClient.ts +96 -0
  236. package/src/hooks/useWatchBlockNumber.ts +49 -0
  237. package/src/hooks/useWatchContractEvent.ts +64 -0
  238. package/src/hooks/useWatchPendingTransactions.ts +52 -0
  239. package/src/types/properties.ts +9 -0
  240. package/src/utils/getVersion.ts +3 -0
  241. package/src/utils/query.ts +102 -0
  242. package/src/version.ts +1 -0
  243. package/README.md +0 -30
  244. package/actions/package.json +0 -4
  245. package/chains/package.json +0 -4
  246. package/connectors/coinbaseWallet/package.json +0 -4
  247. package/connectors/injected/package.json +0 -4
  248. package/connectors/ledger/package.json +0 -4
  249. package/connectors/metaMask/package.json +0 -4
  250. package/connectors/mock/package.json +0 -4
  251. package/connectors/package.json +0 -4
  252. package/connectors/safe/package.json +0 -4
  253. package/connectors/walletConnect/package.json +0 -4
  254. package/connectors/walletConnectLegacy/package.json +0 -4
  255. package/dist/actions.d.ts +0 -1
  256. package/dist/actions.js +0 -85
  257. package/dist/chains.d.ts +0 -2
  258. package/dist/chains.js +0 -4
  259. package/dist/connectors/coinbaseWallet.d.ts +0 -1
  260. package/dist/connectors/coinbaseWallet.js +0 -7
  261. package/dist/connectors/index.d.ts +0 -1
  262. package/dist/connectors/index.js +0 -7
  263. package/dist/connectors/injected.d.ts +0 -1
  264. package/dist/connectors/injected.js +0 -7
  265. package/dist/connectors/ledger.d.ts +0 -1
  266. package/dist/connectors/ledger.js +0 -7
  267. package/dist/connectors/metaMask.d.ts +0 -1
  268. package/dist/connectors/metaMask.js +0 -7
  269. package/dist/connectors/mock.d.ts +0 -1
  270. package/dist/connectors/mock.js +0 -7
  271. package/dist/connectors/safe.d.ts +0 -1
  272. package/dist/connectors/safe.js +0 -7
  273. package/dist/connectors/walletConnect.d.ts +0 -1
  274. package/dist/connectors/walletConnect.js +0 -7
  275. package/dist/connectors/walletConnectLegacy.d.ts +0 -1
  276. package/dist/connectors/walletConnectLegacy.js +0 -7
  277. package/dist/index.d.ts +0 -958
  278. package/dist/index.js +0 -2564
  279. package/dist/providers/alchemy.d.ts +0 -1
  280. package/dist/providers/alchemy.js +0 -7
  281. package/dist/providers/infura.d.ts +0 -1
  282. package/dist/providers/infura.js +0 -7
  283. package/dist/providers/jsonRpc.d.ts +0 -1
  284. package/dist/providers/jsonRpc.js +0 -7
  285. package/dist/providers/public.d.ts +0 -1
  286. package/dist/providers/public.js +0 -7
  287. package/dist/window.d.ts +0 -76
  288. package/dist/window.js +0 -1
  289. package/providers/alchemy/package.json +0 -4
  290. package/providers/infura/package.json +0 -4
  291. package/providers/jsonRpc/package.json +0 -4
  292. package/providers/public/package.json +0 -4
  293. package/window/package.json +0 -4
@@ -0,0 +1,65 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type GetBalanceError,
6
+ type ResolvedRegister,
7
+ } from '@wagmi/core'
8
+ import type { Evaluate } from '@wagmi/core/internal'
9
+ import {
10
+ type GetBalanceData,
11
+ type GetBalanceOptions,
12
+ type GetBalanceQueryKey,
13
+ getBalanceQueryOptions,
14
+ } from '@wagmi/core/query'
15
+ import type { GetBalanceQueryFnData } from '@wagmi/core/query'
16
+
17
+ import type { ConfigParameter } from '../types/properties.js'
18
+ import {
19
+ type UseQueryParameters,
20
+ type UseQueryReturnType,
21
+ useQuery,
22
+ } from '../utils/query.js'
23
+ import { useChainId } from './useChainId.js'
24
+ import { useConfig } from './useConfig.js'
25
+
26
+ export type UseBalanceParameters<
27
+ config extends Config = Config,
28
+ selectData = GetBalanceData,
29
+ > = Evaluate<
30
+ GetBalanceOptions<config> &
31
+ ConfigParameter<config> & {
32
+ query?:
33
+ | UseQueryParameters<
34
+ GetBalanceQueryFnData,
35
+ GetBalanceError,
36
+ selectData,
37
+ GetBalanceQueryKey<config>
38
+ >
39
+ | undefined
40
+ }
41
+ >
42
+
43
+ export type UseBalanceReturnType<selectData = GetBalanceData> =
44
+ UseQueryReturnType<selectData, GetBalanceError>
45
+
46
+ /** https://alpha.wagmi.sh/react/api/hooks/useBalance */
47
+ export function useBalance<
48
+ config extends Config = ResolvedRegister['config'],
49
+ selectData = GetBalanceData,
50
+ >(
51
+ parameters: UseBalanceParameters<config, selectData> = {},
52
+ ): UseBalanceReturnType<selectData> {
53
+ const { address, query = {} } = parameters
54
+
55
+ const config = useConfig(parameters)
56
+ const chainId = useChainId()
57
+
58
+ const queryOptions = getBalanceQueryOptions(config, {
59
+ ...parameters,
60
+ chainId: parameters.chainId ?? chainId,
61
+ })
62
+ const enabled = Boolean(address && (query.enabled ?? true))
63
+
64
+ return useQuery({ ...queryOptions, ...query, enabled })
65
+ }
@@ -0,0 +1,97 @@
1
+ 'use client'
2
+
3
+ import { useQueryClient } from '@tanstack/react-query'
4
+ import {
5
+ type Config,
6
+ type GetBlockNumberError,
7
+ type ResolvedRegister,
8
+ } from '@wagmi/core'
9
+ import { type Evaluate } from '@wagmi/core/internal'
10
+ import {
11
+ type GetBlockNumberData,
12
+ type GetBlockNumberOptions,
13
+ type GetBlockNumberQueryFnData,
14
+ type GetBlockNumberQueryKey,
15
+ getBlockNumberQueryOptions,
16
+ } from '@wagmi/core/query'
17
+
18
+ import type { ConfigParameter } from '../types/properties.js'
19
+ import {
20
+ type UseQueryParameters,
21
+ type UseQueryReturnType,
22
+ useQuery,
23
+ } from '../utils/query.js'
24
+ import { useChainId } from './useChainId.js'
25
+ import { useConfig } from './useConfig.js'
26
+ import {
27
+ type UseWatchBlockNumberParameters,
28
+ useWatchBlockNumber,
29
+ } from './useWatchBlockNumber.js'
30
+
31
+ export type UseBlockNumberParameters<
32
+ config extends Config = Config,
33
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
34
+ selectData = GetBlockNumberData,
35
+ > = Evaluate<
36
+ GetBlockNumberOptions<config> &
37
+ ConfigParameter<config> & {
38
+ query?:
39
+ | UseQueryParameters<
40
+ GetBlockNumberQueryFnData,
41
+ GetBlockNumberError,
42
+ selectData,
43
+ GetBlockNumberQueryKey<config>
44
+ >
45
+ | undefined
46
+ watch?:
47
+ | boolean
48
+ | Omit<
49
+ UseWatchBlockNumberParameters<config, chainId>,
50
+ 'chainId' | 'config' | 'onBlockNumber' | 'onError'
51
+ >
52
+ | undefined
53
+ }
54
+ >
55
+
56
+ export type UseBlockNumberReturnType<selectData = GetBlockNumberData> =
57
+ UseQueryReturnType<selectData, GetBlockNumberError>
58
+
59
+ /** https://alpha.wagmi.sh/react/api/hooks/useBlockNumber */
60
+ export function useBlockNumber<
61
+ config extends Config = ResolvedRegister['config'],
62
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
63
+ selectData = GetBlockNumberData,
64
+ >(
65
+ parameters: UseBlockNumberParameters<config, chainId, selectData> = {},
66
+ ): UseBlockNumberReturnType<selectData> {
67
+ const { query = {}, watch } = parameters
68
+
69
+ const config = useConfig(parameters)
70
+ const queryClient = useQueryClient()
71
+ const configChainId = useChainId()
72
+ const chainId = parameters.chainId ?? configChainId
73
+
74
+ const queryOptions = getBlockNumberQueryOptions(config, {
75
+ ...parameters,
76
+ chainId,
77
+ })
78
+
79
+ useWatchBlockNumber({
80
+ ...{
81
+ config: parameters.config,
82
+ chainId: parameters.chainId as number,
83
+ },
84
+ ...(typeof watch === 'object'
85
+ ? (watch as UseWatchBlockNumberParameters)
86
+ : {}),
87
+ enabled: Boolean(
88
+ (query.enabled ?? true) &&
89
+ (typeof watch === 'object' ? watch.enabled : watch),
90
+ ),
91
+ onBlockNumber(blockNumber) {
92
+ queryClient.setQueryData(queryOptions.queryKey, blockNumber)
93
+ },
94
+ })
95
+
96
+ return useQuery({ ...queryOptions, ...query })
97
+ }
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type GetChainIdReturnType,
6
+ type ResolvedRegister,
7
+ getChainId,
8
+ watchChainId,
9
+ } from '@wagmi/core'
10
+ import { useSyncExternalStore } from 'react'
11
+
12
+ import type { ConfigParameter } from '../types/properties.js'
13
+ import { useConfig } from './useConfig.js'
14
+
15
+ export type UseChainIdParameters<config extends Config = Config> =
16
+ ConfigParameter<config>
17
+
18
+ export type UseChainIdReturnType<config extends Config = Config> =
19
+ GetChainIdReturnType<config>
20
+
21
+ /** https://alpha.wagmi.sh/react/api/hooks/useChainId */
22
+ export function useChainId<config extends Config = ResolvedRegister['config']>(
23
+ parameters: UseChainIdParameters<config> = {},
24
+ ): UseChainIdReturnType<config> {
25
+ const config = useConfig(parameters)
26
+
27
+ return useSyncExternalStore(
28
+ (onChange) => watchChainId(config, { onChange }),
29
+ () => getChainId(config),
30
+ )
31
+ }
@@ -0,0 +1,43 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type GetClientParameters,
6
+ type GetClientReturnType,
7
+ type ResolvedRegister,
8
+ getClient,
9
+ watchClient,
10
+ } from '@wagmi/core'
11
+ import type { Evaluate } from '@wagmi/core/internal'
12
+ import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'
13
+
14
+ import type { ConfigParameter } from '../types/properties.js'
15
+ import { useConfig } from './useConfig.js'
16
+
17
+ export type UseClientParameters<
18
+ config extends Config = Config,
19
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
20
+ > = Evaluate<GetClientParameters<config, chainId> & ConfigParameter<config>>
21
+
22
+ export type UseClientReturnType<
23
+ config extends Config = Config,
24
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
25
+ > = GetClientReturnType<config, chainId>
26
+
27
+ /** https://alpha.wagmi.sh/react/api/hooks/useClient */
28
+ export function useClient<
29
+ config extends Config = ResolvedRegister['config'],
30
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
31
+ >(
32
+ parameters: UseClientParameters<config, chainId> = {},
33
+ ): UseClientReturnType<config, chainId> {
34
+ const config = useConfig(parameters)
35
+
36
+ return useSyncExternalStoreWithSelector(
37
+ (onChange) => watchClient(config, { onChange }),
38
+ () => getClient(config, parameters),
39
+ () => getClient(config, parameters),
40
+ (x) => x,
41
+ (a, b) => a.uid === b.uid,
42
+ ) as any
43
+ }
@@ -0,0 +1,22 @@
1
+ 'use client'
2
+
3
+ import { type Config, type ResolvedRegister } from '@wagmi/core'
4
+ import { useContext } from 'react'
5
+
6
+ import { WagmiContext } from '../context.js'
7
+ import { WagmiProviderNotFoundError } from '../errors/context.js'
8
+ import type { ConfigParameter } from '../types/properties.js'
9
+
10
+ export type UseConfigParameters<config extends Config = Config> =
11
+ ConfigParameter<config>
12
+
13
+ export type UseConfigReturnType<config extends Config = Config> = config
14
+
15
+ /** https://alpha.wagmi.sh/react/api/hooks/useConfig */
16
+ export function useConfig<config extends Config = ResolvedRegister['config']>(
17
+ parameters: UseConfigParameters<config> = {},
18
+ ): UseConfigReturnType<config> {
19
+ const config = parameters.config ?? useContext(WagmiContext)
20
+ if (!config) throw new WagmiProviderNotFoundError()
21
+ return config as UseConfigReturnType<config>
22
+ }
@@ -0,0 +1,80 @@
1
+ 'use client'
2
+
3
+ import { useMutation } from '@tanstack/react-query'
4
+ import {
5
+ type Config,
6
+ type ConnectError,
7
+ type ResolvedRegister,
8
+ } from '@wagmi/core'
9
+ import type { Evaluate } from '@wagmi/core/internal'
10
+ import {
11
+ type ConnectData,
12
+ type ConnectMutate,
13
+ type ConnectMutateAsync,
14
+ type ConnectVariables,
15
+ connectMutationOptions,
16
+ } from '@wagmi/core/query'
17
+
18
+ import type { ConfigParameter } from '../types/properties.js'
19
+ import type {
20
+ UseMutationParameters,
21
+ UseMutationReturnType,
22
+ } from '../utils/query.js'
23
+ import { useConfig } from './useConfig.js'
24
+
25
+ export type UseConnectParameters<
26
+ config extends Config = Config,
27
+ context = unknown,
28
+ > = Evaluate<
29
+ ConfigParameter<config> & {
30
+ mutation?:
31
+ | UseMutationParameters<
32
+ ConnectData<config>,
33
+ ConnectError,
34
+ ConnectVariables<config>,
35
+ context
36
+ >
37
+ | undefined
38
+ }
39
+ >
40
+
41
+ export type UseConnectReturnType<
42
+ config extends Config = Config,
43
+ context = unknown,
44
+ > = Evaluate<
45
+ UseMutationReturnType<
46
+ ConnectData<config>,
47
+ ConnectError,
48
+ ConnectVariables<config>,
49
+ context
50
+ > & {
51
+ connect: ConnectMutate<config, context>
52
+ connectAsync: ConnectMutateAsync<config, context>
53
+ connectors: config['connectors']
54
+ }
55
+ >
56
+
57
+ /** https://alpha.wagmi.sh/react/api/hooks/useConnect */
58
+ export function useConnect<
59
+ config extends Config = ResolvedRegister['config'],
60
+ context = unknown,
61
+ >(
62
+ parameters: UseConnectParameters<config, context> = {},
63
+ ): UseConnectReturnType<config, context> {
64
+ const { mutation } = parameters
65
+
66
+ const config = useConfig(parameters)
67
+
68
+ const mutationOptions = connectMutationOptions(config)
69
+ const { mutate, mutateAsync, ...result } = useMutation({
70
+ ...mutation,
71
+ ...mutationOptions,
72
+ })
73
+
74
+ return {
75
+ ...result,
76
+ connect: mutate,
77
+ connectAsync: mutateAsync,
78
+ connectors: config.connectors,
79
+ }
80
+ }
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type GetConnectionsReturnType,
5
+ getConnections,
6
+ watchConnections,
7
+ } from '@wagmi/core'
8
+ import { useSyncExternalStore } from 'react'
9
+
10
+ import type { ConfigParameter } from '../types/properties.js'
11
+ import { useConfig } from './useConfig.js'
12
+
13
+ export type UseConnectionsParameters = ConfigParameter
14
+
15
+ export type UseConnectionsReturnType = GetConnectionsReturnType
16
+
17
+ /** https://alpha.wagmi.sh/react/api/hooks/useConnections */
18
+ export function useConnections(
19
+ parameters: UseConnectionsParameters = {},
20
+ ): UseConnectionsReturnType {
21
+ const config = useConfig(parameters)
22
+
23
+ return useSyncExternalStore(
24
+ (onChange) => watchConnections(config, { onChange }),
25
+ () => getConnections(config),
26
+ )
27
+ }
@@ -0,0 +1,95 @@
1
+ 'use client'
2
+
3
+ import { useQueryClient } from '@tanstack/react-query'
4
+ import type {
5
+ Config,
6
+ GetConnectorClientError,
7
+ ResolvedRegister,
8
+ } from '@wagmi/core'
9
+ import { type Evaluate, type Omit } from '@wagmi/core/internal'
10
+ import {
11
+ type GetConnectorClientData,
12
+ type GetConnectorClientOptions,
13
+ type GetConnectorClientQueryFnData,
14
+ type GetConnectorClientQueryKey,
15
+ getConnectorClientQueryOptions,
16
+ } from '@wagmi/core/query'
17
+ import { useEffect } from 'react'
18
+
19
+ import type { ConfigParameter } from '../types/properties.js'
20
+ import {
21
+ type UseQueryParameters,
22
+ type UseQueryReturnType,
23
+ useQuery,
24
+ } from '../utils/query.js'
25
+ import { useAccount } from './useAccount.js'
26
+ import { useChainId } from './useChainId.js'
27
+ import { useConfig } from './useConfig.js'
28
+
29
+ export type UseConnectorClientParameters<
30
+ config extends Config = Config,
31
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
32
+ selectData = GetConnectorClientData<config, chainId>,
33
+ > = Evaluate<
34
+ GetConnectorClientOptions<config, chainId> &
35
+ ConfigParameter<config> & {
36
+ query?:
37
+ | Evaluate<
38
+ Omit<
39
+ UseQueryParameters<
40
+ GetConnectorClientQueryFnData<config, chainId>,
41
+ GetConnectorClientError,
42
+ selectData,
43
+ GetConnectorClientQueryKey<config, chainId>
44
+ >,
45
+ 'gcTime' | 'staleTime'
46
+ >
47
+ >
48
+ | undefined
49
+ }
50
+ >
51
+
52
+ export type UseConnectorClientReturnType<
53
+ config extends Config = Config,
54
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
55
+ selectData = GetConnectorClientData<config, chainId>,
56
+ > = UseQueryReturnType<selectData, GetConnectorClientError>
57
+
58
+ /** https://alpha.wagmi.sh/react/api/hooks/useConnectorClient */
59
+ export function useConnectorClient<
60
+ config extends Config = ResolvedRegister['config'],
61
+ chainId extends config['chains'][number]['id'] = config['chains'][number]['id'],
62
+ selectData = GetConnectorClientData<config, chainId>,
63
+ >(
64
+ parameters: UseConnectorClientParameters<config, chainId, selectData> = {},
65
+ ): UseConnectorClientReturnType<config, chainId, selectData> {
66
+ const { query = {} } = parameters
67
+
68
+ const config = useConfig(parameters)
69
+ const queryClient = useQueryClient()
70
+ const { address, connector, status } = useAccount()
71
+ const chainId = useChainId()
72
+
73
+ const { queryKey, ...options } = getConnectorClientQueryOptions(config, {
74
+ ...parameters,
75
+ chainId: parameters.chainId ?? chainId,
76
+ connector: parameters.connector ?? connector,
77
+ })
78
+ const enabled = Boolean(status !== 'disconnected' && (query.enabled ?? true))
79
+
80
+ // biome-ignore lint/nursery/useExhaustiveDependencies: `queryKey` not required
81
+ useEffect(() => {
82
+ // invalidate when address changes
83
+ if (address) queryClient.invalidateQueries({ queryKey })
84
+ else queryClient.removeQueries({ queryKey }) // remove when account is disconnected
85
+ }, [address, queryClient])
86
+
87
+ return useQuery({
88
+ ...options,
89
+ ...query,
90
+ queryKey,
91
+ enabled,
92
+ gcTime: 0,
93
+ staleTime: Infinity,
94
+ })
95
+ }
@@ -0,0 +1,107 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type ReadContractError,
6
+ type ResolvedRegister,
7
+ } from '@wagmi/core'
8
+ import { type UnionEvaluate } from '@wagmi/core/internal'
9
+ import {
10
+ type ReadContractData,
11
+ type ReadContractOptions,
12
+ type ReadContractQueryFnData,
13
+ type ReadContractQueryKey,
14
+ readContractQueryOptions,
15
+ } from '@wagmi/core/query'
16
+ import {
17
+ type Abi,
18
+ type ContractFunctionArgs,
19
+ type ContractFunctionName,
20
+ } from 'viem'
21
+
22
+ import type { ConfigParameter } from '../types/properties.js'
23
+ import {
24
+ type UseQueryParameters,
25
+ type UseQueryReturnType,
26
+ structuralSharing,
27
+ useQuery,
28
+ } from '../utils/query.js'
29
+ import { useChainId } from './useChainId.js'
30
+ import { useConfig } from './useConfig.js'
31
+
32
+ export type UseContractReadParameters<
33
+ abi extends Abi | readonly unknown[] = Abi,
34
+ functionName extends ContractFunctionName<
35
+ abi,
36
+ 'pure' | 'view'
37
+ > = ContractFunctionName<abi, 'pure' | 'view'>,
38
+ args extends ContractFunctionArgs<
39
+ abi,
40
+ 'pure' | 'view',
41
+ functionName
42
+ > = ContractFunctionArgs<abi, 'pure' | 'view', functionName>,
43
+ config extends Config = Config,
44
+ selectData = ReadContractData<abi, functionName, args>,
45
+ > = UnionEvaluate<
46
+ ReadContractOptions<abi, functionName, args, config> &
47
+ ConfigParameter<config> & {
48
+ query?:
49
+ | UseQueryParameters<
50
+ ReadContractQueryFnData<abi, functionName, args>,
51
+ ReadContractError,
52
+ selectData,
53
+ ReadContractQueryKey<config, abi, functionName, args>
54
+ >
55
+ | undefined
56
+ }
57
+ >
58
+
59
+ export type UseContractReadReturnType<
60
+ abi extends Abi | readonly unknown[] = Abi,
61
+ functionName extends ContractFunctionName<
62
+ abi,
63
+ 'pure' | 'view'
64
+ > = ContractFunctionName<abi, 'pure' | 'view'>,
65
+ args extends ContractFunctionArgs<
66
+ abi,
67
+ 'pure' | 'view',
68
+ functionName
69
+ > = ContractFunctionArgs<abi, 'pure' | 'view', functionName>,
70
+ selectData = ReadContractData<abi, functionName, args>,
71
+ > = UseQueryReturnType<selectData, ReadContractError>
72
+
73
+ /** https://alpha.wagmi.sh/react/api/hooks/useContractRead */
74
+ export function useContractRead<
75
+ const abi extends Abi | readonly unknown[],
76
+ functionName extends ContractFunctionName<abi, 'pure' | 'view'>,
77
+ args extends ContractFunctionArgs<abi, 'pure' | 'view', functionName>,
78
+ config extends Config = ResolvedRegister['config'],
79
+ selectData = ReadContractData<abi, functionName, args>,
80
+ >(
81
+ parameters: UseContractReadParameters<
82
+ abi,
83
+ functionName,
84
+ args,
85
+ config,
86
+ selectData
87
+ > = {} as any,
88
+ ): UseContractReadReturnType<abi, functionName, args, selectData> {
89
+ const { abi, address, functionName, query = {} } = parameters
90
+ const config = useConfig(parameters)
91
+ const chainId = useChainId()
92
+
93
+ const queryOptions = readContractQueryOptions(config, {
94
+ ...(parameters as any),
95
+ chainId: parameters.chainId ?? chainId,
96
+ })
97
+ const enabled = Boolean(
98
+ address && abi && functionName && (query.enabled ?? true),
99
+ )
100
+
101
+ return useQuery({
102
+ ...queryOptions,
103
+ ...query,
104
+ enabled,
105
+ structuralSharing: query.structuralSharing ?? structuralSharing,
106
+ })
107
+ }
@@ -0,0 +1,98 @@
1
+ 'use client'
2
+
3
+ import {
4
+ type Config,
5
+ type ReadContractError,
6
+ type ResolvedRegister,
7
+ } from '@wagmi/core'
8
+ import { type Evaluate } from '@wagmi/core/internal'
9
+ import {
10
+ type ReadContractsData,
11
+ type ReadContractsOptions,
12
+ type ReadContractsQueryFnData,
13
+ type ReadContractsQueryKey,
14
+ readContractsQueryOptions,
15
+ } from '@wagmi/core/query'
16
+ import { useMemo } from 'react'
17
+ import type { ContractFunctionParameters } from 'viem'
18
+
19
+ import type { ConfigParameter } from '../types/properties.js'
20
+ import {
21
+ type UseQueryParameters,
22
+ type UseQueryReturnType,
23
+ structuralSharing,
24
+ useQuery,
25
+ } from '../utils/query.js'
26
+ import { useChainId } from './useChainId.js'
27
+ import { useConfig } from './useConfig.js'
28
+
29
+ export type UseContractReadsParameters<
30
+ contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
31
+ allowFailure extends boolean = true,
32
+ config extends Config = Config,
33
+ selectData = ReadContractsData<contracts, allowFailure>,
34
+ > = Evaluate<
35
+ ReadContractsOptions<config, contracts, allowFailure> &
36
+ ConfigParameter<config> & {
37
+ query?:
38
+ | UseQueryParameters<
39
+ ReadContractsQueryFnData<contracts, allowFailure>,
40
+ ReadContractError,
41
+ selectData,
42
+ ReadContractsQueryKey<config, contracts, allowFailure>
43
+ >
44
+ | undefined
45
+ }
46
+ >
47
+
48
+ export type UseContractReadsReturnType<
49
+ contracts extends readonly unknown[] = readonly ContractFunctionParameters[],
50
+ allowFailure extends boolean = true,
51
+ selectData = ReadContractsData<contracts, allowFailure>,
52
+ > = UseQueryReturnType<selectData, ReadContractError>
53
+
54
+ /** https://alpha.wagmi.sh/react/api/hooks/useContractReads */
55
+ export function useContractReads<
56
+ const contracts extends readonly unknown[],
57
+ allowFailure extends boolean = true,
58
+ config extends Config = ResolvedRegister['config'],
59
+ selectData = ReadContractsData<contracts, allowFailure>,
60
+ >(
61
+ parameters: UseContractReadsParameters<
62
+ contracts,
63
+ allowFailure,
64
+ config,
65
+ selectData
66
+ > = {},
67
+ ): UseContractReadsReturnType<contracts, allowFailure, selectData> {
68
+ const { contracts = [], query = {} } = parameters
69
+
70
+ const config = useConfig(parameters)
71
+ const chainId = useChainId()
72
+
73
+ const queryOptions = readContractsQueryOptions(config, {
74
+ ...parameters,
75
+ chainId,
76
+ contracts,
77
+ })
78
+ const enabled = useMemo(() => {
79
+ let isContractsValid = false
80
+ for (const contract of contracts) {
81
+ const { abi, address, functionName } =
82
+ contract as ContractFunctionParameters
83
+ if (!abi || !address || !functionName) {
84
+ isContractsValid = false
85
+ break
86
+ }
87
+ isContractsValid = true
88
+ }
89
+ return Boolean(isContractsValid && (query.enabled ?? true))
90
+ }, [contracts, query.enabled])
91
+
92
+ return useQuery({
93
+ ...queryOptions,
94
+ ...query,
95
+ enabled,
96
+ structuralSharing: query.structuralSharing ?? structuralSharing,
97
+ })
98
+ }