hardhat 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/src/internal/builtin-global-options.d.ts.map +1 -1
  3. package/dist/src/internal/builtin-global-options.js +14 -1
  4. package/dist/src/internal/builtin-global-options.js.map +1 -1
  5. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts +0 -5
  6. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.d.ts.map +1 -1
  7. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js +12 -3
  8. package/dist/src/internal/builtin-plugins/gas-analytics/helpers.js.map +1 -1
  9. package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.d.ts.map +1 -1
  10. package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.js +12 -2
  11. package/dist/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.js.map +1 -1
  12. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts +9 -3
  13. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.d.ts.map +1 -1
  14. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js +65 -42
  15. package/dist/src/internal/builtin-plugins/network-manager/edr/edr-provider.js.map +1 -1
  16. package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts +11 -0
  17. package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.d.ts.map +1 -0
  18. package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js +104 -0
  19. package/dist/src/internal/builtin-plugins/network-manager/edr/genesis-state.js.map +1 -0
  20. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.d.ts +6 -0
  21. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.d.ts.map +1 -0
  22. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.js +152 -0
  23. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.js.map +1 -0
  24. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.d.ts +19 -0
  25. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.d.ts.map +1 -0
  26. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.js +104 -0
  27. package/dist/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.js.map +1 -0
  28. package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js +1 -1
  29. package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/hre.js.map +1 -1
  30. package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.d.ts.map +1 -1
  31. package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js +8 -8
  32. package/dist/src/internal/builtin-plugins/network-manager/hook-handlers/network.js.map +1 -1
  33. package/dist/src/internal/builtin-plugins/network-manager/http-provider.d.ts.map +1 -1
  34. package/dist/src/internal/builtin-plugins/network-manager/http-provider.js +1 -0
  35. package/dist/src/internal/builtin-plugins/network-manager/http-provider.js.map +1 -1
  36. package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts +1 -1
  37. package/dist/src/internal/builtin-plugins/network-manager/network-manager.d.ts.map +1 -1
  38. package/dist/src/internal/builtin-plugins/network-manager/network-manager.js +63 -7
  39. package/dist/src/internal/builtin-plugins/network-manager/network-manager.js.map +1 -1
  40. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.d.ts.map +1 -1
  41. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.js +56 -33
  42. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.js.map +1 -1
  43. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.d.ts +0 -3
  44. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.d.ts.map +1 -1
  45. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.js +9 -12
  46. package/dist/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.js.map +1 -1
  47. package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.d.ts.map +1 -1
  48. package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js +1 -1
  49. package/dist/src/internal/builtin-plugins/node/artifacts/build-info-watcher.js.map +1 -1
  50. package/dist/src/internal/builtin-plugins/node/helpers.d.ts.map +1 -1
  51. package/dist/src/internal/builtin-plugins/node/helpers.js +6 -2
  52. package/dist/src/internal/builtin-plugins/node/helpers.js.map +1 -1
  53. package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.d.ts.map +1 -1
  54. package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.js +4 -0
  55. package/dist/src/internal/builtin-plugins/solidity/build-system/artifacts.js.map +1 -1
  56. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts +5 -1
  57. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.d.ts.map +1 -1
  58. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js +86 -47
  59. package/dist/src/internal/builtin-plugins/solidity/build-system/build-system.js.map +1 -1
  60. package/dist/src/internal/builtin-plugins/solidity/build-system/cache.d.ts +1 -0
  61. package/dist/src/internal/builtin-plugins/solidity/build-system/cache.d.ts.map +1 -1
  62. package/dist/src/internal/builtin-plugins/solidity/build-system/cache.js.map +1 -1
  63. package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.d.ts +3 -3
  64. package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.d.ts.map +1 -1
  65. package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js +24 -4
  66. package/dist/src/internal/builtin-plugins/solidity/build-system/compilation-job.js.map +1 -1
  67. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.d.ts +16 -0
  68. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.d.ts.map +1 -1
  69. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js +1 -1
  70. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.js.map +1 -1
  71. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.d.ts.map +1 -1
  72. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js +1 -1
  73. package/dist/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.js.map +1 -1
  74. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts +2 -2
  75. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.d.ts.map +1 -1
  76. package/dist/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.js.map +1 -1
  77. package/dist/src/internal/builtin-plugins/solidity/config.d.ts +4 -2
  78. package/dist/src/internal/builtin-plugins/solidity/config.d.ts.map +1 -1
  79. package/dist/src/internal/builtin-plugins/solidity/config.js +247 -68
  80. package/dist/src/internal/builtin-plugins/solidity/config.js.map +1 -1
  81. package/dist/src/internal/builtin-plugins/solidity/exports.d.ts +3 -0
  82. package/dist/src/internal/builtin-plugins/solidity/exports.d.ts.map +1 -0
  83. package/dist/src/internal/builtin-plugins/solidity/exports.js +3 -0
  84. package/dist/src/internal/builtin-plugins/solidity/exports.js.map +1 -0
  85. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.d.ts.map +1 -1
  86. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js +2 -1
  87. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/config.js.map +1 -1
  88. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.d.ts +4 -0
  89. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.d.ts.map +1 -0
  90. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.js +7 -0
  91. package/dist/src/internal/builtin-plugins/solidity/hook-handlers/solidity.js.map +1 -0
  92. package/dist/src/internal/builtin-plugins/solidity/index.d.ts.map +1 -1
  93. package/dist/src/internal/builtin-plugins/solidity/index.js +1 -0
  94. package/dist/src/internal/builtin-plugins/solidity/index.js.map +1 -1
  95. package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.d.ts +18 -0
  96. package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.d.ts.map +1 -0
  97. package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js +33 -0
  98. package/dist/src/internal/builtin-plugins/solidity/solidity-hooks.js.map +1 -0
  99. package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts +201 -28
  100. package/dist/src/internal/builtin-plugins/solidity/type-extensions.d.ts.map +1 -1
  101. package/dist/src/internal/builtin-plugins/solidity/type-extensions.js.map +1 -1
  102. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts +12 -6
  103. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.d.ts.map +1 -1
  104. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js +9 -7
  105. package/dist/src/internal/builtin-plugins/solidity-test/edr-artifacts.js.map +1 -1
  106. package/dist/src/internal/builtin-plugins/solidity-test/formatters.d.ts +1 -12
  107. package/dist/src/internal/builtin-plugins/solidity-test/formatters.d.ts.map +1 -1
  108. package/dist/src/internal/builtin-plugins/solidity-test/formatters.js +0 -150
  109. package/dist/src/internal/builtin-plugins/solidity-test/formatters.js.map +1 -1
  110. package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts +4 -3
  111. package/dist/src/internal/builtin-plugins/solidity-test/helpers.d.ts.map +1 -1
  112. package/dist/src/internal/builtin-plugins/solidity-test/helpers.js +5 -9
  113. package/dist/src/internal/builtin-plugins/solidity-test/helpers.js.map +1 -1
  114. package/dist/src/internal/builtin-plugins/solidity-test/index.d.ts.map +1 -1
  115. package/dist/src/internal/builtin-plugins/solidity-test/index.js +0 -7
  116. package/dist/src/internal/builtin-plugins/solidity-test/index.js.map +1 -1
  117. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.d.ts +7 -0
  118. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.d.ts.map +1 -0
  119. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.js +20 -0
  120. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/constants.js.map +1 -0
  121. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.d.ts +24 -0
  122. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.d.ts.map +1 -0
  123. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.js +68 -0
  124. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/helpers.js.map +1 -0
  125. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.d.ts +13 -0
  126. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.d.ts.map +1 -0
  127. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.js +136 -0
  128. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/index.js.map +1 -0
  129. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.d.ts +19 -0
  130. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.d.ts.map +1 -0
  131. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.js +133 -0
  132. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/parsing.js.map +1 -0
  133. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.d.ts +10 -0
  134. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.d.ts.map +1 -0
  135. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.js +2 -0
  136. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/types.js.map +1 -0
  137. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.d.ts +12 -0
  138. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.d.ts.map +1 -0
  139. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.js +81 -0
  140. package/dist/src/internal/builtin-plugins/solidity-test/inline-config/validation.js.map +1 -0
  141. package/dist/src/internal/builtin-plugins/solidity-test/reporter.d.ts +1 -1
  142. package/dist/src/internal/builtin-plugins/solidity-test/reporter.d.ts.map +1 -1
  143. package/dist/src/internal/builtin-plugins/solidity-test/reporter.js +5 -2
  144. package/dist/src/internal/builtin-plugins/solidity-test/reporter.js.map +1 -1
  145. package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts +0 -1
  146. package/dist/src/internal/builtin-plugins/solidity-test/task-action.d.ts.map +1 -1
  147. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js +21 -14
  148. package/dist/src/internal/builtin-plugins/solidity-test/task-action.js.map +1 -1
  149. package/dist/src/internal/builtin-plugins/test/index.d.ts.map +1 -1
  150. package/dist/src/internal/builtin-plugins/test/index.js +0 -7
  151. package/dist/src/internal/builtin-plugins/test/index.js.map +1 -1
  152. package/dist/src/internal/builtin-plugins/test/task-action.d.ts +0 -1
  153. package/dist/src/internal/builtin-plugins/test/task-action.d.ts.map +1 -1
  154. package/dist/src/internal/builtin-plugins/test/task-action.js +1 -4
  155. package/dist/src/internal/builtin-plugins/test/task-action.js.map +1 -1
  156. package/dist/src/internal/cli/help/get-help-string.d.ts.map +1 -1
  157. package/dist/src/internal/cli/help/get-help-string.js +1 -1
  158. package/dist/src/internal/cli/help/get-help-string.js.map +1 -1
  159. package/dist/src/internal/cli/init/init.d.ts.map +1 -1
  160. package/dist/src/internal/cli/init/init.js +1 -1
  161. package/dist/src/internal/cli/init/init.js.map +1 -1
  162. package/dist/src/internal/cli/init/prompt.d.ts.map +1 -1
  163. package/dist/src/internal/cli/init/prompt.js +1 -7
  164. package/dist/src/internal/cli/init/prompt.js.map +1 -1
  165. package/dist/src/internal/core/hre.d.ts +2 -1
  166. package/dist/src/internal/core/hre.d.ts.map +1 -1
  167. package/dist/src/internal/core/hre.js +18 -0
  168. package/dist/src/internal/core/hre.js.map +1 -1
  169. package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.d.ts.map +1 -1
  170. package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.js +6 -1
  171. package/dist/src/internal/core/plugins/detect-plugin-npm-dependency-problems.js.map +1 -1
  172. package/dist/src/internal/core/user-interruptions.d.ts.map +1 -1
  173. package/dist/src/internal/core/user-interruptions.js +2 -5
  174. package/dist/src/internal/core/user-interruptions.js.map +1 -1
  175. package/dist/src/internal/utils/colorizer.d.ts +10 -0
  176. package/dist/src/internal/utils/colorizer.d.ts.map +1 -0
  177. package/dist/src/internal/utils/colorizer.js +2 -0
  178. package/dist/src/internal/utils/colorizer.js.map +1 -0
  179. package/dist/src/internal/utils/package.d.ts.map +1 -1
  180. package/dist/src/internal/utils/package.js +1 -1
  181. package/dist/src/internal/utils/package.js.map +1 -1
  182. package/dist/src/types/global-options.d.ts +1 -0
  183. package/dist/src/types/global-options.d.ts.map +1 -1
  184. package/dist/src/types/hooks.d.ts +32 -0
  185. package/dist/src/types/hooks.d.ts.map +1 -1
  186. package/dist/src/types/solidity/compilation-job.d.ts +5 -5
  187. package/dist/src/types/solidity/compilation-job.d.ts.map +1 -1
  188. package/dist/src/types/solidity/solidity-artifacts.d.ts +15 -0
  189. package/dist/src/types/solidity/solidity-artifacts.d.ts.map +1 -1
  190. package/package.json +6 -5
  191. package/src/internal/builtin-global-options.ts +15 -1
  192. package/src/internal/builtin-plugins/gas-analytics/helpers.ts +13 -3
  193. package/src/internal/builtin-plugins/network-manager/accounts/derive-private-keys.ts +25 -3
  194. package/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts +107 -56
  195. package/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts +179 -0
  196. package/src/internal/builtin-plugins/network-manager/edr/utils/trace-formatters.ts +197 -0
  197. package/src/internal/builtin-plugins/network-manager/edr/utils/trace-output.ts +137 -0
  198. package/src/internal/builtin-plugins/network-manager/hook-handlers/hre.ts +1 -0
  199. package/src/internal/builtin-plugins/network-manager/hook-handlers/network.ts +8 -11
  200. package/src/internal/builtin-plugins/network-manager/http-provider.ts +1 -0
  201. package/src/internal/builtin-plugins/network-manager/network-manager.ts +83 -10
  202. package/src/internal/builtin-plugins/network-manager/request-handlers/handlers/accounts/local-accounts.ts +98 -34
  203. package/src/internal/builtin-plugins/network-manager/request-handlers/handlers-array.ts +10 -30
  204. package/src/internal/builtin-plugins/node/artifacts/build-info-watcher.ts +1 -2
  205. package/src/internal/builtin-plugins/node/helpers.ts +9 -2
  206. package/src/internal/builtin-plugins/solidity/build-system/artifacts.ts +7 -2
  207. package/src/internal/builtin-plugins/solidity/build-system/build-system.ts +141 -65
  208. package/src/internal/builtin-plugins/solidity/build-system/cache.ts +1 -0
  209. package/src/internal/builtin-plugins/solidity/build-system/compilation-job.ts +34 -7
  210. package/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts +1 -1
  211. package/src/internal/builtin-plugins/solidity/build-system/compiler/downloader.ts +1 -2
  212. package/src/internal/builtin-plugins/solidity/build-system/solc-config-selection.ts +4 -2
  213. package/src/internal/builtin-plugins/solidity/config.ts +335 -110
  214. package/src/internal/builtin-plugins/solidity/exports.ts +2 -0
  215. package/src/internal/builtin-plugins/solidity/hook-handlers/config.ts +3 -0
  216. package/src/internal/builtin-plugins/solidity/hook-handlers/solidity.ts +9 -0
  217. package/src/internal/builtin-plugins/solidity/index.ts +1 -0
  218. package/src/internal/builtin-plugins/solidity/solidity-hooks.ts +53 -0
  219. package/src/internal/builtin-plugins/solidity/type-extensions.ts +258 -31
  220. package/src/internal/builtin-plugins/solidity-test/edr-artifacts.ts +22 -10
  221. package/src/internal/builtin-plugins/solidity-test/formatters.ts +1 -213
  222. package/src/internal/builtin-plugins/solidity-test/helpers.ts +8 -8
  223. package/src/internal/builtin-plugins/solidity-test/index.ts +0 -7
  224. package/src/internal/builtin-plugins/solidity-test/inline-config/constants.ts +21 -0
  225. package/src/internal/builtin-plugins/solidity-test/inline-config/helpers.ts +99 -0
  226. package/src/internal/builtin-plugins/solidity-test/inline-config/index.ts +272 -0
  227. package/src/internal/builtin-plugins/solidity-test/inline-config/parsing.ts +186 -0
  228. package/src/internal/builtin-plugins/solidity-test/inline-config/types.ts +9 -0
  229. package/src/internal/builtin-plugins/solidity-test/inline-config/validation.ts +122 -0
  230. package/src/internal/builtin-plugins/solidity-test/reporter.ts +6 -6
  231. package/src/internal/builtin-plugins/solidity-test/task-action.ts +42 -25
  232. package/src/internal/builtin-plugins/test/index.ts +0 -7
  233. package/src/internal/builtin-plugins/test/task-action.ts +1 -6
  234. package/src/internal/cli/help/get-help-string.ts +2 -2
  235. package/src/internal/cli/init/init.ts +1 -1
  236. package/src/internal/cli/init/prompt.ts +1 -14
  237. package/src/internal/core/hre.ts +33 -0
  238. package/src/internal/core/plugins/detect-plugin-npm-dependency-problems.ts +8 -1
  239. package/src/internal/core/user-interruptions.ts +3 -5
  240. package/src/internal/utils/colorizer.ts +9 -0
  241. package/src/internal/utils/package.ts +1 -2
  242. package/src/types/global-options.ts +1 -0
  243. package/src/types/hooks.ts +37 -0
  244. package/src/types/solidity/compilation-job.ts +5 -5
  245. package/src/types/solidity/solidity-artifacts.ts +16 -0
  246. package/templates/hardhat-3/01-node-test-runner-viem/package.json +5 -5
  247. package/templates/hardhat-3/02-mocha-ethers/package.json +11 -11
  248. package/templates/hardhat-3/03-minimal/package.json +1 -1
