viem 0.0.1-alpha.9 → 0.0.1-sushi.25

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 (533) hide show
  1. package/chains/package.json +1 -1
  2. package/contract/package.json +4 -0
  3. package/dist/call-ac509982.d.ts +23 -0
  4. package/dist/chain-c4ccb458.d.ts +5 -0
  5. package/dist/{rpc-b77c5aee.d.ts → chain-f16512e8.d.ts} +97 -17
  6. package/dist/chains.d.ts +1303 -74
  7. package/dist/chains.js +125 -130
  8. package/dist/chains.js.map +1 -0
  9. package/dist/chains.mjs +129 -0
  10. package/dist/chains.mjs.map +1 -0
  11. package/dist/chunk-KLKNITD2.mjs +192 -0
  12. package/dist/chunk-KLKNITD2.mjs.map +1 -0
  13. package/dist/chunk-LBSHIBU7.js +3026 -0
  14. package/dist/chunk-LBSHIBU7.js.map +1 -0
  15. package/dist/chunk-N2P6N5ML.js +1091 -0
  16. package/dist/chunk-N2P6N5ML.js.map +1 -0
  17. package/dist/{chunk-6BXRN6CQ.js → chunk-P73S5JV4.mjs} +526 -482
  18. package/dist/chunk-P73S5JV4.mjs.map +1 -0
  19. package/dist/chunk-VVAGEIV2.js +192 -0
  20. package/dist/chunk-VVAGEIV2.js.map +1 -0
  21. package/dist/chunk-ZRHPJRBJ.mjs +3026 -0
  22. package/dist/chunk-ZRHPJRBJ.mjs.map +1 -0
  23. package/dist/contract-9e76e561.d.ts +166 -0
  24. package/dist/contract.d.ts +123 -0
  25. package/dist/contract.js +53 -0
  26. package/dist/contract.js.map +1 -0
  27. package/dist/contract.mjs +53 -0
  28. package/dist/contract.mjs.map +1 -0
  29. package/dist/createClient-68ee4bb4.d.ts +62 -0
  30. package/dist/createPublicClient-b732194e.d.ts +19 -0
  31. package/dist/createTestClient-dedf321e.d.ts +34 -0
  32. package/dist/createWalletClient-75813d83.d.ts +30 -0
  33. package/dist/decodeErrorResult-0b934d23.d.ts +16 -0
  34. package/dist/{eip1193-020a6f13.d.ts → eip1193-6f9ba163.d.ts} +12 -9
  35. package/dist/ens.d.ts +82 -0
  36. package/dist/ens.js +216 -0
  37. package/dist/ens.js.map +1 -0
  38. package/dist/ens.mjs +216 -0
  39. package/dist/ens.mjs.map +1 -0
  40. package/dist/getAbiItem-c8e6e7d4.d.ts +97 -0
  41. package/dist/index.d.ts +128 -35
  42. package/dist/index.js +370 -374
  43. package/dist/index.js.map +1 -0
  44. package/dist/{chunk-375SRM5R.js → index.mjs} +122 -10
  45. package/dist/index.mjs.map +1 -0
  46. package/dist/public.d.ts +353 -0
  47. package/dist/public.js +58 -0
  48. package/dist/public.js.map +1 -0
  49. package/dist/public.mjs +58 -0
  50. package/dist/public.mjs.map +1 -0
  51. package/dist/readContract-4f6e2692.d.ts +10 -0
  52. package/dist/rpc-a5a7f376.d.ts +121 -0
  53. package/dist/sendTransaction-e713f90c.d.ts +12 -0
  54. package/dist/test.d.ts +161 -0
  55. package/dist/test.js +264 -0
  56. package/dist/test.js.map +1 -0
  57. package/dist/test.mjs +264 -0
  58. package/dist/test.mjs.map +1 -0
  59. package/dist/transactionReceipt-2a86c7c7.d.ts +26 -0
  60. package/dist/transactionRequest-c7794f5e.d.ts +15 -0
  61. package/dist/utils/index.d.ts +255 -8
  62. package/dist/utils/index.js +173 -138
  63. package/dist/utils/index.js.map +1 -0
  64. package/dist/utils/index.mjs +173 -0
  65. package/dist/utils/index.mjs.map +1 -0
  66. package/dist/wallet.d.ts +42 -0
  67. package/dist/wallet.js +24 -0
  68. package/dist/wallet.js.map +1 -0
  69. package/dist/wallet.mjs +24 -0
  70. package/dist/wallet.mjs.map +1 -0
  71. package/dist/watchEvent-c346c12d.d.ts +41 -0
  72. package/dist/window.d.ts +3 -2
  73. package/dist/window.js +1 -0
  74. package/dist/window.js.map +1 -0
  75. package/dist/window.mjs +1 -0
  76. package/dist/window.mjs.map +1 -0
  77. package/ens/package.json +4 -0
  78. package/package.json +45 -71
  79. package/src/_test/abis.ts +1420 -0
  80. package/src/_test/bench.ts +15 -0
  81. package/src/_test/constants.ts +63 -0
  82. package/src/_test/generated.ts +128 -0
  83. package/src/_test/globalSetup.ts +11 -0
  84. package/src/_test/index.ts +25 -0
  85. package/src/_test/setup.ts +8 -0
  86. package/src/_test/utils.ts +155 -0
  87. package/src/actions/ens/getEnsAddress.bench.ts +26 -0
  88. package/src/actions/ens/getEnsAddress.test.ts +97 -0
  89. package/src/actions/ens/getEnsAddress.ts +122 -0
  90. package/src/actions/ens/getEnsName.bench.ts +30 -0
  91. package/src/actions/ens/getEnsName.test.ts +101 -0
  92. package/src/actions/ens/getEnsName.ts +106 -0
  93. package/src/actions/ens/index.test.ts +12 -0
  94. package/src/actions/ens/index.ts +3 -0
  95. package/src/actions/index.test.ts +81 -0
  96. package/src/actions/index.ts +182 -0
  97. package/src/actions/public/call.bench.ts +48 -0
  98. package/src/actions/public/call.test.ts +99 -0
  99. package/src/actions/public/call.ts +97 -0
  100. package/src/actions/public/createBlockFilter.bench.ts +11 -0
  101. package/src/actions/public/createBlockFilter.test.ts +9 -0
  102. package/src/actions/public/createBlockFilter.ts +14 -0
  103. package/src/actions/public/createContractEventFilter.test.ts +119 -0
  104. package/src/actions/public/createContractEventFilter.ts +69 -0
  105. package/src/actions/public/createEventFilter.test.ts +277 -0
  106. package/src/actions/public/createEventFilter.ts +93 -0
  107. package/src/actions/public/createPendingTransactionFilter.bench.ts +11 -0
  108. package/src/actions/public/createPendingTransactionFilter.test.ts +9 -0
  109. package/src/actions/public/createPendingTransactionFilter.ts +14 -0
  110. package/src/actions/public/estimateGas.bench.ts +46 -0
  111. package/src/actions/public/estimateGas.test.ts +92 -0
  112. package/src/actions/public/estimateGas.ts +61 -0
  113. package/src/actions/public/getBalance.test.ts +83 -0
  114. package/src/actions/public/getBalance.ts +37 -0
  115. package/src/actions/public/getBlock.bench.ts +28 -0
  116. package/src/actions/public/getBlock.test.ts +575 -0
  117. package/src/actions/public/getBlock.ts +65 -0
  118. package/src/actions/public/getBlockNumber.bench.ts +28 -0
  119. package/src/actions/public/getBlockNumber.test.ts +27 -0
  120. package/src/actions/public/getBlockNumber.ts +32 -0
  121. package/src/actions/public/getBlockTransactionCount.bench.ts +15 -0
  122. package/src/actions/public/getBlockTransactionCount.test.ts +57 -0
  123. package/src/actions/public/getBlockTransactionCount.ts +52 -0
  124. package/src/actions/public/getBytecode.test.ts +27 -0
  125. package/src/actions/public/getBytecode.ts +32 -0
  126. package/src/actions/public/getChainId.bench.ts +15 -0
  127. package/src/actions/public/getChainId.test.ts +8 -0
  128. package/src/actions/public/getChainId.ts +7 -0
  129. package/src/actions/public/getFeeHistory.bench.ts +18 -0
  130. package/src/actions/public/getFeeHistory.test.ts +137 -0
  131. package/src/actions/public/getFeeHistory.ts +44 -0
  132. package/src/actions/public/getFilterChanges.bench.ts +13 -0
  133. package/src/actions/public/getFilterChanges.test.ts +383 -0
  134. package/src/actions/public/getFilterChanges.ts +23 -0
  135. package/src/actions/public/getFilterLogs.test.ts +297 -0
  136. package/src/actions/public/getFilterLogs.ts +20 -0
  137. package/src/actions/public/getGasPrice.bench.ts +19 -0
  138. package/src/actions/public/getGasPrice.test.ts +8 -0
  139. package/src/actions/public/getGasPrice.ts +15 -0
  140. package/src/actions/public/getLogs.test.ts +306 -0
  141. package/src/actions/public/getLogs.ts +84 -0
  142. package/src/actions/public/getStorageAt.test.ts +34 -0
  143. package/src/actions/public/getStorageAt.ts +32 -0
  144. package/src/actions/public/getTransaction.bench.ts +33 -0
  145. package/src/actions/public/getTransaction.test.ts +311 -0
  146. package/src/actions/public/getTransaction.ts +95 -0
  147. package/src/actions/public/getTransactionConfirmations.test.ts +69 -0
  148. package/src/actions/public/getTransactionConfirmations.ts +38 -0
  149. package/src/actions/public/getTransactionCount.test.ts +56 -0
  150. package/src/actions/public/getTransactionCount.ts +34 -0
  151. package/src/actions/public/getTransactionReceipt.bench.ts +33 -0
  152. package/src/actions/public/getTransactionReceipt.test.ts +179 -0
  153. package/src/actions/public/getTransactionReceipt.ts +34 -0
  154. package/src/actions/public/index.test.ts +43 -0
  155. package/src/actions/public/index.ts +146 -0
  156. package/src/actions/public/multicall.test.ts +452 -0
  157. package/src/actions/public/multicall.ts +108 -0
  158. package/src/actions/public/readContract.test.ts +328 -0
  159. package/src/actions/public/readContract.ts +73 -0
  160. package/src/actions/public/simulateContract.bench.ts +41 -0
  161. package/src/actions/public/simulateContract.test.ts +410 -0
  162. package/src/actions/public/simulateContract.ts +91 -0
  163. package/src/actions/public/uninstallFilter.bench.ts +13 -0
  164. package/src/actions/public/uninstallFilter.test.ts +65 -0
  165. package/src/actions/public/uninstallFilter.ts +17 -0
  166. package/src/actions/public/waitForTransactionReceipt.test.ts +322 -0
  167. package/src/actions/public/waitForTransactionReceipt.ts +170 -0
  168. package/src/actions/public/watchBlockNumber.test.ts +166 -0
  169. package/src/actions/public/watchBlockNumber.ts +79 -0
  170. package/src/actions/public/watchBlocks.test.ts +210 -0
  171. package/src/actions/public/watchBlocks.ts +114 -0
  172. package/src/actions/public/watchContractEvent.test.ts +305 -0
  173. package/src/actions/public/watchContractEvent.ts +108 -0
  174. package/src/actions/public/watchEvent.test.ts +195 -0
  175. package/src/actions/public/watchEvent.ts +95 -0
  176. package/src/actions/public/watchPendingTransactions.test.ts +116 -0
  177. package/src/actions/public/watchPendingTransactions.ts +74 -0
  178. package/src/actions/test/dropTransaction.test.ts +34 -0
  179. package/src/actions/test/dropTransaction.ts +17 -0
  180. package/src/actions/test/getAutomine.test.ts +14 -0
  181. package/src/actions/test/getAutomine.ts +11 -0
  182. package/src/actions/test/getTxpoolContent.test.ts +45 -0
  183. package/src/actions/test/getTxpoolContent.ts +7 -0
  184. package/src/actions/test/getTxpoolStatus.test.ts +41 -0
  185. package/src/actions/test/getTxpoolStatus.ts +12 -0
  186. package/src/actions/test/impersonateAccount.test.ts +26 -0
  187. package/src/actions/test/impersonateAccount.ts +17 -0
  188. package/src/actions/test/increaseTime.test.ts +18 -0
  189. package/src/actions/test/increaseTime.ts +17 -0
  190. package/src/actions/test/index.test.ts +38 -0
  191. package/src/actions/test/index.ts +77 -0
  192. package/src/actions/test/inspectTxpool.test.ts +50 -0
  193. package/src/actions/test/inspectTxpool.ts +7 -0
  194. package/src/actions/test/mine.test.ts +20 -0
  195. package/src/actions/test/mine.ts +16 -0
  196. package/src/actions/test/removeBlockTimestampInterval.test.ts +23 -0
  197. package/src/actions/test/removeBlockTimestampInterval.ts +7 -0
  198. package/src/actions/test/reset.test.ts +19 -0
  199. package/src/actions/test/reset.ts +18 -0
  200. package/src/actions/test/revert.test.ts +39 -0
  201. package/src/actions/test/revert.ts +14 -0
  202. package/src/actions/test/sendUnsignedTransaction.test.ts +52 -0
  203. package/src/actions/test/sendUnsignedTransaction.ts +19 -0
  204. package/src/actions/test/setAutomine.test.ts +14 -0
  205. package/src/actions/test/setAutomine.ts +8 -0
  206. package/src/actions/test/setBalance.test.ts +29 -0
  207. package/src/actions/test/setBalance.ts +20 -0
  208. package/src/actions/test/setBlockGasLimit.test.ts +21 -0
  209. package/src/actions/test/setBlockGasLimit.ts +17 -0
  210. package/src/actions/test/setBlockTimestampInterval.test.ts +23 -0
  211. package/src/actions/test/setBlockTimestampInterval.ts +16 -0
  212. package/src/actions/test/setCode.test.ts +26 -0
  213. package/src/actions/test/setCode.ts +19 -0
  214. package/src/actions/test/setCoinbase.test.ts +11 -0
  215. package/src/actions/test/setCoinbase.ts +17 -0
  216. package/src/actions/test/setIntervalMining.test.ts +30 -0
  217. package/src/actions/test/setIntervalMining.ts +16 -0
  218. package/src/actions/test/setLoggingEnabled.test.ts +10 -0
  219. package/src/actions/test/setLoggingEnabled.ts +8 -0
  220. package/src/actions/test/setMinGasPrice.test.ts +22 -0
  221. package/src/actions/test/setMinGasPrice.ts +17 -0
  222. package/src/actions/test/setNextBlockBaseFeePerGas.test.ts +23 -0
  223. package/src/actions/test/setNextBlockBaseFeePerGas.ts +17 -0
  224. package/src/actions/test/setNextBlockTimestamp.test.ts +19 -0
  225. package/src/actions/test/setNextBlockTimestamp.ts +17 -0
  226. package/src/actions/test/setNonce.test.ts +28 -0
  227. package/src/actions/test/setNonce.ts +20 -0
  228. package/src/actions/test/setRpcUrl.test.ts +9 -0
  229. package/src/actions/test/setRpcUrl.ts +8 -0
  230. package/src/actions/test/setStorageAt.test.ts +36 -0
  231. package/src/actions/test/setStorageAt.ts +26 -0
  232. package/src/actions/test/snapshot.test.ts +18 -0
  233. package/src/actions/test/snapshot.ts +7 -0
  234. package/src/actions/test/stopImpersonatingAccount.test.ts +29 -0
  235. package/src/actions/test/stopImpersonatingAccount.ts +17 -0
  236. package/src/actions/wallet/addChain.test.ts +14 -0
  237. package/src/actions/wallet/addChain.ts +21 -0
  238. package/src/actions/wallet/deployContract.test.ts +55 -0
  239. package/src/actions/wallet/deployContract.ts +38 -0
  240. package/src/actions/wallet/getAccounts.test.ts +22 -0
  241. package/src/actions/wallet/getAccounts.ts +7 -0
  242. package/src/actions/wallet/getPermissions.test.ts +24 -0
  243. package/src/actions/wallet/getPermissions.ts +9 -0
  244. package/src/actions/wallet/index.test.ts +21 -0
  245. package/src/actions/wallet/index.ts +36 -0
  246. package/src/actions/wallet/requestAccounts.test.ts +13 -0
  247. package/src/actions/wallet/requestAccounts.ts +7 -0
  248. package/src/actions/wallet/requestPermissions.test.ts +26 -0
  249. package/src/actions/wallet/requestPermissions.ts +19 -0
  250. package/src/actions/wallet/sendTransaction.bench.ts +57 -0
  251. package/src/actions/wallet/sendTransaction.test.ts +440 -0
  252. package/src/actions/wallet/sendTransaction.ts +77 -0
  253. package/src/actions/wallet/signMessage.test.ts +61 -0
  254. package/src/actions/wallet/signMessage.ts +35 -0
  255. package/src/actions/wallet/switchChain.test.ts +21 -0
  256. package/src/actions/wallet/switchChain.ts +19 -0
  257. package/src/actions/wallet/watchAsset.test.ts +40 -0
  258. package/src/actions/wallet/watchAsset.ts +16 -0
  259. package/src/actions/wallet/writeContract.test.ts +84 -0
  260. package/src/actions/wallet/writeContract.ts +47 -0
  261. package/src/chains.test.ts +439 -0
  262. package/src/chains.ts +99 -0
  263. package/src/clients/createClient.test.ts +295 -0
  264. package/src/clients/createClient.ts +81 -0
  265. package/src/clients/createPublicClient.test.ts +165 -0
  266. package/src/clients/createPublicClient.ts +49 -0
  267. package/src/clients/createTestClient.test.ts +145 -0
  268. package/src/clients/createTestClient.ts +72 -0
  269. package/src/clients/createWalletClient.test.ts +121 -0
  270. package/src/clients/createWalletClient.ts +54 -0
  271. package/src/clients/index.test.ts +19 -0
  272. package/src/clients/index.ts +31 -0
  273. package/src/clients/transports/createTransport.test.ts +58 -0
  274. package/src/clients/transports/createTransport.ts +48 -0
  275. package/src/clients/transports/custom.test.ts +98 -0
  276. package/src/clients/transports/custom.ts +34 -0
  277. package/src/clients/transports/fallback.test.ts +393 -0
  278. package/src/clients/transports/fallback.ts +58 -0
  279. package/src/clients/transports/http.test.ts +109 -0
  280. package/src/clients/transports/http.ts +51 -0
  281. package/src/clients/transports/index.test.ts +15 -0
  282. package/src/clients/transports/index.ts +17 -0
  283. package/src/clients/transports/webSocket.test.ts +164 -0
  284. package/src/clients/transports/webSocket.ts +118 -0
  285. package/src/constants/abis.test.ts +53 -0
  286. package/src/constants/abis.ts +44 -0
  287. package/src/constants/index.test.ts +14 -0
  288. package/src/constants/index.ts +3 -0
  289. package/src/constants/solidity.test.ts +41 -0
  290. package/src/constants/solidity.ts +35 -0
  291. package/src/contract.test.ts +32 -0
  292. package/src/contract.ts +68 -0
  293. package/src/ens.test.ts +15 -0
  294. package/src/ens.ts +8 -0
  295. package/src/errors/abi.test.ts +81 -0
  296. package/src/errors/abi.ts +254 -0
  297. package/src/errors/address.test.ts +14 -0
  298. package/src/errors/address.ts +9 -0
  299. package/src/errors/base.test.ts +114 -0
  300. package/src/errors/base.ts +57 -0
  301. package/src/errors/block.test.ts +24 -0
  302. package/src/errors/block.ts +18 -0
  303. package/src/errors/chain.test.ts +46 -0
  304. package/src/errors/chain.ts +33 -0
  305. package/src/errors/contract.test.ts +233 -0
  306. package/src/errors/contract.ts +178 -0
  307. package/src/errors/data.ts +20 -0
  308. package/src/errors/encoding.ts +60 -0
  309. package/src/errors/index.ts +82 -0
  310. package/src/errors/log.ts +8 -0
  311. package/src/errors/request.test.ts +330 -0
  312. package/src/errors/request.ts +163 -0
  313. package/src/errors/rpc.test.ts +87 -0
  314. package/src/errors/rpc.ts +113 -0
  315. package/src/errors/transaction.test.ts +83 -0
  316. package/src/errors/transaction.ts +54 -0
  317. package/src/errors/transport.test.ts +11 -0
  318. package/src/errors/transport.ts +12 -0
  319. package/src/index.test.ts +116 -0
  320. package/src/index.ts +132 -0
  321. package/src/public.test.ts +36 -0
  322. package/src/public.ts +76 -0
  323. package/src/test.test.ts +38 -0
  324. package/src/test.ts +52 -0
  325. package/src/types/block.ts +71 -0
  326. package/src/types/chain.ts +6 -0
  327. package/src/types/contract.ts +497 -0
  328. package/src/types/eip1193.ts +1041 -0
  329. package/src/types/fee.ts +47 -0
  330. package/src/types/filter.ts +8 -0
  331. package/src/types/formatter.ts +23 -0
  332. package/src/types/index.ts +84 -0
  333. package/src/types/log.ts +22 -0
  334. package/src/types/misc.ts +5 -0
  335. package/src/types/multicall.ts +82 -0
  336. package/src/types/rpc.ts +35 -0
  337. package/src/types/transaction.ts +145 -0
  338. package/src/types/utils.ts +88 -0
  339. package/src/types/window.ts +9 -0
  340. package/src/utils/abi/decodeAbi.bench.ts +135 -0
  341. package/src/utils/abi/decodeAbi.test.ts +1614 -0
  342. package/src/utils/abi/decodeAbi.ts +300 -0
  343. package/src/utils/abi/decodeDeployData.test.ts +151 -0
  344. package/src/utils/abi/decodeDeployData.ts +44 -0
  345. package/src/utils/abi/decodeErrorResult.test.ts +230 -0
  346. package/src/utils/abi/decodeErrorResult.ts +45 -0
  347. package/src/utils/abi/decodeEventLog.test.ts +542 -0
  348. package/src/utils/abi/decodeEventLog.ts +107 -0
  349. package/src/utils/abi/decodeFunctionData.test.ts +138 -0
  350. package/src/utils/abi/decodeFunctionData.ts +32 -0
  351. package/src/utils/abi/decodeFunctionResult.test.ts +333 -0
  352. package/src/utils/abi/decodeFunctionResult.ts +57 -0
  353. package/src/utils/abi/encodeAbi.bench.ts +163 -0
  354. package/src/utils/abi/encodeAbi.test.ts +1447 -0
  355. package/src/utils/abi/encodeAbi.ts +273 -0
  356. package/src/utils/abi/encodeDeployData.test.ts +124 -0
  357. package/src/utils/abi/encodeDeployData.ts +40 -0
  358. package/src/utils/abi/encodeErrorResult.test.ts +192 -0
  359. package/src/utils/abi/encodeErrorResult.ts +47 -0
  360. package/src/utils/abi/encodeEventTopics.test.ts +345 -0
  361. package/src/utils/abi/encodeEventTopics.ts +75 -0
  362. package/src/utils/abi/encodeFunctionData.test.ts +138 -0
  363. package/src/utils/abi/encodeFunctionData.ts +42 -0
  364. package/src/utils/abi/encodeFunctionResult.test.ts +279 -0
  365. package/src/utils/abi/encodeFunctionResult.ts +41 -0
  366. package/src/utils/abi/formatAbiItem.test.ts +335 -0
  367. package/src/utils/abi/formatAbiItem.ts +41 -0
  368. package/src/utils/abi/formatAbiItemWithArgs.test.ts +291 -0
  369. package/src/utils/abi/formatAbiItemWithArgs.ts +27 -0
  370. package/src/utils/abi/getAbiItem.test.ts +547 -0
  371. package/src/utils/abi/getAbiItem.ts +95 -0
  372. package/src/utils/abi/index.test.ts +24 -0
  373. package/src/utils/abi/index.ts +48 -0
  374. package/src/utils/address/getAddress.bench.ts +22 -0
  375. package/src/utils/address/getAddress.test.ts +46 -0
  376. package/src/utils/address/getAddress.ts +28 -0
  377. package/src/utils/address/getContractAddress.bench.ts +20 -0
  378. package/src/utils/address/getContractAddress.test.ts +78 -0
  379. package/src/utils/address/getContractAddress.ts +59 -0
  380. package/src/utils/address/index.test.ts +17 -0
  381. package/src/utils/address/index.ts +16 -0
  382. package/src/utils/address/isAddress.test.ts +10 -0
  383. package/src/utils/address/isAddress.ts +10 -0
  384. package/src/utils/address/isAddressEqual.test.ts +55 -0
  385. package/src/utils/address/isAddressEqual.ts +6 -0
  386. package/src/utils/buildRequest.test.ts +428 -0
  387. package/src/utils/buildRequest.ts +74 -0
  388. package/src/utils/chain.test.ts +43 -0
  389. package/src/utils/chain.ts +8 -0
  390. package/src/utils/contract/extractFunctionParts.test.ts +109 -0
  391. package/src/utils/contract/extractFunctionParts.ts +27 -0
  392. package/src/utils/contract/getContractError.test.ts +282 -0
  393. package/src/utils/contract/getContractError.ts +58 -0
  394. package/src/utils/contract/index.test.ts +15 -0
  395. package/src/utils/contract/index.ts +8 -0
  396. package/src/utils/data/concat.test.ts +35 -0
  397. package/src/utils/data/concat.ts +34 -0
  398. package/src/utils/data/index.test.ts +23 -0
  399. package/src/utils/data/index.ts +13 -0
  400. package/src/utils/data/isBytes.test.ts +9 -0
  401. package/src/utils/data/isBytes.ts +7 -0
  402. package/src/utils/data/isHex.test.ts +13 -0
  403. package/src/utils/data/isHex.ts +5 -0
  404. package/src/utils/data/pad.bench.ts +30 -0
  405. package/src/utils/data/pad.test.ts +367 -0
  406. package/src/utils/data/pad.ts +53 -0
  407. package/src/utils/data/size.test.ts +18 -0
  408. package/src/utils/data/size.ts +13 -0
  409. package/src/utils/data/slice.test.ts +203 -0
  410. package/src/utils/data/slice.ts +60 -0
  411. package/src/utils/data/trim.bench.ts +34 -0
  412. package/src/utils/data/trim.test.ts +175 -0
  413. package/src/utils/data/trim.ts +33 -0
  414. package/src/utils/encoding/decodeBytes.bench.ts +40 -0
  415. package/src/utils/encoding/decodeBytes.test.ts +144 -0
  416. package/src/utils/encoding/decodeBytes.ts +63 -0
  417. package/src/utils/encoding/decodeHex.bench.ts +24 -0
  418. package/src/utils/encoding/decodeHex.test.ts +167 -0
  419. package/src/utils/encoding/decodeHex.ts +76 -0
  420. package/src/utils/encoding/decodeRlp.bench.ts +34 -0
  421. package/src/utils/encoding/decodeRlp.test.ts +350 -0
  422. package/src/utils/encoding/decodeRlp.ts +121 -0
  423. package/src/utils/encoding/encodeBytes.bench.ts +29 -0
  424. package/src/utils/encoding/encodeBytes.test.ts +676 -0
  425. package/src/utils/encoding/encodeBytes.ts +59 -0
  426. package/src/utils/encoding/encodeHex.bench.ts +49 -0
  427. package/src/utils/encoding/encodeHex.test.ts +232 -0
  428. package/src/utils/encoding/encodeHex.ts +104 -0
  429. package/src/utils/encoding/encodeRlp.bench.ts +54 -0
  430. package/src/utils/encoding/encodeRlp.test.ts +254 -0
  431. package/src/utils/encoding/encodeRlp.ts +48 -0
  432. package/src/utils/encoding/index.test.ts +32 -0
  433. package/src/utils/encoding/index.ts +36 -0
  434. package/src/utils/ens/index.test.ts +14 -0
  435. package/src/utils/ens/index.ts +7 -0
  436. package/src/utils/ens/labelhash.test.ts +55 -0
  437. package/src/utils/ens/labelhash.ts +16 -0
  438. package/src/utils/ens/namehash.test.ts +65 -0
  439. package/src/utils/ens/namehash.ts +28 -0
  440. package/src/utils/ens/normalize.bench.ts +14 -0
  441. package/src/utils/ens/normalize.test.ts +35 -0
  442. package/src/utils/ens/normalize.ts +14 -0
  443. package/src/utils/ens/packetToBytes.test.ts +11 -0
  444. package/src/utils/ens/packetToBytes.ts +29 -0
  445. package/src/utils/formatters/block.bench.ts +51 -0
  446. package/src/utils/formatters/block.test.ts +115 -0
  447. package/src/utils/formatters/block.ts +37 -0
  448. package/src/utils/formatters/extract.test.ts +14 -0
  449. package/src/utils/formatters/extract.ts +18 -0
  450. package/src/utils/formatters/feeHistory.test.ts +66 -0
  451. package/src/utils/formatters/feeHistory.ts +12 -0
  452. package/src/utils/formatters/format.test.ts +93 -0
  453. package/src/utils/formatters/format.ts +90 -0
  454. package/src/utils/formatters/index.test.ts +27 -0
  455. package/src/utils/formatters/index.ts +34 -0
  456. package/src/utils/formatters/log.test.ts +79 -0
  457. package/src/utils/formatters/log.ts +12 -0
  458. package/src/utils/formatters/transaction.test.ts +271 -0
  459. package/src/utils/formatters/transaction.ts +63 -0
  460. package/src/utils/formatters/transactionReceipt.bench.ts +73 -0
  461. package/src/utils/formatters/transactionReceipt.test.ts +151 -0
  462. package/src/utils/formatters/transactionReceipt.ts +63 -0
  463. package/src/utils/formatters/transactionRequest.bench.ts +29 -0
  464. package/src/utils/formatters/transactionRequest.test.ts +237 -0
  465. package/src/utils/formatters/transactionRequest.ts +56 -0
  466. package/src/utils/hash/getEventSignature.test.ts +61 -0
  467. package/src/utils/hash/getEventSignature.ts +4 -0
  468. package/src/utils/hash/getFunctionSignature.test.ts +22 -0
  469. package/src/utils/hash/getFunctionSignature.ts +5 -0
  470. package/src/utils/hash/hashFunction.test.ts +65 -0
  471. package/src/utils/hash/hashFunction.ts +12 -0
  472. package/src/utils/hash/index.test.ts +13 -0
  473. package/src/utils/hash/index.ts +5 -0
  474. package/src/utils/hash/keccak256.test.ts +59 -0
  475. package/src/utils/hash/keccak256.ts +21 -0
  476. package/src/utils/index.test.ts +111 -0
  477. package/src/utils/index.ts +142 -0
  478. package/src/utils/observe.test.ts +176 -0
  479. package/src/utils/observe.ts +66 -0
  480. package/src/utils/poll.test.ts +127 -0
  481. package/src/utils/poll.ts +42 -0
  482. package/src/utils/promise/index.test.ts +14 -0
  483. package/src/utils/promise/index.ts +3 -0
  484. package/src/utils/promise/withCache.test.ts +97 -0
  485. package/src/utils/promise/withCache.ts +73 -0
  486. package/src/utils/promise/withRetry.test.ts +231 -0
  487. package/src/utils/promise/withRetry.ts +61 -0
  488. package/src/utils/promise/withTimeout.test.ts +37 -0
  489. package/src/utils/promise/withTimeout.ts +39 -0
  490. package/src/utils/rpc.test.ts +990 -0
  491. package/src/utils/rpc.ts +294 -0
  492. package/src/utils/stringify.test.ts +13 -0
  493. package/src/utils/stringify.ts +5 -0
  494. package/src/utils/uid.ts +14 -0
  495. package/src/utils/unit/constants.test.ts +22 -0
  496. package/src/utils/unit/constants.ts +12 -0
  497. package/src/utils/unit/formatEther.test.ts +75 -0
  498. package/src/utils/unit/formatEther.ts +6 -0
  499. package/src/utils/unit/formatGwei.test.ts +32 -0
  500. package/src/utils/unit/formatGwei.ts +6 -0
  501. package/src/utils/unit/formatUnit.bench.ts +21 -0
  502. package/src/utils/unit/formatUnit.test.ts +40 -0
  503. package/src/utils/unit/formatUnit.ts +16 -0
  504. package/src/utils/unit/index.test.ts +28 -0
  505. package/src/utils/unit/index.ts +7 -0
  506. package/src/utils/unit/parseEther.test.ts +126 -0
  507. package/src/utils/unit/parseEther.ts +6 -0
  508. package/src/utils/unit/parseGwei.test.ts +50 -0
  509. package/src/utils/unit/parseGwei.ts +6 -0
  510. package/src/utils/unit/parseUnit.bench.ts +21 -0
  511. package/src/utils/unit/parseUnit.test.ts +54 -0
  512. package/src/utils/unit/parseUnit.ts +27 -0
  513. package/src/utils/wait.ts +3 -0
  514. package/src/wallet.test.ts +19 -0
  515. package/src/wallet.ts +23 -0
  516. package/src/window.ts +1 -0
  517. package/utils/package.json +1 -1
  518. package/wallet/package.json +4 -0
  519. package/window/package.json +1 -1
  520. package/actions/package.json +0 -4
  521. package/clients/package.json +0 -4
  522. package/dist/actions/index.d.ts +0 -7
  523. package/dist/actions/index.js +0 -124
  524. package/dist/chunk-26WUARDL.js +0 -1374
  525. package/dist/chunk-7H5SPKXN.js +0 -1113
  526. package/dist/clients/index.d.ts +0 -7
  527. package/dist/clients/index.js +0 -23
  528. package/dist/createWalletClient-d612fe08.d.ts +0 -130
  529. package/dist/parseGwei-64031f5e.d.ts +0 -356
  530. package/dist/rpc-26932bae.d.ts +0 -61
  531. package/dist/transactionRequest-3e463099.d.ts +0 -44
  532. package/dist/watchAsset-dc7dcdd9.d.ts +0 -522
  533. package/dist/webSocket-7f88e9e0.d.ts +0 -83
