viem 1.5.4 → 1.6.2

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 (343) hide show
  1. package/chains/utils/package.json +5 -0
  2. package/dist/cjs/accounts/index.js +5 -1
  3. package/dist/cjs/accounts/index.js.map +1 -1
  4. package/dist/cjs/accounts/utils/privateKeyToAddress.js +12 -0
  5. package/dist/cjs/accounts/utils/privateKeyToAddress.js.map +1 -0
  6. package/dist/cjs/accounts/utils/signTransaction.js.map +1 -1
  7. package/dist/cjs/actions/getContract.js.map +1 -1
  8. package/dist/cjs/actions/public/estimateGas.js +3 -1
  9. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  10. package/dist/cjs/actions/public/multicall.js +2 -3
  11. package/dist/cjs/actions/public/multicall.js.map +1 -1
  12. package/dist/cjs/actions/public/watchContractEvent.js +134 -67
  13. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  14. package/dist/cjs/actions/public/watchEvent.js +136 -62
  15. package/dist/cjs/actions/public/watchEvent.js.map +1 -1
  16. package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
  17. package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
  18. package/dist/cjs/chains/{formatters/celo.js → celo/formatters.js} +1 -1
  19. package/dist/cjs/chains/celo/formatters.js.map +1 -0
  20. package/dist/cjs/chains/{serializers/celo.js → celo/serializers.js} +1 -1
  21. package/dist/cjs/chains/celo/serializers.js.map +1 -0
  22. package/dist/cjs/{types/formatter.js → chains/celo/types.js} +1 -1
  23. package/dist/cjs/chains/celo/types.js.map +1 -0
  24. package/dist/cjs/chains/index.js +32 -16
  25. package/dist/cjs/chains/index.js.map +1 -1
  26. package/dist/cjs/chains/optimism/fees.js +7 -0
  27. package/dist/cjs/chains/optimism/fees.js.map +1 -0
  28. package/dist/cjs/chains/{formatters/optimism.js → optimism/formatters.js} +13 -1
  29. package/dist/cjs/chains/optimism/formatters.js.map +1 -0
  30. package/dist/cjs/{types/serializer.js → chains/optimism/types.js} +1 -1
  31. package/dist/cjs/chains/optimism/types.js.map +1 -0
  32. package/dist/cjs/chains/utils.js +11 -0
  33. package/dist/cjs/chains/utils.js.map +1 -0
  34. package/dist/cjs/clients/decorators/public.js.map +1 -1
  35. package/dist/cjs/constants/number.js +96 -96
  36. package/dist/cjs/constants/number.js.map +1 -1
  37. package/dist/cjs/errors/node.js +1 -1
  38. package/dist/cjs/errors/node.js.map +1 -1
  39. package/dist/cjs/errors/version.js +1 -1
  40. package/dist/cjs/index.js.map +1 -1
  41. package/dist/cjs/utils/abi/decodeAbiParameters.js.map +1 -1
  42. package/dist/cjs/utils/abi/decodeDeployData.js.map +1 -1
  43. package/dist/cjs/utils/abi/decodeErrorResult.js.map +1 -1
  44. package/dist/cjs/utils/abi/decodeFunctionResult.js.map +1 -1
  45. package/dist/cjs/utils/abi/encodeAbiParameters.js.map +1 -1
  46. package/dist/cjs/utils/abi/encodeDeployData.js.map +1 -1
  47. package/dist/cjs/utils/abi/encodeEventTopics.js.map +1 -1
  48. package/dist/cjs/utils/abi/encodePacked.js.map +1 -1
  49. package/dist/cjs/utils/chain.js +5 -3
  50. package/dist/cjs/utils/chain.js.map +1 -1
  51. package/dist/cjs/utils/formatters/block.js.map +1 -1
  52. package/dist/cjs/utils/formatters/extract.js.map +1 -1
  53. package/dist/cjs/utils/formatters/formatter.js.map +1 -1
  54. package/dist/cjs/utils/formatters/transaction.js.map +1 -1
  55. package/dist/cjs/utils/formatters/transactionReceipt.js.map +1 -1
  56. package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
  57. package/dist/cjs/utils/poll.js +1 -1
  58. package/dist/cjs/utils/poll.js.map +1 -1
  59. package/dist/cjs/utils/transaction/prepareRequest.js +15 -6
  60. package/dist/cjs/utils/transaction/prepareRequest.js.map +1 -1
  61. package/dist/cjs/utils/typedData.js +2 -2
  62. package/dist/cjs/utils/typedData.js.map +1 -1
  63. package/dist/esm/accounts/index.js +2 -0
  64. package/dist/esm/accounts/index.js.map +1 -1
  65. package/dist/esm/accounts/utils/privateKeyToAddress.js +15 -0
  66. package/dist/esm/accounts/utils/privateKeyToAddress.js.map +1 -0
  67. package/dist/esm/accounts/utils/signTransaction.js.map +1 -1
  68. package/dist/esm/actions/getContract.js.map +1 -1
  69. package/dist/esm/actions/public/estimateGas.js +4 -2
  70. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  71. package/dist/esm/actions/public/multicall.js +2 -4
  72. package/dist/esm/actions/public/multicall.js.map +1 -1
  73. package/dist/esm/actions/public/watchContractEvent.js +145 -76
  74. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  75. package/dist/esm/actions/public/watchEvent.js +146 -70
  76. package/dist/esm/actions/public/watchEvent.js.map +1 -1
  77. package/dist/esm/actions/wallet/sendTransaction.js +1 -1
  78. package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
  79. package/dist/esm/actions/wallet/writeContract.js.map +1 -1
  80. package/dist/esm/chains/{formatters/celo.js → celo/formatters.js} +2 -2
  81. package/dist/esm/chains/celo/formatters.js.map +1 -0
  82. package/dist/esm/chains/{serializers/celo.js → celo/serializers.js} +1 -1
  83. package/dist/esm/chains/celo/serializers.js.map +1 -0
  84. package/dist/esm/chains/celo/types.js +2 -0
  85. package/dist/esm/chains/celo/types.js.map +1 -0
  86. package/dist/esm/chains/index.js +23 -7
  87. package/dist/esm/chains/index.js.map +1 -1
  88. package/dist/esm/chains/optimism/fees.js +4 -0
  89. package/dist/esm/chains/optimism/fees.js.map +1 -0
  90. package/dist/esm/chains/{formatters/optimism.js → optimism/formatters.js} +15 -2
  91. package/dist/esm/chains/optimism/formatters.js.map +1 -0
  92. package/dist/esm/chains/optimism/types.js +2 -0
  93. package/dist/esm/chains/optimism/types.js.map +1 -0
  94. package/dist/esm/chains/utils.js +4 -0
  95. package/dist/esm/chains/utils.js.map +1 -0
  96. package/dist/esm/clients/decorators/public.js.map +1 -1
  97. package/dist/esm/constants/number.js +96 -96
  98. package/dist/esm/constants/number.js.map +1 -1
  99. package/dist/esm/errors/node.js +1 -1
  100. package/dist/esm/errors/node.js.map +1 -1
  101. package/dist/esm/errors/version.js +1 -1
  102. package/dist/esm/index.js.map +1 -1
  103. package/dist/esm/utils/abi/decodeAbiParameters.js.map +1 -1
  104. package/dist/esm/utils/abi/decodeDeployData.js.map +1 -1
  105. package/dist/esm/utils/abi/decodeErrorResult.js.map +1 -1
  106. package/dist/esm/utils/abi/decodeFunctionResult.js.map +1 -1
  107. package/dist/esm/utils/abi/encodeAbiParameters.js.map +1 -1
  108. package/dist/esm/utils/abi/encodeDeployData.js.map +1 -1
  109. package/dist/esm/utils/abi/encodeEventTopics.js.map +1 -1
  110. package/dist/esm/utils/abi/encodePacked.js.map +1 -1
  111. package/dist/esm/utils/chain.js +5 -3
  112. package/dist/esm/utils/chain.js.map +1 -1
  113. package/dist/esm/utils/formatters/block.js.map +1 -1
  114. package/dist/esm/utils/formatters/extract.js.map +1 -1
  115. package/dist/esm/utils/formatters/formatter.js.map +1 -1
  116. package/dist/esm/utils/formatters/transaction.js.map +1 -1
  117. package/dist/esm/utils/formatters/transactionReceipt.js.map +1 -1
  118. package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
  119. package/dist/esm/utils/poll.js +1 -1
  120. package/dist/esm/utils/poll.js.map +1 -1
  121. package/dist/esm/utils/transaction/prepareRequest.js +14 -5
  122. package/dist/esm/utils/transaction/prepareRequest.js.map +1 -1
  123. package/dist/esm/utils/typedData.js +2 -2
  124. package/dist/esm/utils/typedData.js.map +1 -1
  125. package/dist/types/accounts/index.d.ts +2 -0
  126. package/dist/types/accounts/index.d.ts.map +1 -1
  127. package/dist/types/accounts/types.d.ts +1 -1
  128. package/dist/types/accounts/types.d.ts.map +1 -1
  129. package/dist/types/accounts/utils/privateKeyToAddress.d.ts +11 -0
  130. package/dist/types/accounts/utils/privateKeyToAddress.d.ts.map +1 -0
  131. package/dist/types/accounts/utils/signTransaction.d.ts +2 -2
  132. package/dist/types/accounts/utils/signTransaction.d.ts.map +1 -1
  133. package/dist/types/accounts/utils/signTypedData.d.ts +1 -1
  134. package/dist/types/accounts/utils/signTypedData.d.ts.map +1 -1
  135. package/dist/types/actions/getContract.d.ts +5 -5
  136. package/dist/types/actions/getContract.d.ts.map +1 -1
  137. package/dist/types/actions/public/createContractEventFilter.d.ts +3 -3
  138. package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
  139. package/dist/types/actions/public/createEventFilter.d.ts +5 -5
  140. package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
  141. package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
  142. package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
  143. package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
  144. package/dist/types/actions/public/getFilterChanges.d.ts +1 -1
  145. package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
  146. package/dist/types/actions/public/getFilterLogs.d.ts +1 -1
  147. package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
  148. package/dist/types/actions/public/getLogs.d.ts +4 -4
  149. package/dist/types/actions/public/getLogs.d.ts.map +1 -1
  150. package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
  151. package/dist/types/actions/public/getTransactionReceipt.d.ts.map +1 -1
  152. package/dist/types/actions/public/multicall.d.ts +1 -1
  153. package/dist/types/actions/public/multicall.d.ts.map +1 -1
  154. package/dist/types/actions/public/readContract.d.ts +1 -1
  155. package/dist/types/actions/public/readContract.d.ts.map +1 -1
  156. package/dist/types/actions/public/simulateContract.d.ts +3 -3
  157. package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
  158. package/dist/types/actions/public/watchContractEvent.d.ts +34 -8
  159. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  160. package/dist/types/actions/public/watchEvent.d.ts +35 -12
  161. package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
  162. package/dist/types/actions/wallet/deployContract.d.ts +4 -4
  163. package/dist/types/actions/wallet/deployContract.d.ts.map +1 -1
  164. package/dist/types/actions/wallet/sendTransaction.d.ts +2 -2
  165. package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
  166. package/dist/types/actions/wallet/signTypedData.d.ts +1 -1
  167. package/dist/types/actions/wallet/signTypedData.d.ts.map +1 -1
  168. package/dist/types/actions/wallet/writeContract.d.ts +4 -2
  169. package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
  170. package/dist/types/chains/{formatters/celo.d.ts → celo/formatters.d.ts} +26 -85
  171. package/dist/types/chains/celo/formatters.d.ts.map +1 -0
  172. package/dist/types/chains/{serializers/celo.d.ts → celo/serializers.d.ts} +4 -4
  173. package/dist/types/chains/celo/serializers.d.ts.map +1 -0
  174. package/dist/types/chains/celo/types.d.ts +60 -0
  175. package/dist/types/chains/celo/types.d.ts.map +1 -0
  176. package/dist/types/chains/index.d.ts +2681 -2790
  177. package/dist/types/chains/index.d.ts.map +1 -1
  178. package/dist/types/chains/optimism/fees.d.ts +4 -0
  179. package/dist/types/chains/optimism/fees.d.ts.map +1 -0
  180. package/dist/types/chains/{formatters/optimism.d.ts → optimism/formatters.d.ts} +77 -54
  181. package/dist/types/chains/optimism/formatters.d.ts.map +1 -0
  182. package/dist/types/chains/optimism/types.d.ts +53 -0
  183. package/dist/types/chains/optimism/types.d.ts.map +1 -0
  184. package/dist/types/chains/utils.d.ts +6 -0
  185. package/dist/types/chains/utils.d.ts.map +1 -0
  186. package/dist/types/clients/decorators/public.d.ts +10 -10
  187. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  188. package/dist/types/clients/decorators/wallet.d.ts +3 -3
  189. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  190. package/dist/types/constants/number.d.ts.map +1 -1
  191. package/dist/types/errors/node.d.ts.map +1 -1
  192. package/dist/types/errors/version.d.ts +1 -1
  193. package/dist/types/index.d.ts +14 -4
  194. package/dist/types/index.d.ts.map +1 -1
  195. package/dist/types/types/chain.d.ts +52 -8
  196. package/dist/types/types/chain.d.ts.map +1 -1
  197. package/dist/types/types/multicall.d.ts +8 -8
  198. package/dist/types/types/multicall.d.ts.map +1 -1
  199. package/dist/types/types/rpc.d.ts +1 -1
  200. package/dist/types/types/rpc.d.ts.map +1 -1
  201. package/dist/types/types/typedData.d.ts +3 -3
  202. package/dist/types/types/typedData.d.ts.map +1 -1
  203. package/dist/types/types/utils.d.ts +10 -0
  204. package/dist/types/types/utils.d.ts.map +1 -1
  205. package/dist/types/utils/abi/decodeAbiParameters.d.ts +2 -2
  206. package/dist/types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
  207. package/dist/types/utils/abi/decodeDeployData.d.ts +3 -3
  208. package/dist/types/utils/abi/decodeDeployData.d.ts.map +1 -1
  209. package/dist/types/utils/abi/decodeErrorResult.d.ts +3 -3
  210. package/dist/types/utils/abi/decodeErrorResult.d.ts.map +1 -1
  211. package/dist/types/utils/abi/decodeEventLog.d.ts +3 -3
  212. package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
  213. package/dist/types/utils/abi/decodeFunctionResult.d.ts +4 -4
  214. package/dist/types/utils/abi/decodeFunctionResult.d.ts.map +1 -1
  215. package/dist/types/utils/abi/encodeAbiParameters.d.ts +2 -2
  216. package/dist/types/utils/abi/encodeAbiParameters.d.ts.map +1 -1
  217. package/dist/types/utils/abi/encodeDeployData.d.ts +3 -3
  218. package/dist/types/utils/abi/encodeDeployData.d.ts.map +1 -1
  219. package/dist/types/utils/abi/encodeErrorResult.d.ts +4 -4
  220. package/dist/types/utils/abi/encodeErrorResult.d.ts.map +1 -1
  221. package/dist/types/utils/abi/encodeEventTopics.d.ts +4 -4
  222. package/dist/types/utils/abi/encodeEventTopics.d.ts.map +1 -1
  223. package/dist/types/utils/abi/encodeFunctionData.d.ts +4 -4
  224. package/dist/types/utils/abi/encodeFunctionData.d.ts.map +1 -1
  225. package/dist/types/utils/abi/encodeFunctionResult.d.ts +4 -4
  226. package/dist/types/utils/abi/encodeFunctionResult.d.ts.map +1 -1
  227. package/dist/types/utils/abi/encodePacked.d.ts +3 -3
  228. package/dist/types/utils/abi/encodePacked.d.ts.map +1 -1
  229. package/dist/types/utils/abi/getAbiItem.d.ts +3 -3
  230. package/dist/types/utils/abi/getAbiItem.d.ts.map +1 -1
  231. package/dist/types/utils/chain.d.ts +3 -6
  232. package/dist/types/utils/chain.d.ts.map +1 -1
  233. package/dist/types/utils/formatters/block.d.ts +7 -3
  234. package/dist/types/utils/formatters/block.d.ts.map +1 -1
  235. package/dist/types/utils/formatters/extract.d.ts +2 -2
  236. package/dist/types/utils/formatters/extract.d.ts.map +1 -1
  237. package/dist/types/utils/formatters/formatter.d.ts +1 -1
  238. package/dist/types/utils/formatters/transaction.d.ts +8 -4
  239. package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
  240. package/dist/types/utils/formatters/transactionReceipt.d.ts +3 -4
  241. package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
  242. package/dist/types/utils/formatters/transactionRequest.d.ts +4 -5
  243. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  244. package/dist/types/utils/signature/hashTypedData.d.ts +1 -1
  245. package/dist/types/utils/signature/hashTypedData.d.ts.map +1 -1
  246. package/dist/types/utils/signature/recoverTypedDataAddress.d.ts +1 -1
  247. package/dist/types/utils/signature/recoverTypedDataAddress.d.ts.map +1 -1
  248. package/dist/types/utils/signature/verifyTypedData.d.ts +1 -1
  249. package/dist/types/utils/signature/verifyTypedData.d.ts.map +1 -1
  250. package/dist/types/utils/transaction/prepareRequest.d.ts +6 -11
  251. package/dist/types/utils/transaction/prepareRequest.d.ts.map +1 -1
  252. package/dist/types/utils/typedData.d.ts +1 -1
  253. package/dist/types/utils/typedData.d.ts.map +1 -1
  254. package/package.json +9 -3
  255. package/src/accounts/index.ts +6 -0
  256. package/src/accounts/types.ts +1 -1
  257. package/src/accounts/utils/privateKeyToAddress.ts +20 -0
  258. package/src/accounts/utils/signTransaction.ts +2 -2
  259. package/src/accounts/utils/signTypedData.ts +1 -1
  260. package/src/actions/getContract.ts +6 -5
  261. package/src/actions/public/createContractEventFilter.ts +3 -3
  262. package/src/actions/public/createEventFilter.ts +6 -6
  263. package/src/actions/public/estimateContractGas.ts +1 -1
  264. package/src/actions/public/estimateGas.ts +11 -2
  265. package/src/actions/public/getFilterChanges.ts +1 -1
  266. package/src/actions/public/getFilterLogs.ts +1 -1
  267. package/src/actions/public/getLogs.ts +5 -5
  268. package/src/actions/public/multicall.ts +9 -8
  269. package/src/actions/public/readContract.ts +1 -1
  270. package/src/actions/public/simulateContract.ts +3 -3
  271. package/src/actions/public/watchContractEvent.ts +204 -90
  272. package/src/actions/public/watchEvent.ts +232 -111
  273. package/src/actions/wallet/deployContract.ts +4 -4
  274. package/src/actions/wallet/sendTransaction.ts +9 -6
  275. package/src/actions/wallet/signTypedData.ts +1 -1
  276. package/src/actions/wallet/writeContract.ts +12 -8
  277. package/src/chains/{formatters/celo.ts → celo/formatters.ts} +29 -48
  278. package/src/chains/{serializers/celo.ts → celo/serializers.ts} +5 -5
  279. package/src/chains/celo/types.ts +111 -0
  280. package/src/chains/index.ts +23 -7
  281. package/src/chains/optimism/fees.ts +5 -0
  282. package/src/chains/optimism/formatters.ts +74 -0
  283. package/src/chains/optimism/types.ts +102 -0
  284. package/src/chains/utils.ts +41 -0
  285. package/src/clients/decorators/public.ts +16 -16
  286. package/src/clients/decorators/wallet.ts +3 -3
  287. package/src/constants/number.ts +96 -96
  288. package/src/errors/node.ts +2 -1
  289. package/src/errors/version.ts +1 -1
  290. package/src/index.ts +25 -8
  291. package/src/types/chain.ts +91 -14
  292. package/src/types/multicall.ts +14 -11
  293. package/src/types/rpc.ts +2 -6
  294. package/src/types/typedData.ts +2 -3
  295. package/src/types/utils.ts +11 -0
  296. package/src/utils/abi/decodeAbiParameters.ts +7 -8
  297. package/src/utils/abi/decodeDeployData.ts +3 -3
  298. package/src/utils/abi/decodeErrorResult.ts +3 -8
  299. package/src/utils/abi/decodeEventLog.ts +3 -3
  300. package/src/utils/abi/decodeFunctionResult.ts +4 -6
  301. package/src/utils/abi/encodeAbiParameters.ts +8 -9
  302. package/src/utils/abi/encodeDeployData.ts +3 -3
  303. package/src/utils/abi/encodeErrorResult.ts +4 -4
  304. package/src/utils/abi/encodeEventTopics.ts +4 -9
  305. package/src/utils/abi/encodeFunctionData.ts +4 -4
  306. package/src/utils/abi/encodeFunctionResult.ts +4 -4
  307. package/src/utils/abi/encodePacked.ts +6 -8
  308. package/src/utils/abi/getAbiItem.ts +3 -3
  309. package/src/utils/chain.ts +21 -10
  310. package/src/utils/formatters/block.ts +8 -6
  311. package/src/utils/formatters/extract.ts +2 -2
  312. package/src/utils/formatters/formatter.ts +2 -2
  313. package/src/utils/formatters/transaction.ts +8 -6
  314. package/src/utils/formatters/transactionReceipt.ts +9 -3
  315. package/src/utils/formatters/transactionRequest.ts +9 -3
  316. package/src/utils/poll.ts +1 -1
  317. package/src/utils/signature/hashTypedData.ts +1 -1
  318. package/src/utils/signature/recoverTypedDataAddress.ts +1 -1
  319. package/src/utils/signature/verifyTypedData.ts +1 -1
  320. package/src/utils/transaction/prepareRequest.ts +48 -22
  321. package/src/utils/typedData.ts +2 -3
  322. package/dist/cjs/chains/formatters/celo.js.map +0 -1
  323. package/dist/cjs/chains/formatters/optimism.js.map +0 -1
  324. package/dist/cjs/chains/serializers/celo.js.map +0 -1
  325. package/dist/cjs/types/formatter.js.map +0 -1
  326. package/dist/cjs/types/serializer.js.map +0 -1
  327. package/dist/esm/chains/formatters/celo.js.map +0 -1
  328. package/dist/esm/chains/formatters/optimism.js.map +0 -1
  329. package/dist/esm/chains/serializers/celo.js.map +0 -1
  330. package/dist/esm/types/formatter.js +0 -2
  331. package/dist/esm/types/formatter.js.map +0 -1
  332. package/dist/esm/types/serializer.js +0 -2
  333. package/dist/esm/types/serializer.js.map +0 -1
  334. package/dist/types/chains/formatters/celo.d.ts.map +0 -1
  335. package/dist/types/chains/formatters/optimism.d.ts.map +0 -1
  336. package/dist/types/chains/serializers/celo.d.ts.map +0 -1
  337. package/dist/types/types/formatter.d.ts +0 -17
  338. package/dist/types/types/formatter.d.ts.map +0 -1
  339. package/dist/types/types/serializer.d.ts +0 -7
  340. package/dist/types/types/serializer.d.ts.map +0 -1
  341. package/src/chains/formatters/optimism.ts +0 -91
  342. package/src/types/formatter.ts +0 -42
  343. package/src/types/serializer.ts +0 -19