@@ -0,0 +1,137 @@
1
+ import type { Response } from "@nomicfoundation/edr";
2
+
3
+ import chalk from "chalk";
4
+ import debug from "debug";
5
+
6
+ import { formatTraces } from "./trace-formatters.js";
7
+
8
+ const log = debug("hardhat:core:hardhat-network:provider");
9
+
10
+ // Rotating palette for per-connection coloring of trace headers.
11
+ const LABEL_COLORS: Array<(text: string) => string> = [
12
+ chalk.cyan,
13
+ chalk.magenta,
14
+ chalk.blueBright,
15
+ chalk.yellowBright,
16
+ chalk.cyanBright,
17
+ chalk.magentaBright,
18
+ ];
19
+
20
+ // Keyed by `network name` (not connection label) so the map stays bounded
21
+ // by the number of distinct networks, not the number of connections.
22
+ const networkColorMap = new Map<string, (text: string) => string>();
23
+
24
+ // These methods run a simulation before the actual transaction. We skip
25
+ // their traces on success to avoid duplicates, but still show them on
26
+ // failure since the real transaction won't be sent.
27
+ const TRACE_SUPPRESSED_METHODS = new Set(["eth_estimateGas"]);
28
+
29
+ // Bounded set: receipt-polling deduplication only needs a small window.
30
+ // Once the cap is reached the set is cleared so memory stays bounded
31
+ // in long-running nodes.
32
+ const TRACED_TX_HASHES_CAP = 1024;
33
+
34
+ /**
35
+ * Manages trace output formatting, deduplication, and coloring for a single
36
+ * provider connection.
37
+ */
38
+ export class TraceOutputManager {
39
+ readonly #printLineFn: (line: string) => void;
40
+ readonly #connectionLabel: string;
41
+ readonly #labelColor: (text: string) => string;
42
+ readonly #verbosity: number;
43
+ readonly #tracedTxHashes = new Set<string>();
44
+
45
+ constructor(
46
+ printLineFn: (line: string) => void,
47
+ connectionId: number,
48
+ networkName: string,
49
+ verbosity: number,
50
+ ) {
51
+ this.#printLineFn = printLineFn;
52
+ this.#connectionLabel = `connection #${connectionId} (${networkName})`;
53
+ this.#labelColor = this.#colorForNetwork(networkName);
54
+ this.#verbosity = verbosity;
55
+ }
56
+
57
+ /**
58
+ * Output call traces from an EDR response, applying deduplication and
59
+ * suppression rules based on the verbosity level.
60
+ */
61
+ public outputCallTraces(
62
+ edrResponse: Response,
63
+ method: string,
64
+ txHash: string | undefined,
65
+ failed: boolean,
66
+ ): void {
67
+ try {
68
+ // At verbosity < 5, suppress simulation-only methods on success and
69
+ // deduplicate traces for the same transaction. At verbosity >= 5
70
+ // (#showAllTraces), every RPC call with traces is shown.
71
+
72
+ if (this.#verbosity < 5) {
73
+ // Skip successful simulation-only methods, their trace will appear
74
+ // again in the subsequent eth_sendTransaction. Failed simulations
75
+ // are shown because the sendTransaction may never happen.
76
+ if (!failed && TRACE_SUPPRESSED_METHODS.has(method)) {
77
+ return;
78
+ }
79
+
80
+ // Dedup: skip if we already traced this transaction.
81
+ // Prevents the same tx appearing multiple times from receipt polling.
82
+ if (txHash !== undefined && this.#tracedTxHashes.has(txHash)) {
83
+ return;
84
+ }
85
+ }
86
+
87
+ const rawTraces = edrResponse.callTraces();
88
+
89
+ // EDR returns duplicate traces for eth_estimateGas, take only the first.
90
+ const callTraces =
91
+ TRACE_SUPPRESSED_METHODS.has(method) && rawTraces.length > 1
92
+ ? [rawTraces[0]]
93
+ : rawTraces;
94
+
95
+ if (callTraces.length === 0) {
96
+ return;
97
+ }
98
+
99
+ if (txHash !== undefined) {
100
+ if (this.#tracedTxHashes.size >= TRACED_TX_HASHES_CAP) {
101
+ this.#tracedTxHashes.clear();
102
+ }
103
+
104
+ this.#tracedTxHashes.add(txHash);
105
+ }
106
+
107
+ const coloredLabel = this.#labelColor(this.#connectionLabel);
108
+ const prefix = callTraces.length > 1 ? "Traces from" : "Trace from";
109
+ const coloredPrefix = this.#labelColor(prefix);
110
+ const styledMethod = failed ? chalk.red(method) : chalk.dim(method);
111
+ const header = `${coloredPrefix} ${coloredLabel}: ${styledMethod}`;
112
+
113
+ this.#printLineFn(`${header}\n${formatTraces(callTraces, " ", chalk)}`);
114
+ } catch (e) {
115
+ log("Failed to get call traces: %O", e);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Clear the dedup set (e.g. on snapshot revert so replayed txs are traced again).
121
+ */
122
+ public clearTracedHashes(): void {
123
+ this.#tracedTxHashes.clear();
124
+ }
125
+
126
+ #colorForNetwork(networkName: string): (text: string) => string {
127
+ let color = networkColorMap.get(networkName);
128
+
129
+ if (color === undefined) {
130
+ const index = networkColorMap.size % LABEL_COLORS.length;
131
+ color = LABEL_COLORS[index];
132
+ networkColorMap.set(networkName, color);
133
+ }
134
+
135
+ return color;
136
+ }
137
+ }
@@ -50,5 +50,6 @@ async function createNetworkManager(
50
50
  hre.config.chainDescriptors,
51
51
  hre.globalOptions.config,
52
52
  hre.config.paths.root,
53
+ hre.globalOptions.verbosity,
53
54
  );
54
55
  }