@@ -1,6 +1,17 @@
1
1
  import {
2
- checksumAddress,
3
- encodeHex,
2
+ AbiDecodingZeroDataError,
3
+ BlockNotFoundError,
4
+ InvalidGasArgumentsError,
5
+ RawContractError,
6
+ TransactionNotFoundError,
7
+ TransactionReceiptNotFoundError,
8
+ WaitForTransactionReceiptTimeoutError,
9
+ decodeFunctionResult,
10
+ encodeEventTopics,
11
+ encodeFunctionData,
12
+ extract,
13
+ extractFunctionName,
14
+ extractFunctionParams,
4
15
  format,
5
16
  formatBlock,
6
17
  formatFeeHistory,
@@ -8,21 +19,14 @@ import {
8
19
  formatTransaction,
9
20
  formatTransactionReceipt,
10
21
  formatTransactionRequest,
11
- getAddress,
12
- hexToNumber,
13
- numberToHex
14
- } from "./chunk-26WUARDL.js";
15
- import {
16
- BaseError,
17
- BlockNotFoundError,
18
- InvalidGasArgumentsError,
19
- TransactionNotFoundError,
20
- TransactionReceiptNotFoundError,
21
- WaitForTransactionReceiptTimeoutError,
22
22
  getCache,
23
+ getContractError,
24
+ hexToNumber,
25
+ multicall3Abi,
26
+ numberToHex,
23
27
  wait,
24
28
  withCache
25
- } from "./chunk-7H5SPKXN.js";
29
+ } from "./chunk-ZRHPJRBJ.mjs";
26
30
 