@@ -1,4 +1,4 @@
1
- import type { Abi, Address, Narrow } from 'abitype'
1
+ import type { Abi, Address } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -28,7 +28,7 @@ export type CreateContractEventFilterParameters<
28
28
  TToBlock extends BlockNumber | BlockTag | undefined = undefined,
29
29
  > = {
30
30
  address?: Address | Address[]
31
- abi: Narrow<TAbi>
31
+ abi: TAbi
32
32
  eventName?: InferEventName<TAbi, TEventName>
33
33
  fromBlock?: TFromBlock | BlockNumber | BlockTag
34
34
  /**
@@ -87,7 +87,7 @@ export type CreateContractEventFilterReturnType<
87
87
  */
88
88
  export async function createContractEventFilter<
89
89
  TChain extends Chain | undefined,
90
- TAbi extends Abi | readonly unknown[],
90
+ const TAbi extends Abi | readonly unknown[],
91
91
  TEventName extends string | undefined,
92
92
  TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
93
93
  TStrict extends boolean | undefined = undefined,
@@ -1,4 +1,4 @@
1
- import type { AbiEvent, Address, Narrow } from 'abitype'
1
+ import type { AbiEvent, Address } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -44,7 +44,7 @@ export type CreateEventFilterParameters<
44
44
  args:
45
45
  | TEventFilterArgs
46
46
  | (_Args extends TEventFilterArgs ? _Args : never)
47
- event: Narrow<TAbiEvent>
47
+ event: TAbiEvent
48
48
  events?: never
49
49
  /**
50
50
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
@@ -54,7 +54,7 @@ export type CreateEventFilterParameters<
54
54
  }
55
55
  | {
56
56
  args?: never
57
- event?: Narrow<TAbiEvent>
57
+ event?: TAbiEvent
58
58
  events?: never
59
59
  /**
60
60
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
@@ -65,7 +65,7 @@ export type CreateEventFilterParameters<
65
65
  | {
66
66
  args?: never
67
67
  event?: never
68
- events: Narrow<TAbiEvents>
68
+ events: TAbiEvents
69
69
  /**
70
70
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
71
71
  * @default false
@@ -127,8 +127,8 @@ export type CreateEventFilterReturnType<
127
127
  */
128
128
  export async function createEventFilter<
129
129
  TChain extends Chain | undefined,
130
- TAbiEvent extends AbiEvent | undefined = undefined,
131
- TAbiEvents extends
130
+ const TAbiEvent extends AbiEvent | undefined = undefined,
131
+ const TAbiEvents extends
132
132
  | readonly AbiEvent[]
133
133
  | readonly unknown[]
134
134
  | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
@@ -60,7 +60,7 @@ export type EstimateContractGasReturnType = bigint
60
60
  * })