@@ -9,10 +9,10 @@ import type {
9
9
  } from "../../../../types/providers.js";
10
10
  import type { RequestHandler } from "../request-handlers/types.js";
11
11
 
12
- import { deepClone } from "@nomicfoundation/hardhat-utils/lang";
13
12
  import { AsyncMutex } from "@nomicfoundation/hardhat-utils/synchronization";
14
13
 
15
14
  import { isJsonRpcResponse } from "../json-rpc.js";
15
+ import { createHandlersArray } from "../request-handlers/handlers-array.js";
16
16
 
17
17
  export default async (): Promise<Partial<NetworkHooks>> => {
18
18
  // This map is essential for managing multiple network connections in Hardhat V3.
@@ -38,10 +38,6 @@ export default async (): Promise<Partial<NetworkHooks>> => {
38
38
  nextJsonRpcRequest: JsonRpcRequest,
39
39
  ) => Promise<JsonRpcResponse>,
40
40
  ) {
41
- const { createHandlersArray } = await import(
42
- "../request-handlers/handlers-array.js"
43
- );
44
-
45
41
  const requestHandlers = await initializationMutex.exclusiveRun(
46
42
  async () => {
47
43
  let handlersPerConnection =
@@ -61,21 +57,22 @@ export default async (): Promise<Partial<NetworkHooks>> => {
61
57
  },
62
58
  );
63
59
 
64
- // We clone the request to avoid interfering with other hook handlers that
65
- // might be using the original request.
66
- let request = await deepClone(jsonRpcRequest);
60
+ // We previously cloned here, but the performance impact is significant.
61
+ // TODO: ensure the passed in request is not mutated by adapting the
62
+ // handlers being applied here. See https://github.com/NomicFoundation/hardhat/issues/8090
63
+ let updatedRequest = jsonRpcRequest;
67
64
 
68
65
  for (const handler of requestHandlers) {
69
- const newRequestOrResponse = await handler.handle(request);
66
+ const newRequestOrResponse = await handler.handle(updatedRequest);
70
67
 
71
68
  if (isJsonRpcResponse(newRequestOrResponse)) {
72
69
  return newRequestOrResponse;
73
70
  }
74
71
 
75
- request = newRequestOrResponse;
72
+ updatedRequest = newRequestOrResponse;
76
73
  }
77
74
 
78
- return next(context, networkConnection, request);
75
+ return next(context, networkConnection, updatedRequest);
79
76
  },
80
77
 
81
78
  async closeConnection<ChainTypeT extends ChainType | string>(
@@ -161,6 +161,7 @@ export class HttpProvider extends BaseProvider {
161
161
  }
162
162
 
163
163
  public async close(): Promise<void> {
164
+ this.removeAllListeners();
164
165
  if (this.#dispatcher !== undefined) {
165
166
  // See https://github.com/nodejs/undici/discussions/3522#discussioncomment-10498734
166
167
  await this.#dispatcher.close();
@@ -21,7 +21,7 @@ import type {
21
21
  JsonRpcRequest,
22
22
  JsonRpcResponse,
23
23
  } from "../../../types/providers.js";
24
- import type { GasReportConfig } from "@nomicfoundation/edr";
24
+ import type { ContractDecoder, GasReportConfig } from "@nomicfoundation/edr";
25
25
 
26
26
  import {
27
27
  HardhatError,
@@ -29,6 +29,7 @@ import {
29
29
  } from "@nomicfoundation/hardhat-errors";
30
30
  import { exists, readBinaryFile } from "@nomicfoundation/hardhat-utils/fs";
31
31
  import { deepMerge } from "@nomicfoundation/hardhat-utils/lang";
32
+ import { AsyncMutex } from "@nomicfoundation/hardhat-utils/synchronization";
32
33
 
33
34
  import { resolveUserConfigToHardhatConfig } from "../../core/hre.js";
34
35
  import { isSupportedChainType } from "../../edr/chain-type.js";
@@ -37,6 +38,7 @@ import { JsonRpcServerImplementation } from "../node/json-rpc/server.js";
37
38
  import { EdrProvider } from "./edr/edr-provider.js";
38
39
  import { getHardforks } from "./edr/types/hardfork.js";
39
40
  import { edrGasReportToHardhatGasMeasurements } from "./edr/utils/convert-to-edr.js";
41
+ import { verbosityToIncludeTraces } from "./edr/utils/trace-formatters.js";
40
42
  import { HttpProvider } from "./http-provider.js";
41
43
  import { NetworkConnectionImplementation } from "./network-connection.js";
42
44
 
@@ -55,8 +57,11 @@ export class NetworkManagerImplementation implements NetworkManager {
55
57
  readonly #chainDescriptors: Readonly<ChainDescriptorsConfig>;
56
58
  readonly #userProvidedConfigPath: Readonly<string | undefined>;
57
59
  readonly #projectRoot: string;
60
+ readonly #verbosity: number;
58
61
 
59
62
  #nextConnectionId = 0;
63
+ readonly #contractDecoderMutex = new AsyncMutex();
64
+ #contractDecoder: ContractDecoder | undefined;
60
65
 
61
66
  constructor(
62
67
  defaultNetwork: string,
@@ -68,6 +73,7 @@ export class NetworkManagerImplementation implements NetworkManager {
68
73
  chainDescriptors: ChainDescriptorsConfig,
69
74
  userProvidedConfigPath: string | undefined,
70
75
  projectRoot: string,
76
+ verbosity: number,
71
77
  ) {
72
78
  this.#defaultNetwork = defaultNetwork;
73
79
  this.#defaultChainType = defaultChainType;
@@ -78,6 +84,7 @@ export class NetworkManagerImplementation implements NetworkManager {
78
84
  this.#chainDescriptors = chainDescriptors;
79
85
  this.#userProvidedConfigPath = userProvidedConfigPath;
80
86
  this.#projectRoot = projectRoot;
87
+ this.#verbosity = verbosity;
81
88
  }
82
89
 
83
90
  public async connect<
@@ -233,6 +240,42 @@ export class NetworkManagerImplementation implements NetworkManager {
233
240
  };
234
241
  }
235
242
 
243
+ // We load the build infos and their outputs to create a contract
244
+ // decoder when the first provider is created. Successive providers will
245
+ // reuse the same decoder as a performance optimization.
246
+ //
247
+ // The trade-off here is that if you create an EDR provider, then
248
+ // compile new contracts, and create a new provider, the new contracts
249
+ // won't be loaded.
250
+ //
251
+ // Even without this optimization, we already had the problem of new
252
+ // contracts not being visible to existing providers.
253
+ //
254
+ // In practice, most workflows compile everything before creating
255
+ // any network connection.
256
+ if (this.#contractDecoder === undefined) {
257
+ // We want to ensure that only one contract decoder is created so we
258
+ // protect the initialization with a mutex.
259
+ await this.#contractDecoderMutex.exclusiveRun(async () => {
260
+ // We check again if the decoder is undefined because another async
261
+ // execution context could have already initialized it while we were
262
+ // waiting for the mutex.
263
+ if (this.#contractDecoder === undefined) {
264
+ this.#contractDecoder = await EdrProvider.createContractDecoder({
265
+ buildInfos: await this.#getBuildInfosAndOutputsAsBuffers(),
266
+ ignoreContracts: false,
267
+ });
268
+ }
269
+ });
270
+ }
271
+
272
+ assertHardhatInvariant(
273
+ this.#contractDecoder !== undefined,
274
+ "Contract decoder should have been initialized before creating the provider",
275
+ );
276
+
277
+ const includeCallTraces = verbosityToIncludeTraces(this.#verbosity);
278
+
236
279
  return EdrProvider.create({
237
280
  chainDescriptors: this.#chainDescriptors,
238
281
  // The resolvedNetworkConfig can have its chainType set to `undefined`
@@ -249,12 +292,13 @@ export class NetworkManagerImplementation implements NetworkManager {
249
292
  chainType: resolvedChainType as ChainType,
250
293
  },
251
294
  jsonRpcRequestWrapper,
252
- tracingConfig: {
253
- buildInfos: await this.#getBuildInfosAndOutputsAsBuffers(),
254
- ignoreContracts: false,
255
- },
295
+ contractDecoder: this.#contractDecoder,
256
296
  coverageConfig,
257
297
  gasReportConfig,
298
+ includeCallTraces,
299
+ connectionId: networkConnection.id,
300
+ networkName: networkConnection.networkName,
301
+ verbosity: this.#verbosity,
258
302
  });
259
303
  }
260
304
 
@@ -298,17 +342,32 @@ export class NetworkManagerImplementation implements NetworkManager {
298
342
  */
299
343
  async #resolveNetworkConfig<ChainTypeT extends ChainType | string>(
300
344
  resolvedNetworkName: string,
301
- networkConfigOverride: NetworkConfigOverride | undefined = {},
345
+ networkConfigOverride: NetworkConfigOverride = {},
302
346
  resolvedChainType: ChainTypeT,
303
347
  ): Promise<NetworkConfig> {
304
348
  const existingNetworkConfig = this.#networkConfigs[resolvedNetworkName];
305
- if (
306
- Object.keys(networkConfigOverride).length === 0 &&
307
- resolvedChainType === existingNetworkConfig.chainType
308
- ) {
349
+
350
+ const hasNoOverrides = Object.keys(networkConfigOverride).length === 0;
351
+ const isChainTypeUnchanged =
352
+ resolvedChainType === existingNetworkConfig.chainType;
353
+ const isChainTypeDefault =
354
+ existingNetworkConfig.chainType === undefined &&
355
+ resolvedChainType === this.#defaultChainType;
356
+
357
+ if (hasNoOverrides && isChainTypeUnchanged) {
309
358
  return existingNetworkConfig;
310
359
  }
311
360
 
361
+ if (hasNoOverrides && isChainTypeDefault) {
362
+ return {
363
+ ...existingNetworkConfig,
364
+ /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
365
+ TypeScript can't follow this case, but we are just providing the
366
+ default */
367
+ chainType: resolvedChainType as ChainType,
368
+ };
369
+ }
370
+
312
371
  if (
313
372
  "type" in networkConfigOverride &&
314
373
  networkConfigOverride.type !== existingNetworkConfig.type
@@ -357,6 +416,20 @@ export class NetworkManagerImplementation implements NetworkManager {
357
416
  );
358
417
 
359
418
  if (!configResolutionResult.success) {
419
+ if (configResolutionResult.configValidationErrors !== undefined) {
420
+ throw new HardhatError(
421
+ HardhatError.ERRORS.CORE.NETWORK.INVALID_CONFIG_OVERRIDE,
422
+ {
423
+ errors: `\t${configResolutionResult.configValidationErrors
424
+ .map(
425
+ (error) =>
426
+ `* Error in resolved config ${error.path.join(".")}: ${error.message}`,
427
+ )
428
+ .join("\n\t")}`,
429
+ },
430
+ );
431
+ }
432
+
360
433
  throw new HardhatError(
361
434
  HardhatError.ERRORS.CORE.NETWORK.INVALID_CONFIG_OVERRIDE,
362
435
  {
@@ -5,6 +5,8 @@ import type {
5
5
  } from "../../../../../../types/providers.js";
6
6
  import type { RequestHandler } from "../../types.js";
7
7
  import type { RpcTransactionRequest } from "@nomicfoundation/hardhat-zod-utils/rpc";
8
+ import type * as MicroEthSignerT from "micro-eth-signer";
9
+ import type * as MicroEthSignerTypedDataT from "micro-eth-signer/typed-data";
8
10
 
9
11
  import {
10
12
  assertHardhatInvariant,
@@ -27,27 +29,20 @@ import {
27
29
  rpcTransactionRequest,
28
30
  validateParams,
29
31
  } from "@nomicfoundation/hardhat-zod-utils/rpc";
30
- import { addr, Transaction } from "micro-eth-signer";
31
- import { signTyped } from "micro-eth-signer/typed-data";
32
- import * as typed from "micro-eth-signer/typed-data";
32
+
33
+ // micro-eth-signer is known to be slow to load, so we lazy load it
34
+ let microEthSigner: typeof MicroEthSignerT | undefined;
35
+ let microEthSignerTypedData: typeof MicroEthSignerTypedDataT | undefined;
33
36
 
34
37
  import { getRequestParams } from "../../../json-rpc.js";
35
38
  import { ChainId } from "../chain-id/chain-id.js";
36
39
 
37
- /**
38
- * This handler takes a long time to load. Currently, it is only used in the handlers array,
39
- * where it is imported dynamically, and in the HDWalletHandler, which itself is only loaded
40
- * dynamically.
41
- * If we ever need to import this handler elsewhere, we should either import it dynamically
42
- * or import some of the dependencies of this handler dynamically.
43
- * It has been identified that micro-eth-signer is one of the most expensive dependencies here.
44
- * See https://github.com/NomicFoundation/hardhat/pull/6481 for more details.
45
- */
46
-
47
40
  const EXTRA_ENTROPY = false;
48
41
  export class LocalAccountsHandler extends ChainId implements RequestHandler {
49
- readonly #addressToPrivateKey: Map<string, Uint8Array> = new Map();
50
- readonly #addresses: string[] = [];
42
+ readonly #localAccountsHexPrivateKeys: string[];
43
+
44
+ #addressToPrivateKey: Map<string, Uint8Array> | undefined;
45
+ #addresses: string[] | undefined;
51
46
 
52
47
  constructor(
53
48
  provider: EthereumProvider,
@@ -55,7 +50,29 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
55
50
  ) {
56
51
  super(provider);
57
52
 
58
- this.#initializePrivateKeys(localAccountsHexPrivateKeys);
53
+ this.#localAccountsHexPrivateKeys = localAccountsHexPrivateKeys;
54
+ }
55
+
56
+ async #getAddressesAndPrivateKeysMap(): Promise<{
57
+ addresses: string[];
58
+ addressToPrivateKey: Map<string, Uint8Array>;
59
+ }> {
60
+ if (
61
+ this.#addresses === undefined ||
62
+ this.#addressToPrivateKey === undefined
63
+ ) {
64
+ const { addresses, addressToPrivateKey } =
65
+ await this.#initializeAddressesFromPrivateKeys(
66
+ this.#localAccountsHexPrivateKeys,
67
+ );
68
+ this.#addresses = addresses;
69
+ this.#addressToPrivateKey = addressToPrivateKey;
70
+ }
71
+
72
+ return {
73
+ addresses: this.#addresses,
74
+ addressToPrivateKey: this.#addressToPrivateKey,
75
+ };
59
76
  }
60
77
 
61
78
  public async handle(
@@ -78,9 +95,8 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
78
95
  jsonRpcRequest.method === "eth_accounts" ||
79
96
  jsonRpcRequest.method === "eth_requestAccounts"
80
97
  ) {
81
- return this.#createJsonRpcResponse(jsonRpcRequest.id, [
82
- ...this.#addresses,
83
- ]);
98
+ const { addresses } = await this.#getAddressesAndPrivateKeysMap();
99
+ return this.#createJsonRpcResponse(jsonRpcRequest.id, [...addresses]);
84
100
  }
85
101
 
86
102
  const params = getRequestParams(jsonRpcRequest);
@@ -96,10 +112,20 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
96
112
  );
97
113
  }
98
114
 
99
- const privateKey = this.#getPrivateKeyForAddress(address);
115
+ if (microEthSignerTypedData === undefined) {
116
+ microEthSignerTypedData = await import(
117
+ "micro-eth-signer/typed-data"
118
+ );
119
+ }
120
+
121
+ const privateKey = await this.#getPrivateKeyForAddress(address);
100
122
  return this.#createJsonRpcResponse(
101
123
  jsonRpcRequest.id,
102
- typed.personal.sign(data, privateKey, EXTRA_ENTROPY),
124
+ microEthSignerTypedData.personal.sign(
125
+ data,
126
+ privateKey,
127
+ EXTRA_ENTROPY,
128
+ ),
103
129
  );
104
130
  }
105
131
  }
@@ -116,10 +142,20 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
116
142
  );
117
143
  }