27
31
  // src/actions/public/call.ts
28
32
  async function call(client, {
@@ -44,6 +48,7 @@ async function call(client, {
44
48
  if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
45
49
  throw new InvalidGasArgumentsError();
46
50
  const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
51
+ const formatter = chain?.formatters?.transactionRequest;
47
52
  const request_ = format(
48
53
  {
49
54
  from,
@@ -56,10 +61,11 @@ async function call(client, {
56
61
  nonce,
57
62
  to,
58
63
  value,
59
- ...rest
64
+ // Pick out extra data that might exist on the chain's transaction request type.
65
+ ...extract(rest, { formatter })
60
66
  },
61
67
  {
62
- formatter: chain?.formatters?.transactionRequest || formatTransactionRequest
68
+ formatter: formatter || formatTransactionRequest
63
69
  }
64
70
  );
65
71
  const response = await client.request({
@@ -71,6 +77,53 @@ async function call(client, {
71
77
  return { data: response };
72
78
  }
73
79
 
80
+ // src/actions/public/simulateContract.ts
81
+ async function simulateContract(client, {
82
+ abi,
83
+ address,
84
+ args,
85
+ functionName,
86
+ ...callRequest
87
+ }) {
88
+ const calldata = encodeFunctionData({
89
+ abi,
90
+ args,
91
+ functionName
92
+ });
93
+ try {
94
+ const { data } = await call(client, {
95
+ data: calldata,
96
+ to: address,
97
+ ...callRequest
98
+ });
99
+ const result = decodeFunctionResult({
100
+ abi,
101
+ args,
102
+ functionName,
103
+ data: data || "0x"
104
+ });
105
+ return {
106
+ result,
107
+ request: {
108
+ abi,
109
+ address,
110
+ args,
111
+ functionName,
112
+ ...callRequest
113
+ }
114
+ };
115
+ } catch (err) {
116
+ throw getContractError(err, {
117
+ abi,
118
+ address,
119
+ args,
120
+ docsPath: "/docs/contract/simulateContract",
121
+ functionName,
122
+ sender: callRequest.from
123
+ });
124
+ }
125
+ }
126
+
74
127
  // src/actions/public/createPendingTransactionFilter.ts
75
128
  async function createPendingTransactionFilter(client) {
76
129
  const id = await client.request({
@@ -192,6 +245,18 @@ async function getBlockTransactionCount(client, {
192
245
  return hexToNumber(count);
193
246
  }
194
247
 
248
+ // src/actions/public/getBytecode.ts
249
+ async function getBytecode(client, { address, blockNumber, blockTag = "latest" }) {
250
+ const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
251
+ const hex = await client.request({
252
+ method: "eth_getCode",
253
+ params: [address, blockNumberHex || blockTag]
254
+ });
255
+ if (hex === "0x")
256
+ return void 0;
257
+ return hex;
258
+ }
259
+
195
260
  // src/actions/public/getChainId.ts
196
261
  async function getChainId(client) {
197
262
  const chainIdHex = await client.request({ method: "eth_chainId" });
@@ -245,6 +310,95 @@ async function getGasPrice(client) {
245
310
  return BigInt(gasPrice);
246
311
  }
247
312
 
313
+ // src/actions/public/createEventFilter.ts
314
+ async function createEventFilter(client, {
315
+ address,
316
+ event,
317
+ args,
318
+ fromBlock,
319
+ toBlock
320
+ } = {}) {
321
+ let topics = [];
322
+ if (event)
323
+ topics = buildFilterTopics({ event, args });
324
+ const id = await client.request({
325
+ method: "eth_newFilter",
326
+ params: [
327
+ {
328
+ address,
329
+ fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
330
+ toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
331
+ ...topics.length ? { topics } : {}
332
+ }
333
+ ]
334
+ });
335
+ return { id, type: "event" };
336
+ }
337
+ function buildFilterTopics({
338
+ event,
339
+ args
340
+ }) {
341
+ const eventName = extractFunctionName(event);
342
+ const abi = unstable_parseAbi(event);
343
+ return encodeEventTopics({ abi, eventName, args });
344
+ }
345
+ function unstable_parseAbi(definition) {
346
+ const name = extractFunctionName(definition);
347
+ const params = extractFunctionParams(definition);
348
+ return [
349
+ {
350
+ type: "event",
351
+ name,
352
+ inputs: params || []
353
+ }
354
+ ];
355
+ }
356
+
357
+ // src/actions/public/getLogs.ts
358
+ async function getLogs(client, {
359
+ address,
360
+ blockHash,
361
+ fromBlock,
362
+ toBlock,
363
+ event,
364
+ args
365
+ } = {}) {
366
+ let topics = [];
367
+ if (event) {
368
+ topics = buildFilterTopics({ event, args });
369
+ }
370
+ let logs;
371
+ if (blockHash) {
372
+ logs = await client.request({
373
+ method: "eth_getLogs",
374
+ params: [{ address, topics, blockHash }]
375
+ });
376
+ } else {
377
+ logs = await client.request({
378
+ method: "eth_getLogs",
379
+ params: [
380
+ {
381
+ address,
382
+ topics,
383
+ fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
384
+ toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock
385
+ }
386
+ ]
387
+ });
388
+ }
389
+ return logs.map(formatLog);
390
+ }
391
+
392
+ // src/actions/public/getStorageAt.ts
393
+ async function getStorageAt(client, { address, blockNumber, blockTag = "latest", slot }) {
394
+ const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
395
+ const data = await client.request({
396
+ method: "eth_getStorageAt",
397
+ params: [address, slot, blockNumberHex || blockTag]
398
+ });
399
+ return data;
400
+ }
401
+
248
402
  // src/actions/public/getTransaction.ts
249
403
  async function getTransaction(client, {
250
404
  blockHash,
@@ -318,6 +472,117 @@ async function getTransactionReceipt(client, { hash }) {
318
472
  });
319
473
  }
320
474
 
475
+ // src/actions/public/readContract.ts
476
+ async function readContract(client, {
477
+ abi,
478
+ address,
479
+ args,
480
+ functionName,
481
+ ...callRequest
482
+ }) {
483
+ const calldata = encodeFunctionData({
484
+ abi,
485
+ args,
486
+ functionName
487
+ });
488
+ try {
489
+ const { data } = await call(client, {
490
+ data: calldata,
491
+ to: address,
492
+ ...callRequest
493
+ });
494
+ return decodeFunctionResult({
495
+ abi,
496
+ args,
497
+ functionName,
498
+ data: data || "0x"
499
+ });
500
+ } catch (err) {
501
+ throw getContractError(err, {
502
+ abi,
503
+ address,
504
+ args,
505
+ docsPath: "/docs/contract/readContract",
506
+ functionName
507
+ });
508
+ }
509
+ }
510
+
511
+ // src/actions/public/multicall.ts
512
+ async function multicall(client, args) {
513
+ const {
514
+ allowFailure = true,
515
+ blockNumber,
516
+ blockTag,
517
+ contracts,
518
+ multicallAddress
519
+ } = args;
520
+ const calls = contracts.map(({ abi, address, args: args2, functionName }) => {
521
+ try {
522
+ const callData = encodeFunctionData({
523
+ abi,
524
+ args: args2,
525
+ functionName
526
+ });
527
+ return {
528
+ allowFailure: true,
529
+ callData,
530
+ target: address
531
+ };
532
+ } catch (err) {
533
+ const error = getContractError(err, {
534
+ abi,
535
+ address,
536
+ args: args2,
537
+ docsPath: "/docs/contract/multicall",
538
+ functionName
539
+ });
540
+ if (!allowFailure)
541
+ throw error;
542
+ return {
543
+ allowFailure: true,
544
+ callData: "0x",
545
+ target: address
546
+ };
547
+ }
548
+ });
549
+ const results = await readContract(client, {
550
+ abi: multicall3Abi,
551
+ address: multicallAddress,
552
+ args: [calls],
553
+ blockNumber,
554
+ blockTag,
555
+ functionName: "aggregate3"
556
+ });
557
+ return results.map(({ returnData, success }, i) => {
558
+ const { callData } = calls[i];
559
+ const { abi, address, functionName, args: args2 } = contracts[i];
560
+ try {
561
+ if (callData === "0x")
562
+ throw new AbiDecodingZeroDataError();
563
+ if (!success)
564
+ throw new RawContractError({ data: returnData });
565
+ const result = decodeFunctionResult({
566
+ abi,
567
+ data: returnData,
568
+ functionName
569
+ });
570
+ return { result, status: "success" };
571
+ } catch (err) {
572
+ const error = getContractError(err, {
573
+ abi,
574
+ address,
575
+ args: args2,
576
+ docsPath: "/docs/contract/multicall",
577
+ functionName
578
+ });
579
+ if (!allowFailure)
580
+ throw error;
581
+ return { error, result: void 0, status: "failure" };
582
+ }
583
+ });
584
+ }
585
+
321
586
  // src/actions/public/uninstallFilter.ts
322
587
  async function uninstallFilter(client, { filter }) {
323
588
  return client.request({
@@ -368,96 +633,32 @@ function observe(observerId, callbacks, fn) {
368
633
  return unwatch;
369
634
  }
370
635
 
371
- // src/actions/public/waitForTransactionReceipt.ts
372
- async function waitForTransactionReceipt(client, {
373
- confirmations = 1,
374
- hash,
375
- onReplaced,
376
- pollingInterval = client.pollingInterval,
377
- timeout
636
+ // src/actions/public/createContractEventFilter.ts
637
+ async function createContractEventFilter(client, {
638
+ address,
639
+ abi,
640
+ args,
641
+ eventName,
642
+ fromBlock,
643
+ toBlock
378
644
  }) {
379
- const observerId = JSON.stringify([
380
- "waitForTransactionReceipt",
381
- client.uid,
382
- hash
383
- ]);
384
- let transaction;
385
- let replacedTransaction;
386
- let receipt;
387
- return new Promise((resolve, reject) => {
388
- if (timeout)
389
- setTimeout(
390
- () => reject(new WaitForTransactionReceiptTimeoutError({ hash })),
391
- timeout
392
- );
393
- const unobserve = observe(
394
- observerId,
395
- { onReplaced, resolve, reject },
396
- (emit) => {
397
- const unwatch = watchBlockNumber(client, {
398
- emitMissed: true,
399
- emitOnBegin: true,
400
- pollingInterval,
401
- async onBlockNumber(blockNumber) {
402
- const done = async (fn) => {
403
- unwatch();
404
- fn();
405
- unobserve();
406
- };
407
- try {
408
- if (receipt) {
409
- if (blockNumber - receipt.blockNumber + 1n < confirmations)
410
- return;
411
- done(() => emit.resolve(receipt));
412
- return;
413
- }
414
- transaction = await getTransaction(client, { hash });
415
- receipt = await getTransactionReceipt(client, { hash });
416
- if (blockNumber - receipt.blockNumber + 1n < confirmations)
417
- return;
418
- done(() => emit.resolve(receipt));
419
- } catch (err) {
420
- if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
421
- replacedTransaction = transaction;
422
- const block = await getBlock(client, {
423
- blockNumber,
424
- includeTransactions: true
425
- });
426
- const replacementTransaction = block.transactions.find(
427
- ({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
428
- );
429
- if (!replacementTransaction)
430
- return;
431
- receipt = await getTransactionReceipt(client, {
432
- hash: replacementTransaction.hash
433
- });
434
- if (blockNumber - receipt.blockNumber + 1n < confirmations)
435
- return;
436
- let reason = "replaced";
437
- if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
438
- reason = "repriced";
439
- } else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
440
- reason = "cancelled";
441
- }
442
- done(() => {
443
- emit.onReplaced?.({
444
- reason,
445
- replacedTransaction,
446
- transaction: replacementTransaction,
447
- transactionReceipt: receipt
448
- });
449
- emit.resolve(receipt);
450
- });
451
- } else {
452
- done(() => emit.reject(err));
453
- }
454
- }
455
- }
456
- });
457
- return unwatch;
645
+ const topics = eventName ? encodeEventTopics({
646
+ abi,
647
+ args,
648
+ eventName
649
+ }) : void 0;
650
+ const id = await client.request({
651
+ method: "eth_newFilter",
652
+ params: [
653
+ {
654
+ address,
655
+ fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
656
+ toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
657
+ topics
458
658
  }
459
- );
659
+ ]
460
660
  });
661
+ return { id, type: "event" };
461
662
  }
462
663
 
463
664
  // src/utils/poll.ts
@@ -587,6 +788,130 @@ function watchBlocks(client, {
587
788
  );
588
789
  }
589
790
 
791
+ // src/actions/public/watchContractEvent.ts
792
+ function watchContractEvent(client, {
793
+ abi,
794
+ address,
795
+ args,
796
+ batch = true,
797
+ eventName,
798
+ onError,
799
+ onLogs,
800
+ pollingInterval = client.pollingInterval
801
+ }) {
802
+ const observerId = JSON.stringify([
803
+ "watchContractEvent",
804
+ address,
805
+ args,
806
+ batch,
807
+ client.uid,
808
+ eventName,
809
+ pollingInterval
810
+ ]);
811
+ return observe(observerId, { onLogs, onError }, (emit) => {
812
+ let filter;
813
+ const unwatch = poll(
814
+ async () => {
815
+ try {
816
+ if (!filter) {
817
+ try {
818
+ filter = await createContractEventFilter(client, {
819
+ abi,
820
+ address,
821
+ args,
822
+ eventName
823
+ });
824
+ return;
825
+ } catch (err) {
826
+ unwatch();
827
+ throw err;
828
+ }
829
+ }
830
+ const logs = await getFilterChanges(client, { filter });
831
+ if (logs.length === 0)
832
+ return;
833
+ if (batch)
834
+ emit.onLogs(logs);
835
+ else
836
+ logs.forEach((log) => emit.onLogs([log]));
837
+ } catch (err) {
838
+ emit.onError?.(err);
839
+ }
840
+ },
841
+ {
842
+ emitOnBegin: true,
843
+ interval: pollingInterval
844
+ }
845
+ );
846
+ return async () => {
847
+ if (filter)
848
+ await uninstallFilter(client, { filter });
849
+ unwatch();
850
+ };
851
+ });
852
+ }
853
+
854
+ // src/actions/public/watchEvent.ts
855
+ function watchEvent(client, {
856
+ address,
857
+ args,
858
+ batch = true,
859
+ event,
860
+ onError,
861
+ onLogs,
862
+ pollingInterval = client.pollingInterval
863
+ }) {
864
+ const observerId = JSON.stringify([
865
+ "watchEvent",
866
+ address,
867
+ args,
868
+ batch,
869
+ client.uid,
870
+ event,
871
+ pollingInterval
872
+ ]);
873
+ return observe(observerId, { onLogs, onError }, (emit) => {
874
+ let filter;
875
+ const unwatch = poll(
876
+ async () => {
877
+ try {
878
+ if (!filter) {
879
+ try {
880
+ filter = await createEventFilter(client, {
881
+ address,
882
+ args,
883
+ event
884
+ });
885
+ return;
886
+ } catch (err) {
887
+ unwatch();
888
+ throw err;
889
+ }
890
+ }
891
+ const logs = await getFilterChanges(client, { filter });
892
+ if (logs.length === 0)
893
+ return;
894
+ if (batch)
895
+ emit.onLogs(logs);
896
+ else
897
+ logs.forEach((log) => emit.onLogs([log]));
898
+ } catch (err) {
899
+ emit.onError?.(err);
900
+ }
901
+ },
902
+ {
903
+ emitOnBegin: true,
904
+ interval: pollingInterval
905
+ }
906
+ );
907
+ return async () => {
908
+ if (filter)
909
+ await uninstallFilter(client, { filter });
910
+ unwatch();
911
+ };
912
+ });
913
+ }
914
+
590
915
  // src/actions/public/watchPendingTransactions.ts
591
916
  function watchPendingTransactions(client, {
592
917
  batch = true,
@@ -615,6 +940,8 @@ function watchPendingTransactions(client, {
615
940
  }
616
941
  }
617
942
  const hashes = await getFilterChanges(client, { filter });
943
+ if (hashes.length === 0)
944
+ return;
618
945
  if (batch)
619
946
  emit.onTransactions(hashes);
620
947
  else
@@ -636,356 +963,101 @@ function watchPendingTransactions(client, {
636
963
  });
637
964
  }
638
965
 
639
- // src/actions/test/dropTransaction.ts
640
- async function dropTransaction(client, { hash }) {
641
- return await client.request({
642
- method: `${client.mode}_dropTransaction`,
643
- params: [hash]
644
- });
645
- }
646
-
647
- // src/actions/test/getAutomine.ts
648
- async function getAutomine(client) {
649
- return await client.request({
650
- method: `${client.mode}_getAutomine`
651
- });
652
- }
653
-
654
- // src/actions/test/getTxpoolContent.ts
655
- async function getTxpoolContent(client) {
656
- return await client.request({
657
- method: "txpool_content"
658
- });
659
- }
660
-
661
- // src/actions/test/getTxpoolStatus.ts
662
- async function getTxpoolStatus(client) {
663
- const { pending, queued } = await client.request({
664
- method: "txpool_status"
665
- });
666
- return {
667
- pending: hexToNumber(pending),
668
- queued: hexToNumber(queued)
669
- };
670
- }
671
-
672
- // src/actions/test/impersonateAccount.ts
673
- async function impersonateAccount(client, { address }) {
674
- return await client.request({
675
- method: `${client.mode}_impersonateAccount`,
676
- params: [address]
677
- });
678
- }
679
-
680
- // src/actions/test/increaseTime.ts
681
- async function increaseTime(client, { seconds }) {
682
- return await client.request({
683
- method: "evm_increaseTime",
684
- params: [numberToHex(seconds)]
685
- });
686
- }
687
-
688
- // src/actions/test/inspectTxpool.ts
689
- async function inspectTxpool(client) {
690
- return await client.request({
691
- method: "txpool_inspect"
692
- });
693
- }
694
-
695
- // src/actions/test/mine.ts
696
- async function mine(client, { blocks, interval }) {
697
- return await client.request({
698
- method: `${client.mode}_mine`,
699
- params: [numberToHex(blocks), numberToHex(interval || 0)]
700
- });
701
- }
702
-
703
- // src/actions/test/removeBlockTimestampInterval.ts
704
- async function removeBlockTimestampInterval(client) {
705
- return await client.request({
706
- method: `${client.mode}_removeBlockTimestampInterval`
707
- });
708
- }
709
-
710
- // src/actions/test/reset.ts
711
- async function reset(client, { blockNumber, jsonRpcUrl } = {}) {
712
- return await client.request({
713
- method: `${client.mode}_reset`,
714
- params: [{ forking: { blockNumber: Number(blockNumber), jsonRpcUrl } }]
715
- });
716
- }
717
-
718
- // src/actions/test/revert.ts
719
- async function revert(client, { id }) {
720
- return await client.request({
721
- method: "evm_revert",
722
- params: [id]
723
- });
724
- }
725
-
726
- // src/actions/test/sendUnsignedTransaction.ts
727
- async function sendUnsignedTransaction(client, request) {
728
- const request_ = formatTransactionRequest(request);
729
- const hash = await client.request({
730
- method: "eth_sendUnsignedTransaction",
731
- params: [request_]
732
- });
733
- return hash;
734
- }
735
-
736
- // src/actions/test/setAutomine.ts
737
- async function setAutomine(client, enabled) {
738
- return await client.request({
739
- method: "evm_setAutomine",
740
- params: [enabled]
741
- });
742
- }
743
-
744
- // src/actions/test/setBalance.ts
745
- async function setBalance(client, { address, value }) {
746
- return await client.request({
747
- method: `${client.mode}_setBalance`,
748
- params: [address, numberToHex(value)]
749
- });
750
- }
751
-
752
- // src/actions/test/setBlockGasLimit.ts
753
- async function setBlockGasLimit(client, { gasLimit }) {
754
- return await client.request({
755
- method: "evm_setBlockGasLimit",
756
- params: [numberToHex(gasLimit)]
757
- });
758
- }
759
-
760
- // src/actions/test/setBlockTimestampInterval.ts
761
- async function setBlockTimestampInterval(client, { interval }) {
762
- return await client.request({
763
- method: `${client.mode}_setBlockTimestampInterval`,
764
- params: [interval]
765
- });
766
- }
767
-
768
- // src/actions/test/setCode.ts
769
- async function setCode(client, { address, bytecode }) {
770
- return await client.request({
771
- method: `${client.mode}_setCode`,
772
- params: [address, bytecode]
773
- });
774
- }
775
-
776
- // src/actions/test/setCoinbase.ts
777
- async function setCoinbase(client, { address }) {
778
- return await client.request({
779
- method: `${client.mode}_setCoinbase`,
780
- params: [address]
781
- });
782
- }
783
-
784
- // src/actions/test/setIntervalMining.ts
785
- async function setIntervalMining(client, { interval }) {
786
- return await client.request({
787
- method: "evm_setIntervalMining",
788
- params: [interval]
789
- });
790
- }
791
-
792
- // src/actions/test/setLoggingEnabled.ts
793
- async function setLoggingEnabled(client, enabled) {
794
- return await client.request({
795
- method: `${client.mode}_setLoggingEnabled`,
796
- params: [enabled]
797
- });
798
- }
799
-
800
- // src/actions/test/setMinGasPrice.ts
801
- async function setMinGasPrice(client, { gasPrice }) {
802
- return await client.request({
803
- method: `${client.mode}_setMinGasPrice`,
804
- params: [numberToHex(gasPrice)]
805
- });
806
- }
807
-
808
- // src/actions/test/setNextBlockBaseFeePerGas.ts
809
- async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
810
- return await client.request({
811
- method: `${client.mode}_setNextBlockBaseFeePerGas`,
812
- params: [numberToHex(baseFeePerGas)]
813
- });
814
- }
815
-
816
- // src/actions/test/setNextBlockTimestamp.ts
817
- async function setNextBlockTimestamp(client, { timestamp }) {
818
- return await client.request({
819
- method: "evm_setNextBlockTimestamp",
820
- params: [numberToHex(timestamp)]
821
- });
822
- }
823
-
824
- // src/actions/test/setNonce.ts
825
- async function setNonce(client, { address, nonce }) {
826
- return await client.request({
827
- method: `${client.mode}_setNonce`,
828
- params: [address, numberToHex(nonce)]
829
- });
830
- }
831
-
832
- // src/actions/test/setStorageAt.ts
833
- async function setStorageAt(client, { address, index, value }) {
834
- return await client.request({
835
- method: `${client.mode}_setStorageAt`,
836
- params: [
837
- address,
838
- typeof index === "number" ? numberToHex(index) : index,
839
- value
840
- ]
841
- });
842
- }
843
-
844
- // src/actions/test/snapshot.ts
845
- async function snapshot(client) {
846
- return await client.request({
847
- method: "evm_snapshot"
848
- });
849
- }
850
-
851
- // src/actions/test/stopImpersonatingAccount.ts
852
- async function stopImpersonatingAccount(client, { address }) {
853
- return await client.request({
854
- method: `${client.mode}_stopImpersonatingAccount`,
855
- params: [address]
856
- });
857
- }
858
-
859
- // src/actions/wallet/addChain.ts
860
- async function addChain(client, chain) {
861
- const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
862
- await client.request({
863
- method: "wallet_addEthereumChain",
864
- params: [
865
- {
866
- chainId: numberToHex(id),
867
- chainName: name,
868
- nativeCurrency,
869
- rpcUrls: rpcUrls.default.http,
870
- blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
871
- }
872
- ]
873
- });
874
- }
875
-
876
- // src/actions/wallet/getAccounts.ts
877
- async function getAccounts(client) {
878
- const addresses = await client.request({ method: "eth_accounts" });
879
- return addresses.map((address) => checksumAddress(address));
880
- }
881
-
882
- // src/actions/wallet/getPermissions.ts
883
- async function getPermissions(client) {
884
- const permissions = await client.request({ method: "wallet_getPermissions" });
885
- return permissions;
886
- }
887
-
888
- // src/actions/wallet/requestAccounts.ts
889
- async function requestAccounts(client) {
890
- const addresses = await client.request({ method: "eth_requestAccounts" });
891
- return addresses.map((address) => getAddress(address));
892
- }
893
-
894
- // src/actions/wallet/requestPermissions.ts
895
- async function requestPermissions(client, permissions) {
896
- return client.request({
897
- method: "wallet_requestPermissions",
898
- params: [permissions]
899
- });
900
- }
901
-
902
- // src/actions/wallet/sendTransaction.ts
903
- async function sendTransaction(client, {
904
- chain,
905
- from,
906
- accessList,
907
- data,
908
- gas,
909
- gasPrice,
910
- maxFeePerGas,
911
- maxPriorityFeePerGas,
912
- nonce,
913
- to,
914
- value,
915
- ...rest
966
+ // src/actions/public/waitForTransactionReceipt.ts
967
+ async function waitForTransactionReceipt(client, {
968
+ confirmations = 1,
969
+ hash,
970
+ onReplaced,
971
+ pollingInterval = client.pollingInterval,
972
+ timeout
916
973
  }) {
917
- if (maxFeePerGas !== void 0 && maxPriorityFeePerGas !== void 0 && maxFeePerGas < maxPriorityFeePerGas)
918
- throw new InvalidGasArgumentsError();
919
- const request_ = format(
920
- {
921
- from,
922
- accessList,
923
- data,
924
- gas,
925
- gasPrice,
926
- maxFeePerGas,
927
- maxPriorityFeePerGas,
928
- nonce,
929
- to,
930
- value,
931
- ...rest
932
- },
933
- {
934
- formatter: chain?.formatters?.transactionRequest || formatTransactionRequest
935
- }
936
- );
937
- const hash = await client.request({
938
- method: "eth_sendTransaction",
939
- params: [request_]
940
- });
941
- return hash;
942
- }
943
-
944
- // src/actions/wallet/signMessage.ts
945
- async function signMessage(client, { from, data: data_ }) {
946
- let data;
947
- if (typeof data_ === "string") {
948
- if (!data_.startsWith("0x"))
949
- throw new BaseError(
950
- `data ("${data_}") must be a hex value. Encode it first to a hex with the \`encodeHex\` util.`,
951
- {
952
- docsPath: "/TODO"
953
- }
974
+ const observerId = JSON.stringify([
975
+ "waitForTransactionReceipt",
976
+ client.uid,
977
+ hash
978
+ ]);
979
+ let transaction;
980
+ let replacedTransaction;
981
+ let receipt;
982
+ return new Promise((resolve, reject) => {
983
+ if (timeout)
984
+ setTimeout(
985
+ () => reject(new WaitForTransactionReceiptTimeoutError({ hash })),
986
+ timeout
954
987
  );
955
- data = data_;
956
- } else {
957
- data = encodeHex(data_);
958
- }
959
- const signed = await client.request({
960
- method: "personal_sign",
961
- params: [data, from]
962
- });
963
- return signed;
964
- }
965
-
966
- // src/actions/wallet/switchChain.ts
967
- async function switchChain(client, { id }) {
968
- await client.request({
969
- method: "wallet_switchEthereumChain",
970
- params: [
971
- {
972
- chainId: numberToHex(id)
988
+ const unobserve = observe(
989
+ observerId,
990
+ { onReplaced, resolve, reject },
991
+ (emit) => {
992
+ const unwatch = watchBlockNumber(client, {
993
+ emitMissed: true,
994
+ emitOnBegin: true,
995
+ pollingInterval,
996
+ async onBlockNumber(blockNumber) {
997
+ const done = async (fn) => {
998
+ unwatch();
999
+ fn();
1000
+ unobserve();
1001
+ };
1002
+ try {
1003
+ if (receipt) {
1004
+ if (blockNumber - receipt.blockNumber + 1n < confirmations)
1005
+ return;
1006
+ done(() => emit.resolve(receipt));
1007
+ return;
1008
+ }
1009
+ transaction = await getTransaction(client, { hash });
1010
+ receipt = await getTransactionReceipt(client, { hash });
1011
+ if (blockNumber - receipt.blockNumber + 1n < confirmations)
1012
+ return;
1013
+ done(() => emit.resolve(receipt));
1014
+ } catch (err) {
1015
+ if (transaction && (err instanceof TransactionNotFoundError || err instanceof TransactionReceiptNotFoundError)) {
1016
+ replacedTransaction = transaction;
1017
+ const block = await getBlock(client, {
1018
+ blockNumber,
1019
+ includeTransactions: true
1020
+ });
1021
+ const replacementTransaction = block.transactions.find(
1022
+ ({ from, nonce }) => from === replacedTransaction.from && nonce === replacedTransaction.nonce
1023
+ );
1024
+ if (!replacementTransaction)
1025
+ return;
1026
+ receipt = await getTransactionReceipt(client, {
1027
+ hash: replacementTransaction.hash
1028
+ });
1029
+ if (blockNumber - receipt.blockNumber + 1n < confirmations)
1030
+ return;
1031
+ let reason = "replaced";
1032
+ if (replacementTransaction.to === replacedTransaction.to && replacementTransaction.value === replacedTransaction.value) {
1033
+ reason = "repriced";
1034
+ } else if (replacementTransaction.from === replacementTransaction.to && replacementTransaction.value === 0n) {
1035
+ reason = "cancelled";
1036
+ }
1037
+ done(() => {
1038
+ emit.onReplaced?.({
1039
+ reason,
1040
+ replacedTransaction,
1041
+ transaction: replacementTransaction,
1042
+ transactionReceipt: receipt
1043
+ });
1044
+ emit.resolve(receipt);
1045
+ });
1046
+ } else {
1047
+ done(() => emit.reject(err));
1048
+ }
1049
+ }
1050
+ }
1051
+ });
1052
+ return unwatch;
973
1053
  }
974
- ]
975
- });
976
- }
977
-
978
- // src/actions/wallet/watchAsset.ts
979
- async function watchAsset(client, params) {
980
- const added = await client.request({
981
- method: "wallet_watchAsset",
982
- params: [params]
1054
+ );
983
1055
  });
984
- return added;
985
1056
  }
986
1057
 
987
1058
  export {
988
1059
  call,
1060
+ simulateContract,
989
1061
  createPendingTransactionFilter,
990
1062
  createBlockFilter,
991
1063
  estimateGas,
@@ -994,54 +1066,26 @@ export {
994
1066
  getBlockNumberCache,
995
1067
  getBlockNumber,
996
1068
  getBlockTransactionCount,
1069
+ getBytecode,
997
1070
  getChainId,
998
1071
  getFeeHistory,
999
1072
  getFilterChanges,
1000
1073
  getFilterLogs,
1001
1074
  getGasPrice,
1075
+ getLogs,
1076
+ getStorageAt,
1002
1077
  getTransaction,
1003
1078
  getTransactionConfirmations,
1004
1079
  getTransactionCount,
1005
1080
  getTransactionReceipt,
1081
+ readContract,
1082
+ multicall,
1006
1083
  uninstallFilter,
1007
1084
  waitForTransactionReceipt,
1008
1085
  watchBlockNumber,
1009
1086
  watchBlocks,
1010
- watchPendingTransactions,
1011
- dropTransaction,
1012
- getAutomine,
1013
- getTxpoolContent,
1014
- getTxpoolStatus,
1015
- impersonateAccount,
1016
- increaseTime,
1017
- inspectTxpool,
1018
- mine,
1019
- removeBlockTimestampInterval,
1020
- reset,
1021
- revert,
1022
- sendUnsignedTransaction,
1023
- setAutomine,
1024
- setBalance,
1025
- setBlockGasLimit,
1026
- setBlockTimestampInterval,
1027
- setCode,
1028
- setCoinbase,
1029
- setIntervalMining,
1030
- setLoggingEnabled,
1031
- setMinGasPrice,
1032
- setNextBlockBaseFeePerGas,
1033
- setNextBlockTimestamp,
1034
- setNonce,
1035
- setStorageAt,
1036
- snapshot,
1037
- stopImpersonatingAccount,
1038
- addChain,
1039
- getAccounts,
1040
- getPermissions,
1041
- requestAccounts,
1042
- requestPermissions,
1043
- sendTransaction,
1044
- signMessage,
1045
- switchChain,
1046
- watchAsset
1087
+ watchContractEvent,
1088
+ watchEvent,
1089
+ watchPendingTransactions
1047
1090
  };
1091
+ //# sourceMappingURL=chunk-P73S5JV4.mjs.map