61
61
  */
62
62
  export async function estimateContractGas<
63
- TAbi extends Abi | readonly unknown[],
63
+ const TAbi extends Abi | readonly unknown[],
64
64
  TFunctionName extends string,
65
65
  TChain extends Chain | undefined,
66
66
  TAccount extends Account | undefined = undefined,
@@ -20,7 +20,10 @@ import {
20
20
  type AssertRequestParameters,
21
21
  assertRequest,
22
22
  } from '../../utils/transaction/assertRequest.js'
23
- import { prepareRequest } from '../../utils/transaction/prepareRequest.js'
23
+ import {
24
+ type PrepareRequestParameters,
25
+ prepareRequest,
26
+ } from '../../utils/transaction/prepareRequest.js'
24
27
 
25
28
  export type FormattedEstimateGas<
26
29
  TChain extends Chain | undefined = Chain | undefined,
@@ -102,7 +105,13 @@ export async function estimateGas<
102
105
  to,
103
106
  value,
104
107
  ...rest
105
- } = account.type === 'local' ? await prepareRequest(client, args) : args
108
+ } =
109
+ account.type === 'local'
110
+ ? ((await prepareRequest(
111
+ client,
112
+ args as PrepareRequestParameters,
113
+ )) as EstimateGasParameters)
114
+ : args
106
115
 