118
144
 
119
- const privateKey = this.#getPrivateKeyForAddress(address);
145
+ if (microEthSignerTypedData === undefined) {
146
+ microEthSignerTypedData = await import(
147
+ "micro-eth-signer/typed-data"
148
+ );
149
+ }
150
+
151
+ const privateKey = await this.#getPrivateKeyForAddress(address);
120
152
  return this.#createJsonRpcResponse(
121
153
  jsonRpcRequest.id,
122
- typed.personal.sign(data, privateKey, EXTRA_ENTROPY),
154
+ microEthSignerTypedData.personal.sign(
155
+ data,
156
+ privateKey,
157
+ EXTRA_ENTROPY,
158
+ ),
123
159
  );
124
160
  }
125
161
  }
@@ -146,11 +182,19 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
146
182
  }
147
183
 
148
184
  // if we don't manage the address, the method is forwarded
149
- const privateKey = this.#getPrivateKeyForAddressOrNull(address);
185
+ const privateKey = await this.#getPrivateKeyForAddressOrNull(address);
150
186
  if (privateKey !== null) {
187
+ if (microEthSignerTypedData === undefined) {
188
+ microEthSignerTypedData = await import("micro-eth-signer/typed-data");
189
+ }
190
+
151
191
  return this.#createJsonRpcResponse(
152
192
  jsonRpcRequest.id,
153
- signTyped(typedMessage, privateKey, EXTRA_ENTROPY),
193
+ microEthSignerTypedData.signTyped(
194
+ typedMessage,
195
+ privateKey,
196
+ EXTRA_ENTROPY,
197
+ ),
154
198
  );
