hardhat 2.9.9 → 2.10.2-dev.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 (108) hide show
  1. package/README.md +1 -1
  2. package/console.sol +444 -444
  3. package/internal/cli/cli.js +37 -7
  4. package/internal/cli/cli.js.map +1 -1
  5. package/internal/cli/hardhat-vscode-installation.d.ts +8 -0
  6. package/internal/cli/hardhat-vscode-installation.d.ts.map +1 -0
  7. package/internal/cli/hardhat-vscode-installation.js +41 -0
  8. package/internal/cli/hardhat-vscode-installation.js.map +1 -0
  9. package/internal/cli/project-creation.d.ts +0 -1
  10. package/internal/cli/project-creation.d.ts.map +1 -1
  11. package/internal/cli/project-creation.js +87 -179
  12. package/internal/cli/project-creation.js.map +1 -1
  13. package/internal/cli/prompt.d.ts +14 -0
  14. package/internal/cli/prompt.d.ts.map +1 -0
  15. package/internal/cli/prompt.js +120 -0
  16. package/internal/cli/prompt.js.map +1 -0
  17. package/internal/cli/types.d.ts +4 -0
  18. package/internal/cli/types.d.ts.map +1 -0
  19. package/internal/cli/types.js +3 -0
  20. package/internal/cli/types.js.map +1 -0
  21. package/internal/core/config/config-loading.js +1 -1
  22. package/internal/core/errors-list.js +4 -4
  23. package/internal/core/errors-list.js.map +1 -1
  24. package/internal/core/providers/construction.d.ts.map +1 -1
  25. package/internal/core/providers/construction.js +0 -4
  26. package/internal/core/providers/construction.js.map +1 -1
  27. package/internal/core/providers/gas-providers.d.ts +0 -15
  28. package/internal/core/providers/gas-providers.d.ts.map +1 -1
  29. package/internal/core/providers/gas-providers.js +1 -33
  30. package/internal/core/providers/gas-providers.js.map +1 -1
  31. package/internal/hardhat-network/provider/modules/logger.js +1 -1
  32. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  33. package/internal/hardhat-network/provider/node.js +1 -1
  34. package/internal/hardhat-network/provider/node.js.map +1 -1
  35. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
  36. package/internal/hardhat-network/stack-traces/consoleLogger.js +6 -2
  37. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  38. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  39. package/internal/hardhat-network/stack-traces/error-inferrer.js +5 -0
  40. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  41. package/internal/hardhat-network/stack-traces/logger.d.ts +223 -2
  42. package/internal/hardhat-network/stack-traces/logger.d.ts.map +1 -1
  43. package/internal/hardhat-network/stack-traces/logger.js +445 -224
  44. package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
  45. package/internal/hardhat-network/stack-traces/solidity-errors.js +1 -1
  46. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  47. package/internal/util/global-dir.d.ts +5 -0
  48. package/internal/util/global-dir.d.ts.map +1 -1
  49. package/internal/util/global-dir.js +17 -1
  50. package/internal/util/global-dir.js.map +1 -1
  51. package/internal/util/keys-derivation.d.ts.map +1 -1
  52. package/internal/util/keys-derivation.js +3 -1
  53. package/internal/util/keys-derivation.js.map +1 -1
  54. package/package.json +7 -6
  55. package/recommended-gitignore.txt +2 -0
  56. package/sample-projects/{basic → javascript}/LICENSE.md +1 -1
  57. package/sample-projects/javascript/README.md +13 -0
  58. package/sample-projects/javascript/contracts/Lock.sol +34 -0
  59. package/sample-projects/javascript/hardhat.config.js +6 -0
  60. package/sample-projects/javascript/scripts/deploy.js +29 -0
  61. package/sample-projects/javascript/test/Lock.js +126 -0
  62. package/sample-projects/typescript/LICENSE.md +11 -0
  63. package/sample-projects/typescript/README.md +13 -0
  64. package/sample-projects/typescript/contracts/Lock.sol +34 -0
  65. package/sample-projects/typescript/hardhat.config.ts +8 -0
  66. package/sample-projects/typescript/scripts/deploy.ts +23 -0
  67. package/sample-projects/typescript/test/Lock.ts +124 -0
  68. package/sample-projects/typescript/tsconfig.json +10 -0
  69. package/src/internal/cli/cli.ts +55 -7
  70. package/src/internal/cli/hardhat-vscode-installation.ts +43 -0
  71. package/src/internal/cli/project-creation.ts +124 -290
  72. package/src/internal/cli/prompt.ts +143 -0
  73. package/src/internal/cli/types.ts +3 -0
  74. package/src/internal/core/config/config-loading.ts +1 -1
  75. package/src/internal/core/errors-list.ts +4 -4
  76. package/src/internal/core/providers/construction.ts +0 -9
  77. package/src/internal/core/providers/gas-providers.ts +0 -39
  78. package/src/internal/hardhat-network/provider/modules/logger.ts +1 -1
  79. package/src/internal/hardhat-network/provider/node.ts +1 -1
  80. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +9 -4
  81. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +6 -0
  82. package/src/internal/hardhat-network/stack-traces/logger.ts +444 -223
  83. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +1 -1
  84. package/src/internal/util/global-dir.ts +19 -0
  85. package/src/internal/util/keys-derivation.ts +3 -1
  86. package/sample-projects/advanced/.env.example +0 -3
  87. package/sample-projects/advanced/.eslintignore +0 -4
  88. package/sample-projects/advanced/.eslintrc.js +0 -22
  89. package/sample-projects/advanced/.prettierignore +0 -5
  90. package/sample-projects/advanced/.prettierrc +0 -1
  91. package/sample-projects/advanced/.solhint.json +0 -7
  92. package/sample-projects/advanced/.solhintignore +0 -1
  93. package/sample-projects/advanced/README.md +0 -42
  94. package/sample-projects/advanced/hardhat.config.js +0 -40
  95. package/sample-projects/advanced/npmignore +0 -3
  96. package/sample-projects/advanced/scripts/deploy.js +0 -30
  97. package/sample-projects/advanced-ts/.eslintrc.js +0 -24
  98. package/sample-projects/advanced-ts/README.md +0 -46
  99. package/sample-projects/advanced-ts/hardhat.config.ts +0 -43
  100. package/sample-projects/advanced-ts/npmignore +0 -3
  101. package/sample-projects/advanced-ts/scripts/deploy.ts +0 -30
  102. package/sample-projects/advanced-ts/test/index.ts +0 -19
  103. package/sample-projects/advanced-ts/tsconfig.json +0 -12
  104. package/sample-projects/basic/README.md +0 -15
  105. package/sample-projects/basic/contracts/Greeter.sol +0 -22
  106. package/sample-projects/basic/hardhat.config.js +0 -21
  107. package/sample-projects/basic/scripts/sample-script.js +0 -32
  108. package/sample-projects/basic/test/sample-test.js +0 -19