107
116
  const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
108
117
  const block = blockNumberHex || blockTag
@@ -138,7 +138,7 @@ export async function getFilterChanges<
138
138
  TTransport extends Transport,
139
139
  TChain extends Chain | undefined,
140
140
  TFilterType extends FilterType,
141
- TAbi extends Abi | readonly unknown[] | undefined,
141
+ const TAbi extends Abi | readonly unknown[] | undefined,
142
142
  TEventName extends string | undefined,
143
143
  TStrict extends boolean | undefined = undefined,
144
144
  TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
@@ -67,7 +67,7 @@ export type GetFilterLogsReturnType<
67
67
  */
68
68
  export async function getFilterLogs<
69
69
  TChain extends Chain | undefined,
70
- TAbi extends Abi | readonly unknown[] | undefined,
70
+ const TAbi extends Abi | readonly unknown[] | undefined,
71
71
  TEventName extends string | undefined,
72
72
  TStrict extends boolean | undefined = undefined,
73
73
  TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
@@ -1,4 +1,4 @@
1
- import type { Abi, AbiEvent, Address, Narrow } from 'abitype'
1
+ import type { Abi, AbiEvent, Address } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
@@ -38,7 +38,7 @@ export type GetLogsParameters<
38
38
  address?: Address | Address[]