155
199
  }
156
200
  }
@@ -220,7 +264,7 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
220
264
  txRequest.nonce = await this.#getNonce(txRequest.from);
221
265
  }
222
266
 
223
- const privateKey = this.#getPrivateKeyForAddress(txRequest.from);
267
+ const privateKey = await this.#getPrivateKeyForAddress(txRequest.from);
224
268
 
225
269
  const chainId = await this.getChainId();
226
270
 
@@ -235,20 +279,32 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
235
279
  }
236
280
  }
237
281
 
238
- #initializePrivateKeys(localAccountsHexPrivateKeys: string[]) {
282
+ async #initializeAddressesFromPrivateKeys(
283
+ localAccountsHexPrivateKeys: string[],
284
+ ) {
285
+ if (microEthSigner === undefined) {
286
+ microEthSigner = await import("micro-eth-signer");
287
+ }
288
+
239
289
  const privateKeys: Uint8Array[] = localAccountsHexPrivateKeys.map((h) =>
240
290
  hexStringToBytes(h),
241
291
  );
242
292
 
293
+ const addresses = [];
294
+ const addressToPrivateKey = new Map<string, Uint8Array>();
243
295
  for (const pk of privateKeys) {
244
- const address = addr.fromPrivateKey(pk).toLowerCase();
245
- this.#addressToPrivateKey.set(address, pk);
246
- this.#addresses.push(address);
296
+ const address = microEthSigner.addr.fromPrivateKey(pk).toLowerCase();
297
+ addressToPrivateKey.set(address, pk);
298
+ addresses.push(address);
247
299
  }
300
+
301
+ return { addresses, addressToPrivateKey };
248
302
  }
