hardhat 2.9.2 → 2.9.4

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 (128) hide show
  1. package/builtin-tasks/compile.js +18 -10
  2. package/builtin-tasks/compile.js.map +1 -1
  3. package/builtin-tasks/node.js +4 -3
  4. package/builtin-tasks/node.js.map +1 -1
  5. package/internal/artifacts.d.ts.map +1 -1
  6. package/internal/artifacts.js +2 -1
  7. package/internal/artifacts.js.map +1 -1
  8. package/internal/cli/HelpPrinter.js +6 -6
  9. package/internal/cli/HelpPrinter.js.map +1 -1
  10. package/internal/cli/analytics.d.ts.map +1 -1
  11. package/internal/cli/analytics.js +2 -2
  12. package/internal/cli/analytics.js.map +1 -1
  13. package/internal/cli/cli.js +8 -8
  14. package/internal/cli/cli.js.map +1 -1
  15. package/internal/cli/project-creation.js +1 -1
  16. package/internal/core/config/config-loading.d.ts +5 -2
  17. package/internal/core/config/config-loading.d.ts.map +1 -1
  18. package/internal/core/config/config-loading.js +1 -1
  19. package/internal/core/config/config-loading.js.map +1 -1
  20. package/internal/core/errors-list.d.ts +7 -0
  21. package/internal/core/errors-list.d.ts.map +1 -1
  22. package/internal/core/errors-list.js +10 -3
  23. package/internal/core/errors-list.js.map +1 -1
  24. package/internal/core/providers/http.d.ts +1 -1
  25. package/internal/core/providers/http.d.ts.map +1 -1
  26. package/internal/core/providers/http.js +3 -3
  27. package/internal/core/providers/http.js.map +1 -1
  28. package/internal/core/runtime-environment.d.ts +3 -2
  29. package/internal/core/runtime-environment.d.ts.map +1 -1
  30. package/internal/core/runtime-environment.js +2 -1
  31. package/internal/core/runtime-environment.js.map +1 -1
  32. package/internal/hardhat-network/jsonrpc/handler.js +12 -3
  33. package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
  34. package/internal/hardhat-network/jsonrpc/server.d.ts.map +1 -1
  35. package/internal/hardhat-network/jsonrpc/server.js +2 -2
  36. package/internal/hardhat-network/jsonrpc/server.js.map +1 -1
  37. package/internal/hardhat-network/provider/BlockchainBase.d.ts +1 -1
  38. package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -1
  39. package/internal/hardhat-network/provider/BlockchainBase.js +2 -2
  40. package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -1
  41. package/internal/hardhat-network/provider/BlockchainData.d.ts +2 -1
  42. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  43. package/internal/hardhat-network/provider/BlockchainData.js +4 -2
  44. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  45. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +1 -1
  46. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  47. package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -2
  48. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  49. package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
  50. package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
  51. package/internal/hardhat-network/provider/TxPool.js +3 -3
  52. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  53. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +1 -1
  54. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  55. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +3 -3
  56. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  57. package/internal/hardhat-network/provider/modules/eth.d.ts +3 -0
  58. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  59. package/internal/hardhat-network/provider/modules/eth.js +20 -17
  60. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  61. package/internal/hardhat-network/provider/modules/evm.js +2 -2
  62. package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
  63. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  64. package/internal/hardhat-network/provider/modules/logger.js +10 -4
  65. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  66. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  67. package/internal/hardhat-network/provider/node.js +8 -8
  68. package/internal/hardhat-network/provider/node.js.map +1 -1
  69. package/internal/hardhat-network/provider/output.js +1 -1
  70. package/internal/hardhat-network/provider/output.js.map +1 -1
  71. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +1 -1
  72. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  73. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  74. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +1 -10
  75. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  76. package/internal/lib/hardhat-lib.d.ts.map +1 -1
  77. package/internal/lib/hardhat-lib.js +2 -2
  78. package/internal/lib/hardhat-lib.js.map +1 -1
  79. package/internal/solidity/compilation-job.d.ts.map +1 -1
  80. package/internal/solidity/compilation-job.js.map +1 -1
  81. package/internal/util/download.js +1 -1
  82. package/internal/util/download.js.map +1 -1
  83. package/internal/util/lazy.d.ts.map +1 -1
  84. package/internal/util/lazy.js +6 -4
  85. package/internal/util/lazy.js.map +1 -1
  86. package/internal/util/wei-values.js +1 -1
  87. package/internal/util/wei-values.js.map +1 -1
  88. package/package.json +14 -8
  89. package/register.js +2 -2
  90. package/register.js.map +1 -1
  91. package/src/builtin-tasks/compile.ts +30 -14
  92. package/src/builtin-tasks/node.ts +5 -2
  93. package/src/common/bigInt.ts +106 -0
  94. package/src/common/index.ts +2 -0
  95. package/src/internal/artifacts.ts +3 -2
  96. package/src/internal/cli/HelpPrinter.ts +6 -6
  97. package/src/internal/cli/analytics.ts +4 -1
  98. package/src/internal/cli/cli.ts +17 -13
  99. package/src/internal/cli/project-creation.ts +1 -1
  100. package/src/internal/core/config/config-loading.ts +7 -3
  101. package/src/internal/core/errors-list.ts +11 -3
  102. package/src/internal/core/providers/http.ts +6 -2
  103. package/src/internal/core/runtime-environment.ts +3 -1
  104. package/src/internal/hardhat-network/jsonrpc/handler.ts +15 -3
  105. package/src/internal/hardhat-network/jsonrpc/server.ts +2 -1
  106. package/src/internal/hardhat-network/provider/BlockchainBase.ts +4 -2
  107. package/src/internal/hardhat-network/provider/BlockchainData.ts +6 -2
  108. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +4 -2
  109. package/src/internal/hardhat-network/provider/TransactionQueue.ts +3 -1
  110. package/src/internal/hardhat-network/provider/TxPool.ts +3 -3
  111. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +7 -3
  112. package/src/internal/hardhat-network/provider/modules/eth.ts +22 -17
  113. package/src/internal/hardhat-network/provider/modules/evm.ts +2 -2
  114. package/src/internal/hardhat-network/provider/modules/logger.ts +10 -4
  115. package/src/internal/hardhat-network/provider/node.ts +9 -8
  116. package/src/internal/hardhat-network/provider/output.ts +1 -1
  117. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +2 -1
  118. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +1 -11
  119. package/src/internal/lib/hardhat-lib.ts +4 -3
  120. package/src/internal/solidity/compilation-job.ts +3 -1
  121. package/src/internal/util/download.ts +1 -1
  122. package/src/internal/util/lazy.ts +21 -5
  123. package/src/internal/util/wei-values.ts +1 -1
  124. package/src/register.ts +4 -3
  125. package/src/types/runtime.ts +2 -1
  126. package/types/runtime.d.ts +2 -1
  127. package/types/runtime.d.ts.map +1 -1
  128. package/src/tsconfig.json +0 -10