39
39
  } & (
40
40
  | {
41
- event: Narrow<TAbiEvent>
41
+ event: TAbiEvent
42
42
  events?: never
43
43
  args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
44
44
  /**
@@ -49,7 +49,7 @@ export type GetLogsParameters<
49
49
  }
50
50
  | {
51
51
  event?: never
52
- events: Narrow<TAbiEvents>
52
+ events: TAbiEvents
53
53
  args?: never
54
54
  /**
55
55
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
@@ -119,8 +119,8 @@ export type GetLogsReturnType<
119
119
  */
120
120
  export async function getLogs<
121
121
  TChain extends Chain | undefined,
122
- TAbiEvent extends AbiEvent | undefined = undefined,
123
- TAbiEvents extends
122
+ const TAbiEvent extends AbiEvent | undefined = undefined,
123
+ const TAbiEvents extends
124
124
  | readonly AbiEvent[]
125
125
  | readonly unknown[]
126
126
  | undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
@@ -80,8 +80,8 @@ export type MulticallReturnType<
80
80
  * // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
81
81
  */
82
82
  export async function multicall<
83
- TChain extends Chain | undefined,
84
83
  TContracts extends ContractFunctionConfig[],
84
+ TChain extends Chain | undefined,
85
85
  TAllowFailure extends boolean = true,
86
86
  >(
87
87
  client: Client<Transport, TChain>,
@@ -92,7 +92,7 @@ export async function multicall<
92
92
  batchSize: batchSize_,
93
93
  blockNumber,
94
94
  blockTag,
95
- contracts: contracts_,
95
+ contracts,
96
96
  multicallAddress: multicallAddress_,
97
97
  } = args
98
98
 
@@ -102,9 +102,6 @@ export async function multicall<
102
102
  client.batch.multicall.batchSize) ||
103
103
  1_024)