249
303
 
250
- #getPrivateKeyForAddress(address: Uint8Array): Uint8Array {
251
- const pk = this.#addressToPrivateKey.get(bytesToHexString(address));
304
+ async #getPrivateKeyForAddress(address: Uint8Array): Promise<Uint8Array> {
305
+ const { addressToPrivateKey } = await this.#getAddressesAndPrivateKeysMap();
306
+
307
+ const pk = addressToPrivateKey.get(bytesToHexString(address));
252
308
 
253
309
  if (pk === undefined) {
254
310
  throw new HardhatError(
@@ -262,9 +318,11 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
262
318
  return pk;
263
319
  }
264
320
 
265
- #getPrivateKeyForAddressOrNull(address: Uint8Array): Uint8Array | null {
321
+ async #getPrivateKeyForAddressOrNull(
322
+ address: Uint8Array,
323
+ ): Promise<Uint8Array | null> {
266
324
  try {
267
- return this.#getPrivateKeyForAddress(address);
325
+ return await this.#getPrivateKeyForAddress(address);
268
326
  } catch {
269
327
  return null;
270
328
  }
@@ -289,6 +347,12 @@ export class LocalAccountsHandler extends ChainId implements RequestHandler {
289
347
  chainId: number,
290
348
  privateKey: Uint8Array,
291
349
  ): Promise<Uint8Array> {
350
+ if (microEthSigner === undefined) {
351
+ microEthSigner = await import("micro-eth-signer");
352
+ }
353
+
354
+ const { addr, Transaction } = microEthSigner;
355
+
292
356
  const txData = {
293
357
  ...transactionRequest,
294
358
  gasLimit: transactionRequest.gas,