hardhat 2.9.8 → 2.10.1
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.
- package/internal/cli/cli.js +37 -7
- package/internal/cli/cli.js.map +1 -1
- package/internal/cli/hardhat-vscode-installation.d.ts +8 -0
- package/internal/cli/hardhat-vscode-installation.d.ts.map +1 -0
- package/internal/cli/hardhat-vscode-installation.js +41 -0
- package/internal/cli/hardhat-vscode-installation.js.map +1 -0
- package/internal/cli/project-creation.d.ts +0 -1
- package/internal/cli/project-creation.d.ts.map +1 -1
- package/internal/cli/project-creation.js +87 -179
- package/internal/cli/project-creation.js.map +1 -1
- package/internal/cli/prompt.d.ts +14 -0
- package/internal/cli/prompt.d.ts.map +1 -0
- package/internal/cli/prompt.js +120 -0
- package/internal/cli/prompt.js.map +1 -0
- package/internal/cli/types.d.ts +4 -0
- package/internal/cli/types.d.ts.map +1 -0
- package/internal/cli/types.js +3 -0
- package/internal/cli/types.js.map +1 -0
- package/internal/core/config/config-loading.js +1 -1
- package/internal/core/errors-list.js +4 -4
- package/internal/core/errors-list.js.map +1 -1
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +0 -4
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/gas-providers.d.ts +0 -15
- package/internal/core/providers/gas-providers.d.ts.map +1 -1
- package/internal/core/providers/gas-providers.js +1 -33
- package/internal/core/providers/gas-providers.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +1 -1
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/node.js +1 -1
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +5 -0
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/util/global-dir.d.ts +5 -0
- package/internal/util/global-dir.d.ts.map +1 -1
- package/internal/util/global-dir.js +17 -1
- package/internal/util/global-dir.js.map +1 -1
- package/internal/util/keys-derivation.d.ts.map +1 -1
- package/internal/util/keys-derivation.js +3 -1
- package/internal/util/keys-derivation.js.map +1 -1
- package/package.json +19 -9
- package/recommended-gitignore.txt +2 -0
- package/sample-projects/{basic → javascript}/LICENSE.md +1 -1
- package/sample-projects/javascript/README.md +13 -0
- package/sample-projects/javascript/contracts/Lock.sol +34 -0
- package/sample-projects/javascript/hardhat.config.js +6 -0
- package/sample-projects/javascript/scripts/deploy.js +29 -0
- package/sample-projects/javascript/test/Lock.js +126 -0
- package/sample-projects/typescript/LICENSE.md +11 -0
- package/sample-projects/typescript/README.md +13 -0
- package/sample-projects/typescript/contracts/Lock.sol +34 -0
- package/sample-projects/typescript/hardhat.config.ts +8 -0
- package/sample-projects/typescript/scripts/deploy.ts +23 -0
- package/sample-projects/typescript/test/Lock.ts +124 -0
- package/sample-projects/typescript/tsconfig.json +10 -0
- package/src/internal/cli/cli.ts +55 -7
- package/src/internal/cli/hardhat-vscode-installation.ts +43 -0
- package/src/internal/cli/project-creation.ts +124 -290
- package/src/internal/cli/prompt.ts +143 -0
- package/src/internal/cli/types.ts +3 -0
- package/src/internal/core/config/config-loading.ts +1 -1
- package/src/internal/core/errors-list.ts +4 -4
- package/src/internal/core/providers/construction.ts +0 -9
- package/src/internal/core/providers/gas-providers.ts +0 -39
- package/src/internal/hardhat-network/provider/modules/logger.ts +1 -1
- package/src/internal/hardhat-network/provider/node.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +6 -0
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +1 -1
- package/src/internal/util/global-dir.ts +19 -0
- package/src/internal/util/keys-derivation.ts +3 -1
- package/sample-projects/advanced/.env.example +0 -3
- package/sample-projects/advanced/.eslintignore +0 -4
- package/sample-projects/advanced/.eslintrc.js +0 -22
- package/sample-projects/advanced/.prettierignore +0 -5
- package/sample-projects/advanced/.prettierrc +0 -1
- package/sample-projects/advanced/.solhint.json +0 -7
- package/sample-projects/advanced/.solhintignore +0 -1
- package/sample-projects/advanced/README.md +0 -42
- package/sample-projects/advanced/hardhat.config.js +0 -40
- package/sample-projects/advanced/npmignore +0 -3
- package/sample-projects/advanced/scripts/deploy.js +0 -30
- package/sample-projects/advanced-ts/.eslintrc.js +0 -24
- package/sample-projects/advanced-ts/README.md +0 -46
- package/sample-projects/advanced-ts/hardhat.config.ts +0 -43
- package/sample-projects/advanced-ts/npmignore +0 -3
- package/sample-projects/advanced-ts/scripts/deploy.ts +0 -30
- package/sample-projects/advanced-ts/test/index.ts +0 -19
- package/sample-projects/advanced-ts/tsconfig.json +0 -12
- package/sample-projects/basic/README.md +0 -15
- package/sample-projects/basic/contracts/Greeter.sol +0 -22
- package/sample-projects/basic/hardhat.config.js +0 -21
- package/sample-projects/basic/scripts/sample-script.js +0 -32
- package/sample-projects/basic/test/sample-test.js +0 -19
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Dependencies } from "./types";
|
|
2
|
+
|
|
3
|
+
function createConfirmationPrompt(name: string, message: string) {
|
|
4
|
+
return {
|
|
5
|
+
type: "confirm",
|
|
6
|
+
name,
|
|
7
|
+
message,
|
|
8
|
+
initial: "y",
|
|
9
|
+
default: "(Y/n)",
|
|
10
|
+
isTrue(input: string | boolean) {
|
|
11
|
+
if (typeof input === "string") {
|
|
12
|
+
return input.toLowerCase() === "y";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return input;
|
|
16
|
+
},
|
|
17
|
+
isFalse(input: string | boolean) {
|
|
18
|
+
if (typeof input === "string") {
|
|
19
|
+
return input.toLowerCase() === "n";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return input;
|
|
23
|
+
},
|
|
24
|
+
format(): string {
|
|
25
|
+
const that = this as any;
|
|
26
|
+
const value = that.value === true ? "y" : "n";
|
|
27
|
+
|
|
28
|
+
if (that.state.submitted === true) {
|
|
29
|
+
return that.styles.submitted(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return value;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function confirmRecommendedDepsInstallation(
|
|
38
|
+
depsToInstall: Dependencies,
|
|
39
|
+
useYarn: boolean
|
|
40
|
+
): Promise<boolean> {
|
|
41
|
+
const { default: enquirer } = await import("enquirer");
|
|
42
|
+
|
|
43
|
+
let responses: {
|
|
44
|
+
shouldInstallPlugin: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const packageManager = useYarn ? "yarn" : "npm";
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
responses = await enquirer.prompt<typeof responses>([
|
|
51
|
+
createConfirmationPrompt(
|
|
52
|
+
"shouldInstallPlugin",
|
|
53
|
+
`Do you want to install this sample project's dependencies with ${packageManager} (${Object.keys(
|
|
54
|
+
depsToInstall
|
|
55
|
+
).join(" ")})?`
|
|
56
|
+
),
|
|
57
|
+
]);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
if (e === "") {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return responses.shouldInstallPlugin;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function confirmProjectCreation(): Promise<{
|
|
71
|
+
projectRoot: string;
|
|
72
|
+
shouldAddGitIgnore: boolean;
|
|
73
|
+
}> {
|
|
74
|
+
const enquirer = require("enquirer");
|
|
75
|
+
return enquirer.prompt([
|
|
76
|
+
{
|
|
77
|
+
name: "projectRoot",
|
|
78
|
+
type: "input",
|
|
79
|
+
initial: process.cwd(),
|
|
80
|
+
message: "Hardhat project root:",
|
|
81
|
+
},
|
|
82
|
+
createConfirmationPrompt(
|
|
83
|
+
"shouldAddGitIgnore",
|
|
84
|
+
"Do you want to add a .gitignore?"
|
|
85
|
+
),
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function confirmTelemetryConsent(): Promise<boolean | undefined> {
|
|
90
|
+
return confirmationPromptWithTimeout(
|
|
91
|
+
"telemetryConsent",
|
|
92
|
+
"Help us improve Hardhat with anonymous crash reports & basic usage data?"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* true = install ext
|
|
98
|
+
* false = don't install and don't ask again
|
|
99
|
+
* undefined = we couldn't confirm if the extension is installed or not
|
|
100
|
+
*/
|
|
101
|
+
export async function confirmHHVSCodeInstallation(): Promise<
|
|
102
|
+
boolean | undefined
|
|
103
|
+
> {
|
|
104
|
+
return confirmationPromptWithTimeout(
|
|
105
|
+
"shouldInstallExtension",
|
|
106
|
+
"Would you like to install the Hardhat for Visual Studio Code extension? It adds advanced editing assistance for Solidity to VSCode"
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function confirmationPromptWithTimeout(
|
|
111
|
+
name: string,
|
|
112
|
+
message: string,
|
|
113
|
+
timeoutMilliseconds: number = 10_000
|
|
114
|
+
): Promise<boolean | undefined> {
|
|
115
|
+
try {
|
|
116
|
+
const enquirer = require("enquirer");
|
|
117
|
+
|
|
118
|
+
const prompt = new enquirer.prompts.Confirm(
|
|
119
|
+
createConfirmationPrompt(name, message)
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
let timeout;
|
|
123
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
124
|
+
timeout = setTimeout(resolve, timeoutMilliseconds);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const result = await Promise.race([prompt.run(), timeoutPromise]);
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
|
|
130
|
+
if (result === undefined) {
|
|
131
|
+
await prompt.cancel();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return result;
|
|
135
|
+
} catch (e: any) {
|
|
136
|
+
if (e === "") {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -291,7 +291,7 @@ function checkUnsupportedSolidityConfig(resolvedConfig: HardhatConfig) {
|
|
|
291
291
|
unsupportedVersions.length === 1 ? "is" : "are"
|
|
292
292
|
} not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.
|
|
293
293
|
|
|
294
|
-
Learn more at https://hardhat.org/reference/solidity-support
|
|
294
|
+
Learn more at https://hardhat.org/hardhat-runner/docs/reference/solidity-support
|
|
295
295
|
`
|
|
296
296
|
)
|
|
297
297
|
);
|
|
@@ -51,7 +51,7 @@ export const ERRORS = {
|
|
|
51
51
|
title: "You are not inside a Hardhat project",
|
|
52
52
|
description: `You are trying to run Hardhat outside of a Hardhat project.
|
|
53
53
|
|
|
54
|
-
You can learn how to use Hardhat by reading the [Getting Started guide](
|
|
54
|
+
You can learn how to use Hardhat by reading the [Getting Started guide](/hardhat-runner/docs/getting-started).`,
|
|
55
55
|
shouldBeReported: false,
|
|
56
56
|
},
|
|
57
57
|
INVALID_NODE_VERSION: {
|
|
@@ -213,7 +213,7 @@ If you were trying to create a new project, please try again using Windows Subsy
|
|
|
213
213
|
|
|
214
214
|
If you were trying to create a new project, please try again using Windows Subsystem for Linux (WSL) or PowerShell.
|
|
215
215
|
|
|
216
|
-
You can learn how to use Hardhat by reading the [Getting Started guide](
|
|
216
|
+
You can learn how to use Hardhat by reading the [Getting Started guide](/hardhat-runner/docs/getting-started).`,
|
|
217
217
|
shouldBeReported: false,
|
|
218
218
|
},
|
|
219
219
|
CONFLICTING_FILES: {
|
|
@@ -245,7 +245,7 @@ Either try using a new directory name, or remove the conflicting files.`,
|
|
|
245
245
|
title: "Selected network doesn't exist",
|
|
246
246
|
description: `You are trying to run Hardhat with a nonexistent network.
|
|
247
247
|
|
|
248
|
-
Read the [documentation](https://hardhat.org/config
|
|
248
|
+
Read the [documentation](https://hardhat.org/hardhat-runner/docs/config#networks-configuration) to learn how to define custom networks.`,
|
|
249
249
|
shouldBeReported: false,
|
|
250
250
|
},
|
|
251
251
|
INVALID_GLOBAL_CHAIN_ID: {
|
|
@@ -305,7 +305,7 @@ Please make sure that your Ethereum node has unlocked accounts.`,
|
|
|
305
305
|
title: "Invalid HD path",
|
|
306
306
|
description: `An invalid HD/BIP32 derivation path was provided in your config.
|
|
307
307
|
|
|
308
|
-
Read the [documentation](https://hardhat.org/config
|
|
308
|
+
Read the [documentation](https://hardhat.org/hardhat-runner/docs/config#hd-wallet-config) to learn how to define HD accounts correctly.`,
|
|
309
309
|
shouldBeReported: false,
|
|
310
310
|
},
|
|
311
311
|
INVALID_RPC_QUANTITY_VALUE: {
|
|
@@ -171,11 +171,6 @@ export function applyProviderWrappers(
|
|
|
171
171
|
typeof import("./gas-providers"),
|
|
172
172
|
"FixedGasPriceProvider"
|
|
173
173
|
>("./gas-providers", "FixedGasPriceProvider");
|
|
174
|
-
const GanacheGasMultiplierProvider = importProvider<
|
|
175
|
-
typeof import("./gas-providers"),
|
|
176
|
-
"GanacheGasMultiplierProvider"
|
|
177
|
-
>("./gas-providers", "GanacheGasMultiplierProvider");
|
|
178
|
-
|
|
179
174
|
const ChainIdValidatorProvider = importProvider<
|
|
180
175
|
typeof import("./chainId"),
|
|
181
176
|
"ChainIdValidatorProvider"
|
|
@@ -198,10 +193,6 @@ export function applyProviderWrappers(
|
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
// TODO: Add some extension mechanism for account plugins here
|
|
201
|
-
|
|
202
|
-
if (typeof netConfig.gas !== "number") {
|
|
203
|
-
provider = new GanacheGasMultiplierProvider(provider);
|
|
204
|
-
}
|
|
205
196
|
}
|
|
206
197
|
|
|
207
198
|
if (netConfig.from !== undefined) {
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
import { ProviderWrapper } from "./wrapper";
|
|
10
10
|
|
|
11
11
|
const DEFAULT_GAS_MULTIPLIER = 1;
|
|
12
|
-
export const GANACHE_GAS_MULTIPLIER = 5;
|
|
13
12
|
|
|
14
13
|
export class FixedGasProvider extends ProviderWrapper {
|
|
15
14
|
constructor(provider: EIP1193Provider, private readonly _gasLimit: number) {
|
|
@@ -286,41 +285,3 @@ export class AutomaticGasPriceProvider extends ProviderWrapper {
|
|
|
286
285
|
}
|
|
287
286
|
}
|
|
288
287
|
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* This provider multiplies whatever gas estimation Ganache gives by [[GANACHE_GAS_MULTIPLIER]]
|
|
292
|
-
*
|
|
293
|
-
* NOTE: This bug was present at least in Ganache 6.4.x.
|
|
294
|
-
* One way to test if the bug is still present is to check if the estimation to
|
|
295
|
-
* run a deployment transaction with this data is high enough:
|
|
296
|
-
* * 0x608060405234801561001057600080fd5b5060405161043e38038061043e8339810180604052602081101561003357600080fd5b81019080805164010000000081111561004b57600080fd5b8281019050602081018481111561006157600080fd5b815185600182028301116401000000008211171561007e57600080fd5b50509291905050506040516100929061010b565b604051809103906000f0801580156100ae573d6000803e3d6000fd5b506000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060019080519060200190610104929190610117565b50506101bc565b6088806103b683390190565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015857805160ff1916838001178555610186565b82800160010185558215610186579182015b8281111561018557825182559160200191906001019061016a565b5b5090506101939190610197565b5090565b6101b991905b808211156101b557600081600090555060010161019d565b5090565b90565b6101eb806101cb6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063f86cc00914610030575b600080fd5b61003861003a565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166319ff1d216040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156100a357600080fd5b505af11580156100b7573d6000803e3d6000fd5b505050506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166319ff1d216040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561012457600080fd5b505af1158015610138573d6000803e3d6000fd5b505050506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166319ff1d216040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156101a557600080fd5b505af11580156101b9573d6000803e3d6000fd5b5050505056fea165627a7a723058203691efa02f6279a7b7eea9265988d2deaf417c2590c3103779c96b68e78463b700296080604052348015600f57600080fd5b50606b80601d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806319ff1d2114602d575b600080fd5b60336035565b005b600560008190555056fea165627a7a72305820a00cf00e60c019ed83e0857faef9e9383880a5addd91429d30203771c82a4014002900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000
|
|
297
|
-
*/
|
|
298
|
-
export class GanacheGasMultiplierProvider extends MultipliedGasEstimationProvider {
|
|
299
|
-
private _cachedIsGanache: boolean | undefined;
|
|
300
|
-
|
|
301
|
-
constructor(provider: EIP1193Provider) {
|
|
302
|
-
super(provider, GANACHE_GAS_MULTIPLIER);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
public async request(args: RequestArguments): Promise<unknown> {
|
|
306
|
-
const isGanache = await this._isGanache();
|
|
307
|
-
if (args.method === "eth_estimateGas" && isGanache) {
|
|
308
|
-
const params = this._getParams(args);
|
|
309
|
-
return this._getMultipliedGasEstimation(params);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return this._wrappedProvider.request(args);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private async _isGanache(): Promise<boolean> {
|
|
316
|
-
if (this._cachedIsGanache === undefined) {
|
|
317
|
-
const clientVersion = (await this._wrappedProvider.request({
|
|
318
|
-
method: "web3_clientVersion",
|
|
319
|
-
})) as string;
|
|
320
|
-
|
|
321
|
-
this._cachedIsGanache = clientVersion.includes("TestRPC");
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return this._cachedIsGanache;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
@@ -496,7 +496,7 @@ export class ModulesLogger {
|
|
|
496
496
|
this.printEmptyLine();
|
|
497
497
|
|
|
498
498
|
this._print(
|
|
499
|
-
"If you think this is a bug in Hardhat, please report it here: https://hardhat.org/
|
|
499
|
+
"If you think this is a bug in Hardhat, please report it here: https://hardhat.org/report-bug"
|
|
500
500
|
);
|
|
501
501
|
});
|
|
502
502
|
}
|
|
@@ -2532,7 +2532,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
|
|
|
2532
2532
|
throw new InternalError(
|
|
2533
2533
|
`No known hardfork for execution on historical block ${blockNumber.toString()} (relative to fork block number ${
|
|
2534
2534
|
this._forkBlockNumber
|
|
2535
|
-
}). The node was not configured with a hardfork activation history. See http://hardhat.org/
|
|
2535
|
+
}). The node was not configured with a hardfork activation history. See http://hardhat.org/custom-hardfork-history`
|
|
2536
2536
|
);
|
|
2537
2537
|
}
|
|
2538
2538
|
|
|
@@ -1586,6 +1586,12 @@ export class ErrorInferrer {
|
|
|
1586
1586
|
return true;
|
|
1587
1587
|
}
|
|
1588
1588
|
|
|
1589
|
+
// If the return data is not empty, and it's still the same, we assume it
|
|
1590
|
+
// is being propagated
|
|
1591
|
+
if (trace.returnData.length > 0) {
|
|
1592
|
+
return true;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1589
1595
|
return this._failsRightAfterCall(trace, callSubtraceStepIndex);
|
|
1590
1596
|
}
|
|
1591
1597
|
|
|
@@ -285,7 +285,7 @@ function getMessageFromLastStackTraceEntry(
|
|
|
285
285
|
|
|
286
286
|
case StackTraceEntryType.OTHER_EXECUTION_ERROR:
|
|
287
287
|
// TODO: What if there was returnData?
|
|
288
|
-
return `Transaction reverted and Hardhat couldn't infer the reason
|
|
288
|
+
return `Transaction reverted and Hardhat couldn't infer the reason.`;
|
|
289
289
|
|
|
290
290
|
case StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR:
|
|
291
291
|
return "Transaction reverted without a reason string and without a valid sourcemap provided by the compiler. Some line numbers may be off. We strongly recommend upgrading solc and always using revert reasons.";
|
|
@@ -120,3 +120,22 @@ export function writeTelemetryConsent(consent: boolean) {
|
|
|
120
120
|
|
|
121
121
|
fs.writeJSONSync(telemetryConsentPath, { consent }, { spaces: 2 });
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Checks if we have already prompted the user to install the Hardhat for VSCode extension.
|
|
126
|
+
*/
|
|
127
|
+
export function hasPromptedForHHVSCode(): boolean {
|
|
128
|
+
const configDir = getConfigDirSync();
|
|
129
|
+
const extensionPromptedPath = path.join(configDir, "extension-prompt.json");
|
|
130
|
+
|
|
131
|
+
const fileExists = fs.pathExistsSync(extensionPromptedPath);
|
|
132
|
+
|
|
133
|
+
return fileExists;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function writePromptedForHHVSCode() {
|
|
137
|
+
const configDir = getConfigDirSync();
|
|
138
|
+
const extensionPromptedPath = path.join(configDir, "extension-prompt.json");
|
|
139
|
+
|
|
140
|
+
fs.writeFileSync(extensionPromptedPath, "{}");
|
|
141
|
+
}
|
|
@@ -22,5 +22,7 @@ export function deriveKeyFromMnemonicAndPath(
|
|
|
22
22
|
const masterKey = HDKey.fromMasterSeed(seed);
|
|
23
23
|
const derived = masterKey.derive(hdPath);
|
|
24
24
|
|
|
25
|
-
return derived.privateKey === null
|
|
25
|
+
return derived.privateKey === null
|
|
26
|
+
? undefined
|
|
27
|
+
: Buffer.from(derived.privateKey);
|
|
26
28
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: false,
|
|
4
|
-
es2021: true,
|
|
5
|
-
mocha: true,
|
|
6
|
-
node: true,
|
|
7
|
-
},
|
|
8
|
-
extends: [
|
|
9
|
-
"standard",
|
|
10
|
-
"plugin:prettier/recommended",
|
|
11
|
-
"plugin:node/recommended",
|
|
12
|
-
],
|
|
13
|
-
parserOptions: {
|
|
14
|
-
ecmaVersion: 12,
|
|
15
|
-
},
|
|
16
|
-
overrides: [
|
|
17
|
-
{
|
|
18
|
-
files: ["hardhat.config.js"],
|
|
19
|
-
globals: { task: true },
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# Advanced Sample Hardhat Project
|
|
2
|
-
|
|
3
|
-
This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.
|
|
4
|
-
|
|
5
|
-
The project comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. It also comes with a variety of other tools, preconfigured to work with the project code.
|
|
6
|
-
|
|
7
|
-
Try running some of the following tasks:
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
npx hardhat accounts
|
|
11
|
-
npx hardhat compile
|
|
12
|
-
npx hardhat clean
|
|
13
|
-
npx hardhat test
|
|
14
|
-
npx hardhat node
|
|
15
|
-
npx hardhat help
|
|
16
|
-
REPORT_GAS=true npx hardhat test
|
|
17
|
-
npx hardhat coverage
|
|
18
|
-
npx hardhat run scripts/deploy.js
|
|
19
|
-
node scripts/deploy.js
|
|
20
|
-
npx eslint '**/*.js'
|
|
21
|
-
npx eslint '**/*.js' --fix
|
|
22
|
-
npx prettier '**/*.{json,sol,md}' --check
|
|
23
|
-
npx prettier '**/*.{json,sol,md}' --write
|
|
24
|
-
npx solhint 'contracts/**/*.sol'
|
|
25
|
-
npx solhint 'contracts/**/*.sol' --fix
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
# Etherscan verification
|
|
29
|
-
|
|
30
|
-
To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.
|
|
31
|
-
|
|
32
|
-
In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
|
|
33
|
-
|
|
34
|
-
```shell
|
|
35
|
-
hardhat run --network ropsten scripts/deploy.js
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
|
|
39
|
-
|
|
40
|
-
```shell
|
|
41
|
-
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
|
|
42
|
-
```
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require("dotenv").config();
|
|
2
|
-
|
|
3
|
-
require("@nomiclabs/hardhat-etherscan");
|
|
4
|
-
require("@nomiclabs/hardhat-waffle");
|
|
5
|
-
require("hardhat-gas-reporter");
|
|
6
|
-
require("solidity-coverage");
|
|
7
|
-
|
|
8
|
-
// This is a sample Hardhat task. To learn how to create your own go to
|
|
9
|
-
// https://hardhat.org/guides/create-task.html
|
|
10
|
-
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
|
|
11
|
-
const accounts = await hre.ethers.getSigners();
|
|
12
|
-
|
|
13
|
-
for (const account of accounts) {
|
|
14
|
-
console.log(account.address);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// You need to export an object to set up your config
|
|
19
|
-
// Go to https://hardhat.org/config/ to learn more
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @type import('hardhat/config').HardhatUserConfig
|
|
23
|
-
*/
|
|
24
|
-
module.exports = {
|
|
25
|
-
solidity: "0.8.4",
|
|
26
|
-
networks: {
|
|
27
|
-
ropsten: {
|
|
28
|
-
url: process.env.ROPSTEN_URL || "",
|
|
29
|
-
accounts:
|
|
30
|
-
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
gasReporter: {
|
|
34
|
-
enabled: process.env.REPORT_GAS !== undefined,
|
|
35
|
-
currency: "USD",
|
|
36
|
-
},
|
|
37
|
-
etherscan: {
|
|
38
|
-
apiKey: process.env.ETHERSCAN_API_KEY,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// We require the Hardhat Runtime Environment explicitly here. This is optional
|
|
2
|
-
// but useful for running the script in a standalone fashion through `node <script>`.
|
|
3
|
-
//
|
|
4
|
-
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
|
|
5
|
-
// Runtime Environment's members available in the global scope.
|
|
6
|
-
const hre = require("hardhat");
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
// Hardhat always runs the compile task when running scripts with its command
|
|
10
|
-
// line interface.
|
|
11
|
-
//
|
|
12
|
-
// If this script is run directly using `node` you may want to call compile
|
|
13
|
-
// manually to make sure everything is compiled
|
|
14
|
-
// await hre.run('compile');
|
|
15
|
-
|
|
16
|
-
// We get the contract to deploy
|
|
17
|
-
const Greeter = await hre.ethers.getContractFactory("Greeter");
|
|
18
|
-
const greeter = await Greeter.deploy("Hello, Hardhat!");
|
|
19
|
-
|
|
20
|
-
await greeter.deployed();
|
|
21
|
-
|
|
22
|
-
console.log("Greeter deployed to:", greeter.address);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// We recommend this pattern to be able to use async/await everywhere
|
|
26
|
-
// and properly handle errors.
|
|
27
|
-
main().catch((error) => {
|
|
28
|
-
console.error(error);
|
|
29
|
-
process.exitCode = 1;
|
|
30
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: false,
|
|
4
|
-
es2021: true,
|
|
5
|
-
mocha: true,
|
|
6
|
-
node: true,
|
|
7
|
-
},
|
|
8
|
-
plugins: ["@typescript-eslint"],
|
|
9
|
-
extends: [
|
|
10
|
-
"standard",
|
|
11
|
-
"plugin:prettier/recommended",
|
|
12
|
-
"plugin:node/recommended",
|
|
13
|
-
],
|
|
14
|
-
parser: "@typescript-eslint/parser",
|
|
15
|
-
parserOptions: {
|
|
16
|
-
ecmaVersion: 12,
|
|
17
|
-
},
|
|
18
|
-
rules: {
|
|
19
|
-
"node/no-unsupported-features/es-syntax": [
|
|
20
|
-
"error",
|
|
21
|
-
{ ignores: ["modules"] },
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# Advanced Sample Hardhat Project
|
|
2
|
-
|
|
3
|
-
This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.
|
|
4
|
-
|
|
5
|
-
The project comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. It also comes with a variety of other tools, preconfigured to work with the project code.
|
|
6
|
-
|
|
7
|
-
Try running some of the following tasks:
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
npx hardhat accounts
|
|
11
|
-
npx hardhat compile
|
|
12
|
-
npx hardhat clean
|
|
13
|
-
npx hardhat test
|
|
14
|
-
npx hardhat node
|
|
15
|
-
npx hardhat help
|
|
16
|
-
REPORT_GAS=true npx hardhat test
|
|
17
|
-
npx hardhat coverage
|
|
18
|
-
npx hardhat run scripts/deploy.ts
|
|
19
|
-
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
|
|
20
|
-
npx eslint '**/*.{js,ts}'
|
|
21
|
-
npx eslint '**/*.{js,ts}' --fix
|
|
22
|
-
npx prettier '**/*.{json,sol,md}' --check
|
|
23
|
-
npx prettier '**/*.{json,sol,md}' --write
|
|
24
|
-
npx solhint 'contracts/**/*.sol'
|
|
25
|
-
npx solhint 'contracts/**/*.sol' --fix
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
# Etherscan verification
|
|
29
|
-
|
|
30
|
-
To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.
|
|
31
|
-
|
|
32
|
-
In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
|
|
33
|
-
|
|
34
|
-
```shell
|
|
35
|
-
hardhat run --network ropsten scripts/deploy.ts
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
|
|
39
|
-
|
|
40
|
-
```shell
|
|
41
|
-
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
# Performance optimizations
|
|
45
|
-
|
|
46
|
-
For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations).
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as dotenv from "dotenv";
|
|
2
|
-
|
|
3
|
-
import { HardhatUserConfig, task } from "hardhat/config";
|
|
4
|
-
import "@nomiclabs/hardhat-etherscan";
|
|
5
|
-
import "@nomiclabs/hardhat-waffle";
|
|
6
|
-
import "@typechain/hardhat";
|
|
7
|
-
import "hardhat-gas-reporter";
|
|
8
|
-
import "solidity-coverage";
|
|
9
|
-
|
|
10
|
-
dotenv.config();
|
|
11
|
-
|
|
12
|
-
// This is a sample Hardhat task. To learn how to create your own go to
|
|
13
|
-
// https://hardhat.org/guides/create-task.html
|
|
14
|
-
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
|
|
15
|
-
const accounts = await hre.ethers.getSigners();
|
|
16
|
-
|
|
17
|
-
for (const account of accounts) {
|
|
18
|
-
console.log(account.address);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// You need to export an object to set up your config
|
|
23
|
-
// Go to https://hardhat.org/config/ to learn more
|
|
24
|
-
|
|
25
|
-
const config: HardhatUserConfig = {
|
|
26
|
-
solidity: "0.8.4",
|
|
27
|
-
networks: {
|
|
28
|
-
ropsten: {
|
|
29
|
-
url: process.env.ROPSTEN_URL || "",
|
|
30
|
-
accounts:
|
|
31
|
-
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
gasReporter: {
|
|
35
|
-
enabled: process.env.REPORT_GAS !== undefined,
|
|
36
|
-
currency: "USD",
|
|
37
|
-
},
|
|
38
|
-
etherscan: {
|
|
39
|
-
apiKey: process.env.ETHERSCAN_API_KEY,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default config;
|