104
104
 
105
- // Fix type cast from `Narrow` in type definition.
106
- const contracts = contracts_ as readonly [...MulticallContracts<TContracts>]
107
-
108
105
  let multicallAddress = multicallAddress_
109
106
  if (!multicallAddress) {
110
107
  if (!client.chain)
@@ -129,7 +126,9 @@ export async function multicall<
129
126
  let currentChunk = 0
130
127
  let currentChunkSize = 0
131
128
  for (let i = 0; i < contracts.length; i++) {
132
- const { abi, address, args, functionName } = contracts[i]
129
+ const { abi, address, args, functionName } = contracts[
130
+ i
131
+ ] as ContractFunctionConfig
133
132
  try {
134
133
  const callData = encodeFunctionData({
135
134
  abi,
@@ -188,7 +187,9 @@ export async function multicall<
188
187
  return results.flat().map(({ returnData, success }, i) => {
189
188
  const calls = chunkedCalls.flat()
190
189
  const { callData } = calls[i]
191
- const { abi, address, functionName, args } = contracts[i]
190
+ const { abi, address, functionName, args } = contracts[
191
+ i
192
+ ] as ContractFunctionConfig
192
193
  try {
193
194
  if (callData === '0x') throw new AbiDecodingZeroDataError()
194
195
  if (!success) throw new RawContractError({ data: returnData })
@@ -196,7 +197,7 @@ export async function multicall<
196
197
  abi,
197
198
  args,
198
199
  data: returnData,
199
- functionName: functionName,
200
+ functionName,
200
201
  })
201
202
  return allowFailure ? { result, status: 'success' } : result
202
203
  } catch (err) {
@@ -64,7 +64,7 @@ export type ReadContractReturnType<
64
64
  */
65
65
  export async function readContract<
66
66
  TChain extends Chain | undefined,
67
- TAbi extends Abi | readonly unknown[],
67
+ const TAbi extends Abi | readonly unknown[],
68
68
  TFunctionName extends string,
69
69
  >(
70
70
  client: Client<Transport, TChain>,
@@ -29,7 +29,7 @@ export type SimulateContractParameters<
29
29
  TAbi extends Abi | readonly unknown[] = Abi,
30
30
  TFunctionName extends string = any,
31
31
  TChain extends Chain | undefined = Chain | undefined,
32
- TChainOverride extends Chain | undefined = undefined,
32
+ TChainOverride extends Chain | undefined = Chain | undefined,
33
33
  > = {
34
34
  chain?: TChainOverride
35
35
  /** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
@@ -51,7 +51,7 @@ export type SimulateContractReturnType<
51
51
  TAbi extends Abi | readonly unknown[] = Abi,
52
52
  TFunctionName extends string = string,
53
53
  TChain extends Chain | undefined = Chain | undefined,
54
- TChainOverride extends Chain | undefined = undefined,
54
+ TChainOverride extends Chain | undefined = Chain | undefined,
55
55
  > = {
56
56
  result: ContractFunctionResult<TAbi, TFunctionName>
57
57
  request: UnionOmit<
@@ -102,7 +102,7 @@ export type SimulateContractReturnType<
102
102
  */
103
103
  export async function simulateContract<
104
104
  TChain extends Chain | undefined,
105
- TAbi extends Abi | readonly unknown[],
105
+ const TAbi extends Abi | readonly unknown[],
106
106
  TFunctionName extends string,
107
107
  TChainOverride extends Chain | undefined,
108
108
  >(
@@ -1,11 +1,14 @@
1
- import type { Abi, AbiEvent, Address, ExtractAbiEvent, Narrow } from 'abitype'
1
+ import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
+ import type { EncodeEventTopicsParameters, LogTopic } from '../../index.js'
5
6
  import type { Chain } from '../../types/chain.js'
6
7
  import type { GetEventArgs, InferEventName } from '../../types/contract.js'
7
8
  import type { Filter } from '../../types/filter.js'
8
9
  import type { Log } from '../../types/log.js'
10
+ import type { GetTransportConfig } from '../../types/transport.js'
11
+
9
12
  import {
10
13
  type GetAbiItemParameters,
11
14
  getAbiItem,
@@ -14,7 +17,14 @@ import { observe } from '../../utils/observe.js'
14
17
  import { poll } from '../../utils/poll.js'
15
18
  import { stringify } from '../../utils/stringify.js'
16
19
 
17
- import { InvalidInputRpcError } from '../../index.js'
20
+ import { DecodeLogDataMismatch } from '../../errors/abi.js'
21
+ import {
22
+ DecodeLogTopicsMismatch,
23
+ InvalidInputRpcError,
24
+ decodeEventLog,
25
+ encodeEventTopics,
26
+ formatLog,
27
+ } from '../../index.js'
18
28
  import {
19
29
  type CreateContractEventFilterParameters,
20
30
  createContractEventFilter,
@@ -24,6 +34,19 @@ import { getFilterChanges } from './getFilterChanges.js'
24
34
  import { getLogs } from './getLogs.js'
25
35
  import { uninstallFilter } from './uninstallFilter.js'
26
36
 
37
+ type PollOptions = {
38
+ /**
39
+ * Whether or not the transaction hashes should be batched on each invocation.
40
+ * @default true
41
+ */
42
+ batch?: boolean
43
+ /**
44
+ * Polling frequency (in ms). Defaults to Client's pollingInterval config.
45
+ * @default client.pollingInterval
46
+ */
47
+ pollingInterval?: number
48
+ }
49
+
27
50
  export type WatchContractEventOnLogsParameter<
28
51
  TAbi extends Abi | readonly unknown[] = readonly unknown[],
29
52
  TEventName extends string = string,
@@ -45,24 +68,40 @@ export type WatchContractEventParameters<
45
68
  /** The address of the contract. */
46
69
  address?: Address | Address[]
47
70
  /** Contract ABI. */
48
- abi: Narrow<TAbi>
71
+ abi: TAbi
49
72
  args?: GetEventArgs<TAbi, TEventName>
50
- /** Whether or not the event logs should be batched on each invocation. */
51
- batch?: boolean
52
73
  /** Contract event. */
53
74
  eventName?: InferEventName<TAbi, TEventName>
54
75
  /** The callback to call when an error occurred when trying to get for a new block. */
55
76
  onError?: (error: Error) => void
56
77
  /** The callback to call when new event logs are received. */
57
78
  onLogs: WatchContractEventOnLogsFn<TAbi, TEventName, TStrict>
58
- /** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
59
- pollingInterval?: number
60
79
  /**
61
80
  * Whether or not the logs must match the indexed/non-indexed arguments on `event`.
62
81
  * @default false
63
82
  */
64
83
  strict?: TStrict
65
- }
84
+ } & (GetTransportConfig<Transport>['type'] extends 'webSocket'
85
+ ?
86
+ | {
87
+ batch?: never
88
+ /**
89
+ * Whether or not the WebSocket Transport should poll the JSON-RPC, rather than using `eth_subscribe`.
90
+ * @default false
91
+ */
92
+ poll?: false
93
+ pollingInterval?: never
94
+ }
95
+ | (PollOptions & {
96
+ /**
97
+ * Whether or not the WebSocket Transport should poll the JSON-RPC, rather than using `eth_subscribe`.
98
+ * @default true
99
+ */
100
+ poll?: true
101
+ })
102
+ : PollOptions & {
103
+ poll?: true
104
+ })
66
105
 
67
106
  export type WatchContractEventReturnType = () => void
68
107
 
@@ -98,7 +137,7 @@ export type WatchContractEventReturnType = () => void
98
137
  */
99
138
  export function watchContractEvent<
100
139
  TChain extends Chain | undefined,
101
- TAbi extends Abi | readonly unknown[],
140
+ const TAbi extends Abi | readonly unknown[],
102
141
  TEventName extends string,
103
142
  TStrict extends boolean | undefined = undefined,
104
143
  >(
@@ -111,96 +150,171 @@ export function watchContractEvent<
111
150
  eventName,
112
151
  onError,
113
152
  onLogs,
153
+ poll: poll_,
114
154
  pollingInterval = client.pollingInterval,
115
155
  strict: strict_,
116
156
  }: WatchContractEventParameters<TAbi, TEventName, TStrict>,
117
157
  ): WatchContractEventReturnType {
118
- const observerId = stringify([
119
- 'watchContractEvent',
120
- address,
121
- args,
122
- batch,
123
- client.uid,
124
- eventName,
125
- pollingInterval,
126
- ])
127
- const strict = strict_ ?? false
128
-
129
- return observe(observerId, { onLogs, onError }, (emit) => {
130
- let previousBlockNumber: bigint
131
- let filter: Filter<'event', TAbi, TEventName> | undefined
132
- let initialized = false
133
-
134
- const unwatch = poll(
135
- async () => {
136
- if (!initialized) {
137
- try {
138
- filter = (await createContractEventFilter(client, {
139
- abi,
140
- address,
141
- args,
142
- eventName,
143
- strict,
144
- } as unknown as CreateContractEventFilterParameters)) as Filter<
145
- 'event',
146
- TAbi,
147
- TEventName
148
- >
149
- } catch {}
150
- initialized = true
151
- return
152
- }
158
+ const enablePolling =
159
+ typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
153
160
 
154
- try {
155
- let logs: Log[]
156
- if (filter) {
157
- logs = await getFilterChanges(client, { filter })
158
- } else {
159
- // If the filter doesn't exist, we will fall back to use `getLogs`.
160
- // The fall back exists because some RPC Providers do not support filters.
161
-
162
- // Fetch the block number to use for `getLogs`.
163
- const blockNumber = await getBlockNumber(client)
164
-
165
- // If the block number has changed, we will need to fetch the logs.
166
- // If the block number doesn't exist, we are yet to reach the first poll interval,
167
- // so do not emit any logs.
168
- if (previousBlockNumber && previousBlockNumber !== blockNumber) {
169
- logs = await getLogs(client, {
161
+ const pollContractEvent = () => {
162
+ const observerId = stringify([
163
+ 'watchContractEvent',
164
+ address,
165
+ args,
166
+ batch,
167
+ client.uid,
168
+ eventName,
169
+ pollingInterval,
170
+ ])
171
+ const strict = strict_ ?? false
172
+
173
+ return observe(observerId, { onLogs, onError }, (emit) => {
174
+ let previousBlockNumber: bigint
175
+ let filter: Filter<'event', TAbi, TEventName> | undefined
176
+ let initialized = false
177
+
178
+ const unwatch = poll(
179
+ async () => {
180
+ if (!initialized) {
181
+ try {
182
+ filter = (await createContractEventFilter(client, {
183
+ abi,
170
184
  address,
171
185
  args,
172
- fromBlock: previousBlockNumber + 1n,
173
- toBlock: blockNumber,
174
- event: getAbiItem({
175
- abi,
176
- name: eventName,
177
- } as unknown as GetAbiItemParameters) as AbiEvent,
178
- })
186
+ eventName,
187
+ strict,
188
+ } as unknown as CreateContractEventFilterParameters)) as Filter<
189
+ 'event',
190
+ TAbi,
191
+ TEventName
192
+ >
193
+ } catch {}
194
+ initialized = true
195
+ return
196
+ }
197
+
198
+ try {
199
+ let logs: Log[]
200
+ if (filter) {
201
+ logs = await getFilterChanges(client, { filter })
179
202
  } else {
180
- logs = []
203
+ // If the filter doesn't exist, we will fall back to use `getLogs`.
204
+ // The fall back exists because some RPC Providers do not support filters.
205
+
206
+ // Fetch the block number to use for `getLogs`.
207
+ const blockNumber = await getBlockNumber(client)
208
+
209
+ // If the block number has changed, we will need to fetch the logs.
210
+ // If the block number doesn't exist, we are yet to reach the first poll interval,
211
+ // so do not emit any logs.
212
+ if (previousBlockNumber && previousBlockNumber !== blockNumber) {
213
+ logs = await getLogs(client, {
214
+ address,
215
+ args,
216
+ fromBlock: previousBlockNumber + 1n,
217
+ toBlock: blockNumber,
218
+ event: getAbiItem({
219
+ abi,
220
+ name: eventName,
221
+ } as unknown as GetAbiItemParameters) as AbiEvent,
222
+ })
223
+ } else {
224
+ logs = []
225
+ }
226
+ previousBlockNumber = blockNumber
181
227
  }
182
- previousBlockNumber = blockNumber
228
+
229
+ if (logs.length === 0) return
230
+ if (batch) emit.onLogs(logs as any)
231
+ else logs.forEach((log) => emit.onLogs([log] as any))
232
+ } catch (err) {
233
+ // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
234
+ // Reinitalize the filter when this occurs
235
+ if (filter && err instanceof InvalidInputRpcError)
236
+ initialized = false
237
+ emit.onError?.(err as Error)
183
238
  }
239
+ },
240
+ {
241
+ emitOnBegin: true,
242
+ interval: pollingInterval,
243
+ },
244
+ )
184
245
 
185
- if (logs.length === 0) return
186
- if (batch) emit.onLogs(logs as any)
187
- else logs.forEach((log) => emit.onLogs([log] as any))
188
- } catch (err) {
189
- // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
190
- // Reinitalize the filter when this occurs
191
- if (filter && err instanceof InvalidInputRpcError) initialized = false
192
- emit.onError?.(err as Error)
193
- }
194
- },
195
- {
196
- emitOnBegin: true,
197
- interval: pollingInterval,
198
- },
199
- )
200
-
201
- return async () => {
202
- if (filter) await uninstallFilter(client, { filter })
203
- unwatch()
204
- }
205
- })
246
+ return async () => {
247
+ if (filter) await uninstallFilter(client, { filter })
248
+ unwatch()
249
+ }
250
+ })
251
+ }
252
+
253
+ const subscribeContractEvent = () => {
254
+ let active = true
255
+ let unsubscribe = () => (active = false)
256
+ ;(async () => {
257
+ try {
258
+ const topics: LogTopic[] = eventName
259
+ ? encodeEventTopics({
260
+ abi: abi,
261
+ eventName: eventName,
262
+ args,
263
+ } as EncodeEventTopicsParameters)
264
+ : []
265
+
266
+ const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
267
+ params: ['logs', { address, topics }],
268
+ onData(data: any) {
269
+ if (!active) return
270
+ const log = data.result
271
+ try {
272
+ const { eventName, args } = decodeEventLog({
273
+ abi: abi,
274
+ data: log.data,
275
+ topics: log.topics as any,
276
+ strict: strict_,
277
+ })
278
+ const formatted = formatLog(log, {
279
+ args,
280
+ eventName: eventName as string,
281
+ })
282
+ onLogs([formatted] as any)
283
+ } catch (err) {
284
+ let eventName
285
+ let isUnnamed
286
+ if (
287
+ err instanceof DecodeLogDataMismatch ||
288
+ err instanceof DecodeLogTopicsMismatch
289
+ ) {
290
+ // If strict mode is on, and log data/topics do not match event definition, skip.
291
+ if (strict_) return
292
+ eventName = err.abiItem.name
293
+ isUnnamed = err.abiItem.inputs?.some(
294
+ (x) => !('name' in x && x.name),
295
+ )
296
+ }
297
+
298
+ // Set args to empty if there is an error decoding (e.g. indexed/non-indexed params mismatch).
299
+ const formatted = formatLog(log, {
300
+ args: isUnnamed ? [] : {},
301
+ eventName,
302
+ })
303
+ onLogs([formatted] as any)
304
+ }
305
+ },
306
+ onError(error: Error) {
307
+ onError?.(error)
308
+ },
309
+ })
310
+ unsubscribe = unsubscribe_
311
+ if (!active) unsubscribe()
312
+ } catch (err) {
313
+ onError?.(err as Error)
314
+ }
315
+ })()
316
+ return unsubscribe
317
+ }
318
+
319
+ return enablePolling ? pollContractEvent() : subscribeContractEvent()
206
320
  }