viem 0.0.1-alpha.21 → 0.0.1-alpha.23

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 (181) hide show
  1. package/dist/{chain-32f56cfa.d.ts → chain-4b39613a.d.ts} +2 -2
  2. package/dist/{chain-f12cdc7f.d.ts → chain-aa4898d0.d.ts} +1 -1
  3. package/dist/chains.d.ts +3 -3
  4. package/dist/chains.js +46 -46
  5. package/dist/chains.mjs +1 -1
  6. package/dist/{chunk-EC3NUIJE.js → chunk-7Y5QVLX7.js} +13 -13
  7. package/dist/{chunk-EC3NUIJE.js.map → chunk-7Y5QVLX7.js.map} +1 -1
  8. package/dist/{chunk-KEHGSYDO.js → chunk-BV5NTHUX.js} +14 -13
  9. package/dist/chunk-BV5NTHUX.js.map +1 -0
  10. package/dist/{chunk-46BO7YAQ.mjs → chunk-EGVXCZNJ.mjs} +4 -3
  11. package/dist/chunk-EGVXCZNJ.mjs.map +1 -0
  12. package/dist/{chunk-57ZOFERP.mjs → chunk-GX2KDAM3.mjs} +2 -2
  13. package/dist/{chunk-57ZOFERP.mjs.map → chunk-GX2KDAM3.mjs.map} +0 -0
  14. package/dist/{chunk-W7BWWAC4.js → chunk-NW6724MI.js} +14 -14
  15. package/dist/{chunk-W7BWWAC4.js.map → chunk-NW6724MI.js.map} +0 -0
  16. package/dist/{chunk-DGO77E2H.mjs → chunk-RJLUZTJS.mjs} +86 -3
  17. package/dist/chunk-RJLUZTJS.mjs.map +1 -0
  18. package/dist/{chunk-O2GYLJVD.js → chunk-SSPRUPGN.js} +405 -165
  19. package/dist/chunk-SSPRUPGN.js.map +1 -0
  20. package/dist/{chunk-DSPMAIDO.mjs → chunk-TXHOG6KU.mjs} +2 -2
  21. package/dist/{chunk-DSPMAIDO.mjs.map → chunk-TXHOG6KU.mjs.map} +1 -1
  22. package/dist/{chunk-62VTYU2V.mjs → chunk-XBUH66KN.mjs} +406 -166
  23. package/dist/chunk-XBUH66KN.mjs.map +1 -0
  24. package/dist/{chunk-KZMJR27B.js → chunk-ZKYGWITF.js} +147 -64
  25. package/dist/chunk-ZKYGWITF.js.map +1 -0
  26. package/dist/clients/index.d.ts +7 -7
  27. package/dist/clients/index.js +3 -3
  28. package/dist/clients/index.mjs +2 -2
  29. package/dist/{contract-9af4608b.d.ts → contract-4c3a37b3.d.ts} +14 -3
  30. package/dist/{createClient-5d316c7e.d.ts → createClient-55a04188.d.ts} +2 -2
  31. package/dist/{createPublicClient-9d2b42e1.d.ts → createPublicClient-3b27b282.d.ts} +3 -3
  32. package/dist/{createTestClient-79498dab.d.ts → createTestClient-93f9eac6.d.ts} +3 -3
  33. package/dist/{createWalletClient-f69a5230.d.ts → createWalletClient-c10df94d.d.ts} +3 -3
  34. package/dist/{eip1193-6c485d63.d.ts → eip1193-4c24765a.d.ts} +1 -1
  35. package/dist/ens.d.ts +1 -0
  36. package/dist/ens.js +11 -0
  37. package/dist/ens.js.map +1 -0
  38. package/dist/ens.mjs +11 -0
  39. package/dist/ens.mjs.map +1 -0
  40. package/dist/index.d.ts +174 -113
  41. package/dist/index.js +16 -6
  42. package/dist/index.mjs +15 -5
  43. package/dist/normalize-ef9240c0.d.ts +33 -0
  44. package/dist/{parseGwei-4308ad80.d.ts → parseGwei-3411cf2d.d.ts} +101 -37
  45. package/dist/public.d.ts +9 -9
  46. package/dist/public.js +4 -4
  47. package/dist/public.mjs +3 -3
  48. package/dist/{sendTransaction-1c8290a9.d.ts → sendTransaction-f17a2389.d.ts} +3 -3
  49. package/dist/{stopImpersonatingAccount-7781842a.d.ts → stopImpersonatingAccount-afb26486.d.ts} +2 -2
  50. package/dist/test.d.ts +5 -5
  51. package/dist/test.js +3 -3
  52. package/dist/test.mjs +2 -2
  53. package/dist/{transactionRequest-341b6ed2.d.ts → transactionRequest-93e9f001.d.ts} +2 -2
  54. package/dist/utils/index.d.ts +14 -16
  55. package/dist/utils/index.js +8 -2
  56. package/dist/utils/index.mjs +7 -1
  57. package/dist/wallet.d.ts +7 -7
  58. package/dist/wallet.js +3 -3
  59. package/dist/wallet.mjs +2 -2
  60. package/dist/{watchAsset-afaad3c7.d.ts → watchAsset-efd3dd05.d.ts} +3 -3
  61. package/dist/{watchPendingTransactions-3b722547.d.ts → watchPendingTransactions-57df1a13.d.ts} +17 -27
  62. package/dist/{webSocket-b180e679.d.ts → webSocket-d2e7bd0e.d.ts} +2 -2
  63. package/dist/window.d.ts +2 -2
  64. package/package.json +8 -2
  65. package/src/_test/abis.ts +7 -0
  66. package/src/_test/bench.ts +4 -4
  67. package/src/_test/constants.ts +4 -3
  68. package/src/_test/index.ts +4 -2
  69. package/src/_test/utils.ts +39 -1
  70. package/src/actions/index.test.ts +1 -0
  71. package/src/actions/index.ts +2 -0
  72. package/src/actions/public/call.bench.ts +5 -5
  73. package/src/actions/public/deployContract.ts +4 -4
  74. package/src/actions/public/estimateGas.bench.ts +6 -6
  75. package/src/actions/public/getBlock.bench.ts +5 -5
  76. package/src/actions/public/getBlockNumber.bench.ts +5 -5
  77. package/src/actions/public/getFilterChanges.test.ts +9 -9
  78. package/src/actions/public/getFilterLogs.test.ts +7 -7
  79. package/src/actions/public/getGasPrice.bench.ts +1 -10
  80. package/src/actions/public/getLogs.test.ts +7 -7
  81. package/src/actions/public/getTransaction.bench.ts +5 -5
  82. package/src/actions/public/getTransactionReceipt.bench.ts +5 -5
  83. package/src/actions/public/index.test.ts +1 -0
  84. package/src/actions/public/index.ts +3 -0
  85. package/src/actions/public/multicall.test.ts +452 -0
  86. package/src/actions/public/multicall.ts +103 -0
  87. package/src/actions/public/readContract.test.ts +226 -26
  88. package/src/actions/public/readContract.ts +13 -27
  89. package/src/actions/public/simulateContract.bench.ts +10 -0
  90. package/src/actions/public/simulateContract.test.ts +209 -37
  91. package/src/actions/public/simulateContract.ts +17 -21
  92. package/src/actions/public/watchContractEvent.test.ts +61 -57
  93. package/src/actions/public/watchEvent.test.ts +42 -37
  94. package/src/actions/test/impersonateAccount.test.ts +4 -6
  95. package/src/actions/test/sendUnsignedTransaction.test.ts +2 -2
  96. package/src/actions/test/stopImpersonatingAccount.test.ts +5 -7
  97. package/src/actions/wallet/signMessage.test.ts +0 -1
  98. package/src/actions/wallet/switchChain.test.ts +1 -2
  99. package/src/actions/wallet/watchAsset.test.ts +1 -2
  100. package/src/actions/wallet/writeContract.test.ts +37 -7
  101. package/src/actions/wallet/writeContract.ts +5 -14
  102. package/src/clients/transports/fallback.test.ts +34 -0
  103. package/src/clients/transports/fallback.ts +3 -1
  104. package/src/clients/transports/http.test.ts +0 -1
  105. package/src/clients/transports/webSocket.test.ts +0 -1
  106. package/src/constants/abis.test.ts +53 -0
  107. package/src/constants/abis.ts +44 -0
  108. package/src/constants/index.test.ts +14 -0
  109. package/src/constants/index.ts +3 -0
  110. package/src/constants/solidity.test.ts +41 -0
  111. package/src/constants/solidity.ts +35 -0
  112. package/src/ens.ts +5 -0
  113. package/src/errors/abi.test.ts +0 -2
  114. package/src/errors/base.test.ts +44 -2
  115. package/src/errors/base.ts +12 -12
  116. package/src/errors/block.test.ts +6 -6
  117. package/src/errors/contract.test.ts +233 -0
  118. package/src/errors/contract.ts +133 -80
  119. package/src/errors/index.ts +4 -2
  120. package/src/errors/request.test.ts +3 -4
  121. package/src/errors/request.ts +17 -17
  122. package/src/errors/rpc.test.ts +1 -2
  123. package/src/errors/transaction.test.ts +12 -12
  124. package/src/errors/transport.test.ts +0 -1
  125. package/src/index.test.ts +47 -0
  126. package/src/index.ts +10 -0
  127. package/src/types/contract.ts +55 -4
  128. package/src/types/index.ts +5 -0
  129. package/src/types/multicall.ts +82 -0
  130. package/src/utils/abi/decodeAbi.test.ts +1 -2
  131. package/src/utils/abi/decodeAbi.ts +11 -7
  132. package/src/utils/abi/decodeDeployData.test.ts +7 -15
  133. package/src/utils/abi/decodeDeployData.ts +10 -7
  134. package/src/utils/abi/decodeErrorResult.test.ts +103 -3
  135. package/src/utils/abi/decodeErrorResult.ts +30 -13
  136. package/src/utils/abi/decodeFunctionData.test.ts +0 -1
  137. package/src/utils/abi/decodeFunctionResult.test.ts +80 -9
  138. package/src/utils/abi/decodeFunctionResult.ts +15 -11
  139. package/src/utils/abi/encodeAbi.test.ts +3 -4
  140. package/src/utils/abi/encodeAbi.ts +19 -10
  141. package/src/utils/abi/encodeDeployData.test.ts +6 -13
  142. package/src/utils/abi/encodeDeployData.ts +10 -7
  143. package/src/utils/abi/encodeErrorResult.test.ts +2 -7
  144. package/src/utils/abi/encodeErrorResult.ts +18 -11
  145. package/src/utils/abi/encodeEventTopics.test.ts +11 -14
  146. package/src/utils/abi/encodeEventTopics.ts +15 -9
  147. package/src/utils/abi/encodeFunctionData.test.ts +5 -7
  148. package/src/utils/abi/encodeFunctionData.ts +16 -9
  149. package/src/utils/abi/encodeFunctionResult.test.ts +10 -15
  150. package/src/utils/abi/encodeFunctionResult.ts +9 -7
  151. package/src/utils/abi/getAbiItem.test.ts +547 -0
  152. package/src/utils/abi/getAbiItem.ts +93 -3
  153. package/src/utils/abi/index.ts +5 -1
  154. package/src/utils/address/getAddress.test.ts +6 -6
  155. package/src/utils/contract/getContractError.test.ts +247 -62
  156. package/src/utils/contract/getContractError.ts +30 -38
  157. package/src/utils/data/pad.bench.ts +0 -9
  158. package/src/utils/data/trim.bench.ts +0 -16
  159. package/src/utils/encoding/encodeBytes.bench.ts +0 -12
  160. package/src/utils/encoding/encodeHex.bench.ts +0 -11
  161. package/src/utils/ens/index.test.ts +13 -0
  162. package/src/utils/ens/index.ts +5 -0
  163. package/src/utils/ens/labelhash.test.ts +55 -0
  164. package/src/utils/ens/labelhash.ts +16 -0
  165. package/src/utils/ens/namehash.test.ts +65 -0
  166. package/src/utils/ens/namehash.ts +28 -0
  167. package/src/utils/ens/normalize.bench.ts +14 -0
  168. package/src/utils/ens/normalize.test.ts +35 -0
  169. package/src/utils/ens/normalize.ts +14 -0
  170. package/src/utils/hash/keccak256.ts +3 -5
  171. package/src/utils/index.test.ts +3 -0
  172. package/src/utils/index.ts +4 -0
  173. package/src/utils/rpc.test.ts +3 -6
  174. package/src/utils/unit/formatUnit.bench.ts +0 -5
  175. package/src/utils/unit/parseUnit.bench.ts +0 -5
  176. package/dist/chunk-46BO7YAQ.mjs.map +0 -1
  177. package/dist/chunk-62VTYU2V.mjs.map +0 -1
  178. package/dist/chunk-DGO77E2H.mjs.map +0 -1
  179. package/dist/chunk-KEHGSYDO.js.map +0 -1
  180. package/dist/chunk-KZMJR27B.js.map +0 -1
  181. package/dist/chunk-O2GYLJVD.js.map +0 -1