@@ -0,0 +1,106 @@
1
+ import type { BigNumber as EthersBigNumberType } from "ethers";
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import type { BigNumber as BigNumberJsType } from "bignumber.js";
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
5
+ import type { default as BNType } from "bn.js";
6
+
7
+ import { HardhatError } from "../internal/core/errors";
8
+ import { ERRORS } from "../internal/core/errors-list";
9
+
10
+ export function normalizeToBigInt(
11
+ source:
12
+ | number
13
+ | bigint
14
+ | BNType
15
+ | EthersBigNumberType
16
+ | BigNumberJsType
17
+ | string
18
+ ): bigint {
19
+ switch (typeof source) {
20
+ case "object":
21
+ if (isBigNumber(source)) {
22
+ return BigInt(source.toString());
23
+ } else {
24
+ throw new HardhatError(ERRORS.GENERAL.INVALID_BIG_NUMBER, {
25
+ message: `Value ${JSON.stringify(
26
+ source
27
+ )} is of type "object" but is not an instanceof one of the known big number object types.`,
28
+ });
29
+ }
30
+ case "number":
31
+ if (!Number.isInteger(source)) {
32
+ throw new HardhatError(ERRORS.GENERAL.INVALID_BIG_NUMBER, {
33
+ message: `${source} is not an integer`,
34
+ });
35
+ }
36
+ if (!Number.isSafeInteger(source)) {
37
+ throw new HardhatError(ERRORS.GENERAL.INVALID_BIG_NUMBER, {
38
+ message: `Integer ${source} is unsafe. Consider using ${source}n instead. For more details, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger`,
39
+ });
40
+ }
41
+ // `break;` intentionally omitted. fallthrough desired.
42
+ case "string":
43
+ case "bigint":
44
+ return BigInt(source);
45
+ default:
46
+ const _exhaustiveCheck: never = source;
47
+ throw new HardhatError(ERRORS.GENERAL.INVALID_BIG_NUMBER, {
48
+ message: `Unsupported type ${typeof source}`,
49
+ });
50
+ }
51
+ }
52
+
53
+ export function isBigNumber(source: any): boolean {
54
+ return (
55
+ typeof source === "bigint" ||
56
+ isEthersBigNumber(source) ||
57
+ isBN(source) ||
58
+ isBigNumberJsBigNumber(source)
59
+ );
60
+ }
61
+
62
+ function isBN(n: any) {
63
+ try {
64
+ // eslint-disable-next-line import/no-extraneous-dependencies
65
+ const BN: typeof BNType = require("bn.js");
66
+ return BN.isBN(n);
67
+ } catch (e) {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ function isEthersBigNumber(n: any) {
73
+ try {
74
+ const BigNumber: typeof EthersBigNumberType =
75
+ // eslint-disable-next-line import/no-extraneous-dependencies
76
+ require("ethers").ethers.BigNumber;
77
+ return BigNumber.isBigNumber(n);
78
+ } catch (e) {
79
+ return false;
80
+ }
81
+ }
82
+
83
+ function isBigNumberJsBigNumber(n: any) {
84
+ try {
85
+ // eslint-disable-next-line import/no-extraneous-dependencies
86
+ const BigNumber: typeof BigNumberJsType = require("bignumber.js").BigNumber;
87
+ return BigNumber.isBigNumber(n);
88
+ } catch (e) {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ export function formatNumberType(
94
+ n: string | bigint | BNType | EthersBigNumberType | BigNumberJsType
95
+ ): string {
96
+ if (typeof n === "object") {
97
+ if (isBN(n)) {
98
+ return "BN";
99
+ } else if (isEthersBigNumber(n)) {
100
+ return "ethers.BigNumber";
101
+ } else if (isBigNumberJsBigNumber(n)) {
102
+ return "bignumber.js";
103
+ }
104
+ }
105
+ return typeof n;
106
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./bigInt";
2
+ export { CustomError } from "../internal/core/errors";
@@ -428,7 +428,7 @@ export class Artifacts implements IArtifacts {
428
428
  return paths.map((p) => this._getFullyQualifiedNameFromPath(p)).sort();
429
429
  }
430
430
 
431
- private _formatSuggestions(names: string[], contractName?: string): string {
431
+ private _formatSuggestions(names: string[], contractName: string): string {
432
432
  switch (names.length) {
433
433
  case 0:
434
434
  return "";
@@ -456,7 +456,7 @@ Please replace "${contractName}" for the correct contract name wherever you are
456
456
 
457
457
  throw new HardhatError(ERRORS.ARTIFACTS.NOT_FOUND, {
458
458
  contractName: fullyQualifiedName,
459
- suggestion: this._formatSuggestions(similarNames),
459
+ suggestion: this._formatSuggestions(similarNames, fullyQualifiedName),
460
460
  });
461
461
  }
462
462
 
@@ -501,6 +501,7 @@ Please replace "${contractName}" for the correct contract name wherever you are
501
501
  ): string[] {
502
502
  const outputNames = [];
503
503
  const groups = similarNames.reduce((obj, cur) => {
504
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
504
505
  obj[cur] = obj[cur] ? obj[cur] + 1 : 1;
505
506
  return obj;
506
507
  }, {} as { [k: string]: number });
@@ -112,11 +112,11 @@ export class HelpPrinter {
112
112
 
113
113
  for (const name of Object.keys(paramDefinitions).sort()) {
114
114
  const definition = paramDefinitions[name];
115
- const { defaultValue, isFlag } = definition;
115
+ const { isFlag, isOptional } = definition;
116
116
 
117
117
  paramsList += " ";
118
118
 
119
- if (defaultValue !== undefined) {
119
+ if (isOptional) {
120
120
  paramsList += "[";
121
121
  }
122
122
 
@@ -126,7 +126,7 @@ export class HelpPrinter {
126
126
  paramsList += ` ${this._getParamValueDescription(definition)}`;
127
127
  }
128
128
 
129
- if (defaultValue !== undefined) {
129
+ if (isOptional) {
130
130
  paramsList += "]";
131
131
  }
132
132
  }
@@ -140,11 +140,11 @@ export class HelpPrinter {
140
140
  let paramsList = "";
141
141
 
142
142
  for (const definition of positionalParamDefinitions) {
143
- const { defaultValue, isVariadic, name } = definition;
143
+ const { isOptional, isVariadic, name } = definition;
144
144
 
145
145
  paramsList += " ";
146
146
 
147
- if (defaultValue !== undefined) {
147
+ if (isOptional) {
148
148
  paramsList += "[";
149
149
  }
150
150
 
@@ -154,7 +154,7 @@ export class HelpPrinter {
154
154
 
155
155
  paramsList += name;
156
156
 
157
- if (defaultValue !== undefined) {
157
+ if (isOptional) {
158
158
  paramsList += "]";
159
159
  }
160
160
  }
@@ -1,8 +1,9 @@
1
+ import type { request as RequestT } from "undici";
2
+
1
3
  import AbortController from "abort-controller";
2
4
  import debug from "debug";
3
5
  import os from "os";
4
6
  import qs from "qs";
5
- import { request } from "undici";
6
7
  import { v4 as uuid } from "uuid";
7
8
 
8
9
  import * as builtinTaskNames from "../../builtin-tasks/task-names";
@@ -157,6 +158,8 @@ export class Analytics {
157
158
  }
158
159
 
159
160
  private _sendHit(hit: RawAnalytics): [AbortAnalytics, Promise<void>] {
161
+ const { request } = require("undici") as { request: typeof RequestT };
162
+
160
163
  log(`Sending hit for ${hit.dp}`);
161
164
 
162
165
  const controller = new AbortController();
@@ -94,6 +94,12 @@ async function main() {
94
94
 
95
95
  showStackTraces = hardhatArguments.showStackTraces;
96
96
 
97
+ // --version is a special case
98
+ if (hardhatArguments.version) {
99
+ await printVersionMessage(packageJson);
100
+ return;
101
+ }
102
+
97
103
  if (hardhatArguments.config === undefined && !isCwdInsideProject()) {
98
104
  if (
99
105
  process.stdout.isTTY === true ||
@@ -118,12 +124,6 @@ async function main() {
118
124
  }
119
125
  }
120
126
 
121
- // --version is a special case
122
- if (hardhatArguments.version) {
123
- await printVersionMessage(packageJson);
124
- return;
125
- }
126
-
127
127
  if (!isHardhatInstalledLocallyOrLinked()) {
128
128
  throw new HardhatError(ERRORS.GENERAL.NON_LOCAL_INSTALLATION);
129
129
  }
@@ -139,10 +139,13 @@ async function main() {
139
139
 
140
140
  const ctx = HardhatContext.createHardhatContext();
141
141
 
142
- const config = loadConfigAndTasks(hardhatArguments, {
143
- showEmptyConfigWarning,
144
- showSolidityConfigWarnings,
145
- });
142
+ const { resolvedConfig, userConfig } = loadConfigAndTasks(
143
+ hardhatArguments,
144
+ {
145
+ showEmptyConfigWarning,
146
+ showSolidityConfigWarnings,
147
+ }
148
+ );
146
149
 
147
150
  let telemetryConsent: boolean | undefined = hasConsentedTelemetry();
148
151
 
@@ -162,7 +165,7 @@ async function main() {
162
165
 
163
166
  const analytics = await Analytics.getInstance(telemetryConsent);
164
167
 
165
- Reporter.setConfigPath(config.paths.configFile);
168
+ Reporter.setConfigPath(resolvedConfig.paths.configFile);
166
169
  if (telemetryConsent === true) {
167
170
  Reporter.setEnabled(true);
168
171
  }
@@ -200,11 +203,12 @@ async function main() {
200
203
  }
201
204
 
202
205
  const env = new Environment(
203
- config,
206
+ resolvedConfig,
204
207
  hardhatArguments,
205
208
  taskDefinitions,
206
209
  envExtenders,
207
- ctx.experimentalHardhatNetworkMessageTraceHooks
210
+ ctx.experimentalHardhatNetworkMessageTraceHooks,
211
+ userConfig
208
212
  );
209
213
 
210
214
  ctx.setHardhatRuntimeEnvironment(env);
@@ -47,7 +47,7 @@ const BASIC_SAMPLE_PROJECT_DEPENDENCIES: Dependencies = {
47
47
  const ADVANCED_SAMPLE_PROJECT_DEPENDENCIES: Dependencies = {
48
48
  ...BASIC_SAMPLE_PROJECT_DEPENDENCIES,
49
49
  "@nomiclabs/hardhat-etherscan": "^3.0.0",
50
- dotenv: "^10.0.0",
50
+ dotenv: "^16.0.0",
51
51
  eslint: "^7.29.0",
52
52
  "eslint-config-prettier": "^8.3.0",
53
53
  "eslint-config-standard": "^16.0.3",
@@ -6,7 +6,11 @@ import fsExtra from "fs-extra";
6
6
  import path from "path";
7
7
  import semver from "semver";
8
8
 
9
- import { HardhatArguments, HardhatConfig } from "../../../types";
9
+ import {
10
+ HardhatArguments,
11
+ HardhatConfig,
12
+ HardhatUserConfig,
13
+ } from "../../../types";
10
14
  import { HardhatContext } from "../../context";
11
15
  import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "../../hardhat-network/stack-traces/solidityTracer";
12
16
  import { findClosestPackageJson } from "../../util/packageInfo";
@@ -49,7 +53,7 @@ export function loadConfigAndTasks(
49
53
  showEmptyConfigWarning: false,
50
54
  showSolidityConfigWarnings: false,
51
55
  }
52
- ): HardhatConfig {
56
+ ): { resolvedConfig: HardhatConfig; userConfig: HardhatUserConfig } {
53
57
  let configPath =
54
58
  hardhatArguments !== undefined ? hardhatArguments.config : undefined;
55
59
 
@@ -109,7 +113,7 @@ export function loadConfigAndTasks(
109
113
  checkUnsupportedRemappings(resolved);
110
114
  }
111
115
 
112
- return resolved;
116
+ return { resolvedConfig: resolved, userConfig: frozenUserConfig };
113
117
  }
114
118
 
115
119
  function deepFreezeUserConfig(
@@ -68,7 +68,7 @@ Please upgrade your version of Node.js and try again.`,
68
68
  number: 3,
69
69
  message: "%operation% is not supported in Hardhat.",
70
70
  title: "Unsupported operation",
71
- description: `You are tying to perform an unsupported operation.
71
+ description: `You are trying to perform an unsupported operation.
72
72
 
73
73
  Unless you are creating a task or plugin, this is probably a bug.
74
74
 
@@ -229,6 +229,14 @@ Either try using a new directory, or remove the files listed above.`,
229
229
  Either try using a new directory name, or remove the conflicting files.`,
230
230
  shouldBeReported: false,
231
231
  },
232
+ INVALID_BIG_NUMBER: {
233
+ number: 17,
234
+ message: "The input value cannot be normalized to a BigInt: %message%",
235
+ title: "Invalid big number",
236
+ description:
237
+ "Hardhat attempted to convert the input value to a BigInt, but no known conversion method was applicable to the given value.",
238
+ shouldBeReported: false,
239
+ },
232
240
  },
233
241
  NETWORK: {
234
242
  CONFIG_NOT_FOUND: {
@@ -655,7 +663,7 @@ Please double check how you invoked Hardhat or ran your task.`,
655
663
  number: 312,
656
664
  title: "Subtask run from the command line",
657
665
  message: "Trying to run the %name% subtask from the CLI",
658
- description: `You tried to run an subtask from the command line.
666
+ description: `You tried to run a subtask from the command line.
659
667
 
660
668
  This is not supported. Please run the help task to see the available options.`,
661
669
  shouldBeReported: false,
@@ -722,7 +730,7 @@ You must always use slashes (/) in Solidity imports.`,
722
730
  title: "Invalid import: trying to use an unsupported protocol",
723
731
  description: `A Solidity file is trying to import a file using an unsupported protocol, like http.
724
732
 
725
- You can only import files thar are available locally or installed through npm.`,
733
+ You can only import files that are available locally or installed through npm.`,
726
734
  shouldBeReported: false,
727
735
  },
728
736
  INVALID_IMPORT_ABSOLUTE_PATH: {
@@ -1,5 +1,6 @@
1
+ import type { Dispatcher, Pool as PoolT } from "undici";
2
+
1
3
  import { EventEmitter } from "events";
2
- import { Dispatcher, Pool } from "undici";
3
4
 
4
5
  import { EIP1193Provider, RequestArguments } from "../../../types";
5
6
  import {
@@ -44,6 +45,9 @@ export class HttpProvider extends EventEmitter implements EIP1193Provider {
44
45
  client: Dispatcher | undefined = undefined
45
46
  ) {
46
47
  super();
48
+
49
+ const { Pool } = require("undici") as { Pool: typeof PoolT };
50
+
47
51
  const url = new URL(this._url);
48
52
  this._path = url.pathname;
49
53
  this._authHeader =
@@ -171,7 +175,7 @@ export class HttpProvider extends EventEmitter implements EIP1193Provider {
171
175
  : this._timeout,
172
176
  headers: {
173
177
  "Content-Type": "application/json",
174
- "User-Agent": `hardhat ${hardhatVersion}`,
178
+ "User-Agent": `hardhat ${hardhatVersion ?? "(unknown version)"}`,
175
179
  Authorization: this._authHeader,
176
180
  ...this._extraHeaders,
177
181
  },
@@ -7,6 +7,7 @@ import {
7
7
  HardhatArguments,
8
8
  HardhatConfig,
9
9
  HardhatRuntimeEnvironment,
10
+ HardhatUserConfig,
10
11
  Network,
11
12
  ParamDefinition,
12
13
  RunSuperFunction,
@@ -56,7 +57,8 @@ export class Environment implements HardhatRuntimeEnvironment {
56
57
  public readonly hardhatArguments: HardhatArguments,
57
58
  public readonly tasks: TasksMap,
58
59
  extenders: EnvironmentExtender[] = [],
59
- experimentalHardhatNetworkMessageTraceHooks: ExperimentalHardhatNetworkMessageTraceHook[] = []
60
+ experimentalHardhatNetworkMessageTraceHooks: ExperimentalHardhatNetworkMessageTraceHook[] = [],
61
+ public readonly userConfig: HardhatUserConfig = {}
60
62
  ) {
61
63
  log("Creating HardhatRuntimeEnvironment");
62
64
 
@@ -235,10 +235,16 @@ const _readWsRequest = (msg: string): JsonRpcRequest => {
235
235
  };
236
236
 
237
237
  const _handleError = (error: any): JsonRpcResponse => {
238
+ // extract the relevant fields from the error before wrapping it
238
239
  let txHash: string | undefined;
240
+ let returnData: string | undefined;
241
+
239
242
  if (error.transactionHash !== undefined) {
240
243
  txHash = error.transactionHash;
241
244
  }
245
+ if (error.data !== undefined) {
246
+ returnData = error.data;
247
+ }
242
248
 
243
249
  // In case of non-hardhat error, treat it as internal and associate the appropriate error code.
244
250
  if (!ProviderError.isProviderError(error)) {
@@ -254,10 +260,16 @@ const _handleError = (error: any): JsonRpcResponse => {
254
260
  },
255
261
  };
256
262
 
263
+ response.error.data = {
264
+ message: error.message,
265
+ };
266
+
257
267
  if (txHash !== undefined) {
258
- response.error.data = {
259
- txHash,
260
- };
268
+ response.error.data.txHash = txHash;
269
+ }
270
+
271
+ if (returnData !== undefined) {
272
+ response.error.data.data = returnData;
261
273
  }
262
274
 
263
275
  return response;
@@ -1,9 +1,9 @@
1
+ import type { Client as ClientT } from "undici";
1
2
  import type WsT from "ws";
2
3
 
3
4
  import debug from "debug";
4
5
  import http, { Server } from "http";
5
6
  import { AddressInfo } from "net";
6
- import { Client } from "undici";
7
7
 
8
8
  import {
9
9
  EIP1193Provider,
@@ -44,6 +44,7 @@ export class JsonRpcServer implements IJsonRpcServer {
44
44
  }
45
45
 
46
46
  public getProvider = (name = "json-rpc"): EIP1193Provider => {
47
+ const { Client } = require("undici") as { Client: typeof ClientT };
47
48
  const { address, port } = this._httpServer.address() as AddressInfo;
48
49
 
49
50
  const dispatcher = new Client(`http://${address}:${port}/`, {
@@ -86,14 +86,16 @@ export abstract class BlockchainBase {
86
86
  count: BN,
87
87
  interval: BN,
88
88
  previousBlockStateRoot: Buffer,
89
- previousBlockTotalDifficulty: BN
89
+ previousBlockTotalDifficulty: BN,
90
+ previousBlockBaseFeePerGas: BN | undefined
90
91
  ) {
91
92
  this._data.reserveBlocks(
92
93
  this.getLatestBlockNumber().addn(1),
93
94
  count,
94
95
  interval,
95
96
  previousBlockStateRoot,
96
- previousBlockTotalDifficulty
97
+ previousBlockTotalDifficulty,
98
+ previousBlockBaseFeePerGas
97
99
  );
98
100
  }
99
101
 
@@ -15,6 +15,7 @@ interface Reservation {
15
15
  interval: BN;
16
16
  previousBlockStateRoot: Buffer;
17
17
  previousBlockTotalDifficulty: BN;
18
+ previousBlockBaseFeePerGas: BN | undefined;
18
19
  }
19
20
 
20
21
  export class BlockchainData {
@@ -33,7 +34,8 @@ export class BlockchainData {
33
34
  count: BN,
34
35
  interval: BN,
35
36
  previousBlockStateRoot: Buffer,
36
- previousBlockTotalDifficulty: BN
37
+ previousBlockTotalDifficulty: BN,
38
+ previousBlockBaseFeePerGas: BN | undefined
37
39
  ) {
38
40
  const reservation: Reservation = {
39
41
  first,
@@ -41,6 +43,7 @@ export class BlockchainData {
41
43
  interval,
42
44
  previousBlockStateRoot,
43
45
  previousBlockTotalDifficulty,
46
+ previousBlockBaseFeePerGas,
44
47
  };
45
48
  this._blockReservations.push(reservation);
46
49
  }
@@ -188,7 +191,7 @@ export class BlockchainData {
188
191
  const reservationIndex = this._findBlockReservation(blockNumber);
189
192
  assertHardhatInvariant(
190
193
  reservationIndex !== -1,
191
- `No reservation to fill for block number ${blockNumber}`
194
+ `No reservation to fill for block number ${blockNumber.toString()}`
192
195
  );
193
196
 
194
197
  // capture the timestamp before removing the reservation:
@@ -217,6 +220,7 @@ export class BlockchainData {
217
220
  header: {
218
221
  number: blockNumber,
219
222
  stateRoot: oldReservation.previousBlockStateRoot,
223
+ baseFeePerGas: oldReservation.previousBlockBaseFeePerGas,
220
224
  timestamp,
221
225
  },
222
226
  },
@@ -36,13 +36,15 @@ export class HardhatBlockchain
36
36
  count: BN,
37
37
  interval: BN,
38
38
  previousBlockStateRoot: Buffer,
39
- previousBlockTotalDifficulty: BN
39
+ previousBlockTotalDifficulty: BN,
40
+ previousBlockBaseFeePerGas: BN | undefined
40
41
  ) {
41
42
  super.reserveBlocks(
42
43
  count,
43
44
  interval,
44
45
  previousBlockStateRoot,
45
- previousBlockTotalDifficulty
46
+ previousBlockTotalDifficulty,
47
+ previousBlockBaseFeePerGas
46
48
  );
47
49
  this._length = this._length + count.toNumber();
48
50
  }
@@ -62,7 +62,9 @@ function getOrderedTransactionHeap(
62
62
  );
63
63
  default:
64
64
  // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
65
- throw new InvalidInputError(`Invalid mempool order: ${mempoolOrder}`);
65
+ throw new InvalidInputError(
66
+ `Invalid mempool order: ${mempoolOrder as any}`
67
+ );
66
68
  }
67
69
  }
68
70
 
@@ -445,7 +445,7 @@ export class TxPool {
445
445
 
446
446
  if (txMaxUpfrontCost.gt(senderBalance)) {
447
447
  throw new InvalidInputError(
448
- `sender doesn't have enough funds to send tx. The max upfront cost is: ${txMaxUpfrontCost}` +
448
+ `sender doesn't have enough funds to send tx. The max upfront cost is: ${txMaxUpfrontCost.toString()}` +
449
449
  ` and the sender's account only has: ${senderBalance.toString()}`
450
450
  );
451
451
  }
@@ -461,7 +461,7 @@ export class TxPool {
461
461
 
462
462
  if (gasLimit.lt(baseFee)) {
463
463
  throw new InvalidInputError(
464
- `Transaction requires at least ${baseFee} gas but got ${gasLimit}`
464
+ `Transaction requires at least ${baseFee.toString()} gas but got ${gasLimit.toString()}`
465
465
  );
466
466
  }
467
467
 
@@ -469,7 +469,7 @@ export class TxPool {
469
469
 
470
470
  if (gasLimit.gt(blockGasLimit)) {
471
471
  throw new InvalidInputError(
472
- `Transaction gas limit is ${gasLimit} and exceeds block gas limit of ${blockGasLimit}`
472
+ `Transaction gas limit is ${gasLimit.toString()} and exceeds block gas limit of ${blockGasLimit.toString()}`
473
473
  );
474
474
  }
475
475
  }
@@ -97,13 +97,15 @@ export class ForkBlockchain
97
97
  count: BN,
98
98
  interval: BN,
99
99
  previousBlockStateRoot: Buffer,
100
- previousBlockTotalDifficulty: BN
100
+ previousBlockTotalDifficulty: BN,
101
+ previousBlockBaseFeePerGas: BN | undefined
101
102
  ) {
102
103
  super.reserveBlocks(
103
104
  count,
104
105
  interval,
105
106
  previousBlockStateRoot,
106
- previousBlockTotalDifficulty
107
+ previousBlockTotalDifficulty,
108
+ previousBlockBaseFeePerGas
107
109
  );
108
110
  this._latestBlockNumber = this._latestBlockNumber.add(count);
109
111
  }
@@ -293,7 +295,9 @@ export class ForkBlockchain
293
295
  rpcToTxData(transaction) as FeeMarketEIP1559TxData
294
296
  );
295
297
  } else {
296
- throw new InternalError(`Unknown transaction type ${transaction.type}`);
298
+ throw new InternalError(
299
+ `Unknown transaction type ${transaction.type.toString()}`
300
+ );
297
301
  }
298
302
 
299
303
  block.transactions.push(tx);