@@ -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. Please report this to help us improve Hardhat.`;
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 ? undefined : derived.privateKey;
25
+ return derived.privateKey === null
26
+ ? undefined
27
+ : Buffer.from(derived.privateKey);
26
28
  }
@@ -1,3 +0,0 @@
1
- ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
2
- ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
3
- PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1
@@ -1,4 +0,0 @@
1
- node_modules
2
- artifacts
3
- cache
4
- coverage
@@ -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,5 +0,0 @@
1
- node_modules
2
- artifacts
3
- cache
4
- coverage*
5
- gasReporterOutput.json
@@ -1 +0,0 @@
1
- {}
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "solhint:recommended",
3
- "rules": {
4
- "compiler-version": ["error", "^0.8.0"],
5
- "func-visibility": ["warn", { "ignoreConstructors": true }]
6
- }
7
- }
@@ -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,3 +0,0 @@
1
- hardhat.config.js
2
- scripts
3
- test
@@ -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;
@@ -1,3 +0,0 @@
1
- hardhat.config.ts
2
- scripts
3
- test
@@ -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
- import { ethers } from "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 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,19 +0,0 @@
1
- import { expect } from "chai";
2
- import { ethers } from "hardhat";
3
-
4
- describe("Greeter", function () {
5
- it("Should return the new greeting once it's changed", async function () {
6
- const Greeter = await ethers.getContractFactory("Greeter");
7
- const greeter = await Greeter.deploy("Hello, world!");
8
- await greeter.deployed();
9
-
10
- expect(await greeter.greet()).to.equal("Hello, world!");
11
-
12
- const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
13
-
14
- // wait until the transaction is mined
15
- await setGreetingTx.wait();
16
-
17
- expect(await greeter.greet()).to.equal("Hola, mundo!");
18
- });
19
- });
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "commonjs",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "outDir": "dist",
8
- "declaration": true
9
- },
10
- "include": ["./scripts", "./test", "./typechain"],
11
- "files": ["./hardhat.config.ts"]
12
- }
@@ -1,15 +0,0 @@
1
- # Basic Sample Hardhat Project
2
-
3
- This project demonstrates a basic Hardhat use case. It 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.
4
-
5
- Try running some of the following tasks:
6
-
7
- ```shell
8
- npx hardhat accounts
9
- npx hardhat compile
10
- npx hardhat clean
11
- npx hardhat test
12
- npx hardhat node
13
- node scripts/sample-script.js
14
- npx hardhat help
15
- ```
@@ -1,22 +0,0 @@
1
- //SPDX-License-Identifier: Unlicense
2
- pragma solidity ^0.8.0;
3
-
4
- import "hardhat/console.sol";
5
-
6
- contract Greeter {
7
- string private greeting;
8
-
9
- constructor(string memory _greeting) {
10
- console.log("Deploying a Greeter with greeting:", _greeting);
11
- greeting = _greeting;
12
- }
13
-
14
- function greet() public view returns (string memory) {
15
- return greeting;
16
- }
17
-
18
- function setGreeting(string memory _greeting) public {
19
- console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
20
- greeting = _greeting;
21
- }
22
- }
@@ -1,21 +0,0 @@
1
- require("@nomiclabs/hardhat-waffle");
2
-
3
- // This is a sample Hardhat task. To learn how to create your own go to
4
- // https://hardhat.org/guides/create-task.html
5
- task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
6
- const accounts = await hre.ethers.getSigners();
7
-
8
- for (const account of accounts) {
9
- console.log(account.address);
10
- }
11
- });
12
-
13
- // You need to export an object to set up your config
14
- // Go to https://hardhat.org/config/ to learn more
15
-
16
- /**
17
- * @type import('hardhat/config').HardhatUserConfig
18
- */
19
- module.exports = {
20
- solidity: "0.8.4",
21
- };
@@ -1,32 +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()
28
- .then(() => process.exit(0))
29
- .catch((error) => {
30
- console.error(error);
31
- process.exit(1);
32
- });
@@ -1,19 +0,0 @@
1
- const { expect } = require("chai");
2
- const { ethers } = require("hardhat");
3
-
4
- describe("Greeter", function () {
5
- it("Should return the new greeting once it's changed", async function () {
6
- const Greeter = await ethers.getContractFactory("Greeter");
7
- const greeter = await Greeter.deploy("Hello, world!");
8
- await greeter.deployed();
9
-
10
- expect(await greeter.greet()).to.equal("Hello, world!");
11
-
12
- const setGreetingTx = await greeter.setGreeting("Hola, mundo!");
13
-
14
- // wait until the transaction is mined
15
- await setGreetingTx.wait();
16
-
17
- expect(await greeter.greet()).to.equal("Hola, mundo!");
18
- });
19
- });