@@ -7,19 +7,15 @@
7
7
 
8
8
  import { describe, expect, test } from 'vitest'
9
9
  import {
10
- accounts,
10
+ address,
11
+ initialBlockNumber,
11
12
  publicClient,
12
- testClient,
13
13
  wagmiContractConfig,
14
- walletClient,
15
14
  } from '../../_test'
16
15
  import { baycContractConfig } from '../../_test/abis'
17
- import { encodeFunctionData } from '../../utils'
18
- import { mine } from '../test'
19
- import { sendTransaction } from '../wallet'
16
+ import { errorsExampleABI } from '../../_test/generated'
17
+ import { deployErrorExample } from '../../_test/utils'
20
18
 
21
- import { deployContract } from './deployContract'
22
- import { getTransactionReceipt } from './getTransactionReceipt'
23
19
  import { readContract } from './readContract'
24
20
 
25
21
  describe('wagmi', () => {
@@ -86,10 +82,226 @@ describe('wagmi', () => {
86
82
  expect(
87
83
  await readContract(publicClient, {
88
84
  ...wagmiContractConfig,
85
+ blockNumber: initialBlockNumber,
89
86
  functionName: 'totalSupply',
90
87
  }),
91
88
  ).toEqual(558n)
92
89
  })
90
+
91
+ test('overloaded function', async () => {
92
+ expect(
93
+ await readContract(publicClient, {
94
+ ...wagmiContractConfig,
95
+ abi: [
96
+ {
97
+ inputs: [{ type: 'uint256', name: 'x' }],
98
+ name: 'balanceOf',
99
+ outputs: [{ type: 'address', name: 'x' }],
100
+ stateMutability: 'pure',
101
+ type: 'function',
102
+ },
103
+ ...wagmiContractConfig.abi,
104
+ ],
105
+ functionName: 'balanceOf',
106
+ args: ['0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'],
107
+ }),
108
+ ).toEqual(3n)
109
+ })
110
+ })
111
+
112
+ describe('bayc', () => {
113
+ test('revert', async () => {
114
+ await expect(() =>
115
+ readContract(publicClient, {
116
+ ...baycContractConfig,
117
+ functionName: 'tokenOfOwnerByIndex',
118
+ args: [address.vitalik, 5n],
119
+ }),
120
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
121
+ "The contract function \\"tokenOfOwnerByIndex\\" reverted with the following reason:
122
+ EnumerableSet: index out of bounds
123
+
124
+ Contract: 0x0000000000000000000000000000000000000000
125
+ Function: tokenOfOwnerByIndex(address owner, uint256 index)
126
+ Arguments: (0xd8da6bf26964af9d7eed9e03e53415d37aa96045, 5)
127
+
128
+ Docs: https://viem.sh/docs/contract/readContract
129
+ Version: viem@1.0.2"
130
+ `)
131
+ })
132
+
133
+ test('revert', async () => {
134
+ await expect(() =>
135
+ readContract(publicClient, {
136
+ ...baycContractConfig,
137
+ functionName: 'ownerOf',
138
+ args: [420213123123n],
139
+ }),
140
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
141
+ "The contract function \\"ownerOf\\" reverted with the following reason:
142
+ ERC721: owner query for nonexistent token
143
+
144
+ Contract: 0x0000000000000000000000000000000000000000
145
+ Function: ownerOf(uint256 tokenId)
146
+ Arguments: (420213123123)
147
+
148
+ Docs: https://viem.sh/docs/contract/readContract
149
+ Version: viem@1.0.2"
150
+ `)
151
+ })
152
+ })
153
+
154
+ describe('contract errors', () => {
155
+ test('revert', async () => {
156
+ const { contractAddress } = await deployErrorExample()
157
+
158
+ await expect(() =>
159
+ readContract(publicClient, {
160
+ abi: errorsExampleABI,
161
+ address: contractAddress!,
162
+ functionName: 'revertRead',
163
+ }),
164
+ ).rejects.toMatchInlineSnapshot(`
165
+ [ContractFunctionExecutionError: The contract function "revertRead" reverted with the following reason:
166
+ This is a revert message
167
+
168
+ Contract: 0x0000000000000000000000000000000000000000
169
+ Function: revertRead()
170
+
171
+ Docs: https://viem.sh/docs/contract/readContract
172
+ Version: viem@1.0.2]
173
+ `)
174
+ })
175
+
176
+ test('assert', async () => {
177
+ const { contractAddress } = await deployErrorExample()
178
+
179
+ await expect(() =>
180
+ readContract(publicClient, {
181
+ abi: errorsExampleABI,
182
+ address: contractAddress!,
183
+ functionName: 'assertRead',
184
+ }),
185
+ ).rejects.toMatchInlineSnapshot(`
186
+ [ContractFunctionExecutionError: The contract function "assertRead" reverted with the following reason:
187
+ An \`assert\` condition failed.
188
+
189
+ Contract: 0x0000000000000000000000000000000000000000
190
+ Function: assertRead()
191
+
192
+ Docs: https://viem.sh/docs/contract/readContract
193
+ Version: viem@1.0.2]
194
+ `)
195
+ })
196
+
197
+ test('overflow', async () => {
198
+ const { contractAddress } = await deployErrorExample()
199
+
200
+ await expect(() =>
201
+ readContract(publicClient, {
202
+ abi: errorsExampleABI,
203
+ address: contractAddress!,
204
+ functionName: 'overflowRead',
205
+ }),
206
+ ).rejects.toMatchInlineSnapshot(`
207
+ [ContractFunctionExecutionError: The contract function "overflowRead" reverted with the following reason:
208
+ Arithmic operation resulted in underflow or overflow.
209
+
210
+ Contract: 0x0000000000000000000000000000000000000000
211
+ Function: overflowRead()
212
+
213
+ Docs: https://viem.sh/docs/contract/readContract
214
+ Version: viem@1.0.2]
215
+ `)
216
+ })
217
+
218
+ test('divide by zero', async () => {
219
+ const { contractAddress } = await deployErrorExample()
220
+
221
+ await expect(() =>
222
+ readContract(publicClient, {
223
+ abi: errorsExampleABI,
224
+ address: contractAddress!,
225
+ functionName: 'divideByZeroRead',
226
+ }),
227
+ ).rejects.toMatchInlineSnapshot(`
228
+ [ContractFunctionExecutionError: The contract function "divideByZeroRead" reverted with the following reason:
229
+ Division or modulo by zero (e.g. \`5 / 0\` or \`23 % 0\`).
230
+
231
+ Contract: 0x0000000000000000000000000000000000000000
232
+ Function: divideByZeroRead()
233
+
234
+ Docs: https://viem.sh/docs/contract/readContract
235
+ Version: viem@1.0.2]
236
+ `)
237
+ })
238
+
239
+ test('require', async () => {
240
+ const { contractAddress } = await deployErrorExample()
241
+
242
+ await expect(() =>
243
+ readContract(publicClient, {
244
+ abi: errorsExampleABI,
245
+ address: contractAddress!,
246
+ functionName: 'requireRead',
247
+ }),
248
+ ).rejects.toMatchInlineSnapshot(`
249
+ [ContractFunctionExecutionError: The contract function "requireRead" reverted with the following reason:
250
+ execution reverted
251
+
252
+ Contract: 0x0000000000000000000000000000000000000000
253
+ Function: requireRead()
254
+
255
+ Docs: https://viem.sh/docs/contract/readContract
256
+ Version: viem@1.0.2]
257
+ `)
258
+ })
259
+
260
+ test('custom error: simple', async () => {
261
+ const { contractAddress } = await deployErrorExample()
262
+
263
+ await expect(() =>
264
+ readContract(publicClient, {
265
+ abi: errorsExampleABI,
266
+ address: contractAddress!,
267
+ functionName: 'simpleCustomRead',
268
+ }),
269
+ ).rejects.toMatchInlineSnapshot(`
270
+ [ContractFunctionExecutionError: The contract function "simpleCustomRead" reverted.
271
+
272
+ Error: SimpleError(string message)
273
+ Arguments: (bugger)
274
+
275
+ Contract: 0x0000000000000000000000000000000000000000
276
+ Function: simpleCustomRead()
277
+
278
+ Docs: https://viem.sh/docs/contract/readContract
279
+ Version: viem@1.0.2]
280
+ `)
281
+ })
282
+
283
+ test('custom error: complex', async () => {
284
+ const { contractAddress } = await deployErrorExample()
285
+
286
+ await expect(() =>
287
+ readContract(publicClient, {
288
+ abi: errorsExampleABI,
289
+ address: contractAddress!,
290
+ functionName: 'complexCustomRead',
291
+ }),
292
+ ).rejects.toMatchInlineSnapshot(`
293
+ [ContractFunctionExecutionError: The contract function "complexCustomRead" reverted.
294
+
295
+ Error: ComplexError((address sender, uint256 bar), string message, uint256 number)
296
+ Arguments: ({"sender":"0x0000000000000000000000000000000000000000","bar":"69"}, bugger, 69)
297
+
298
+ Contract: 0x0000000000000000000000000000000000000000
299
+ Function: complexCustomRead()
300
+
301
+ Docs: https://viem.sh/docs/contract/readContract
302
+ Version: viem@1.0.2]
303
+ `)
304
+ })
93
305
  })
94
306
 
95
307
  test('fake contract address', async () => {
@@ -100,29 +312,17 @@ test('fake contract address', async () => {
100
312
  functionName: 'totalSupply',
101
313
  }),
102
314
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
103
- "The contract method \\"totalSupply\\" returned no data (\\"0x\\"). This could be due to any of the following:
315
+ "The contract function \\"totalSupply\\" returned no data (\\"0x\\").
316
+
317
+ This could be due to any of the following:
104
318
  - The contract does not have the function \\"totalSupply\\",
105
319
  - The parameters passed to the contract function may be invalid, or
106
320
  - The address is not a contract.
107
321
 
108
- Contract: 0x0000000000000000000000000000000000000000
109
- Function: totalSupply()
110
- > \\"0x\\"
322
+ Contract: 0x0000000000000000000000000000000000000000
323
+ Function: totalSupply()
111
324
 
325
+ Docs: https://viem.sh/docs/contract/readContract
112
326
  Version: viem@1.0.2"
113
327
  `)
114
328
  })
115
-
116
- // Deploy BAYC Contract
117
- async function deployBAYC() {
118
- const hash = await deployContract(walletClient, {
119
- ...baycContractConfig,
120
- args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n],
121
- from: accounts[0].address,
122
- })
123
- await mine(testClient, { blocks: 1 })
124
- const { contractAddress } = await getTransactionReceipt(publicClient, {
125
- hash,
126
- })
127
- return { contractAddress }
128
- }
@@ -1,11 +1,10 @@
1
1
  import { Abi } from 'abitype'
2
2
 
3
3
  import type { PublicClient } from '../../clients'
4
+ import { BaseError } from '../../errors'
4
5
  import type {
5
- Address,
6
- ExtractArgsFromAbi,
6
+ ContractConfig,
7
7
  ExtractResultFromAbi,
8
- ExtractFunctionNameFromAbi,
9
8
  Formatter,
10
9
  } from '../../types'
11
10
  import {
@@ -13,6 +12,7 @@ import {
13
12
  decodeFunctionResult,
14
13
  encodeFunctionData,
15
14
  getContractError,
15
+ DecodeFunctionResultArgs,
16
16
  } from '../../utils'
17
17
  import { call, CallArgs, FormattedCall } from './call'
18
18
 
@@ -22,25 +22,9 @@ export type FormattedReadContract<
22
22
 
23
23
  export type ReadContractArgs<
24
24
  TAbi extends Abi | readonly unknown[] = Abi,
25
- TFunctionName extends string = any,
26
- > = Omit<
27
- CallArgs,
28
- | 'accessList'
29
- | 'chain'
30
- | 'from'
31
- | 'gas'
32
- | 'gasPrice'
33
- | 'maxFeePerGas'
34
- | 'maxPriorityFeePerGas'
35
- | 'nonce'
36
- | 'to'
37
- | 'data'
38
- | 'value'
39
- > & {
40
- address: Address
41
- abi: TAbi
42
- functionName: ExtractFunctionNameFromAbi<TAbi, TFunctionName, 'pure' | 'view'>
43
- } & ExtractArgsFromAbi<TAbi, TFunctionName>
25
+ TFunctionName extends string = string,
26
+ > = Pick<CallArgs, 'blockNumber' | 'blockTag'> &
27
+ ContractConfig<TAbi, TFunctionName, 'view' | 'pure'>
44
28
 
45
29
  export type ReadContractResponse<
46
30
  TAbi extends Abi | readonly unknown[] = Abi,
@@ -48,8 +32,8 @@ export type ReadContractResponse<
48
32
  > = ExtractResultFromAbi<TAbi, TFunctionName>
49
33
 
50
34
  export async function readContract<
51
- TAbi extends Abi = Abi,
52
- TFunctionName extends string = any,
35
+ TAbi extends Abi | readonly unknown[],
36
+ TFunctionName extends string,
53
37
  >(
54
38
  client: PublicClient,
55
39
  {
@@ -73,14 +57,16 @@ export async function readContract<
73
57
  } as unknown as CallArgs)
74
58
  return decodeFunctionResult({
75
59
  abi,
60
+ args,
76
61
  functionName,
77
62
  data: data || '0x',
78
- })
63
+ } as DecodeFunctionResultArgs<TAbi, TFunctionName>)
79
64
  } catch (err) {
80
- throw getContractError(err, {
81
- abi,
65
+ throw getContractError(err as BaseError, {
66
+ abi: abi as Abi,
82
67
  address,
83
68
  args,
69
+ docsPath: '/docs/contract/readContract',
84
70
  functionName,
85
71
  })
86
72
  }
@@ -1,4 +1,5 @@
1
1
  import { Contract } from 'ethers'
2
+ import { Contract as ContractV6 } from 'ethers@6'
2
3
  import { bench, describe } from 'vitest'
3
4
 
4
5
  import {
@@ -28,4 +29,13 @@ describe('Simulate Contract', () => {
28
29
  )
29
30
  await wagmi.callStatic.mint(1)
30
31
  })
32
+
33
+ bench('ethers@6: `callStatic`', async () => {
34
+ const wagmi = new ContractV6(
35
+ wagmiContractConfig.address,
36
+ wagmiContractConfig.abi,
37
+ ethersProvider,
38
+ )
39
+ await wagmi.mint.staticCall(1)
40
+ })
31
41
  })