Skip to content

Commit 929ccb5

Browse files
Merge pull request #5787 from NomicFoundation/feature/port-hh-ethers
Port 'hardhat-ethers' plugin from V2 to V3
2 parents 32b867e + 5a170ac commit 929ccb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+8050
-0
lines changed

.changeset/pre.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@ignored/hardhat-vnext": "2.0.0",
2424
"@ignored/hardhat-vnext-build-system": "2.0.0",
2525
"@ignored/hardhat-vnext-errors": "2.0.0",
26+
"@ignored/hardhat-vnext-ethers": "2.0.0",
2627
"@ignored/hardhat-vnext-keystore": "2.0.0",
2728
"@ignored/hardhat-vnext-network-helpers": "2.0.0",
2829
"@ignored/hardhat-vnext-node-test-reporter": "2.0.0",

pnpm-lock.yaml

+79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v-next/example-project/hardhat.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import HardhatMochaTestRunner from "@ignored/hardhat-vnext-mocha-test-runner";
99
import HardhatKeystore from "@ignored/hardhat-vnext-keystore";
1010
import { viemScketchPlugin } from "./viem-scketch-plugin.js";
1111
import hardhatNetworkHelpersPlugin from "@ignored/hardhat-vnext-network-helpers";
12+
import hardhatEthersPlugin from "@ignored/hardhat-vnext-ethers";
1213

1314
const exampleEmptyTask = emptyTask("empty", "An example empty task").build();
1415

@@ -120,6 +121,7 @@ const config: HardhatUserConfig = {
120121
],
121122
plugins: [
122123
pluginExample,
124+
hardhatEthersPlugin,
123125
HardhatKeystore,
124126
// HardhatMochaTestRunner,
125127
// if testing node plugin, use the following line instead

v-next/example-project/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"devDependencies": {
2323
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.3",
24+
"@ignored/hardhat-vnext-ethers": "workspace:^3.0.0-next.2",
2425
"@ignored/hardhat-vnext-keystore": "workspace:^3.0.0-next.2",
2526
"@ignored/hardhat-vnext-mocha-test-runner": "workspace:^3.0.0-next.2",
2627
"@ignored/hardhat-vnext-network-helpers": "workspace:^3.0.0-next.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* How to run this script:
3+
* 1) Start a Hardhat V2 node (until the V3 node is ready)
4+
* 3) Run this script with `npx hardhat run scripts/hardhat-ethers.ts`.
5+
*/
6+
7+
import hre from "@ignored/hardhat-vnext";
8+
9+
const { ethers } = await hre.network.connect();
10+
11+
// ethers functionalities
12+
ethers.isAddress("0x1234567890123456789012345678901234567890");
13+
14+
// ethers.Provider
15+
await ethers.provider.getBlockNumber();
16+
17+
// Hardhat helper methods
18+
await ethers.getSigners();

v-next/example-project/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
},
1616
{
1717
"path": "../hardhat-keystore"
18+
},
19+
{
20+
"path": "../hardhat-ethers"
1821
}
1922
]
2023
}

v-next/hardhat-errors/src/descriptors.ts

+93
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export const ERROR_CATEGORIES: {
7878
max: 1099,
7979
websiteTitle: "Solidity tests errors",
8080
},
81+
ETHERS: {
82+
min: 1100,
83+
max: 1199,
84+
websiteTitle: "Ethers errors",
85+
},
8186
};
8287

8388
export const ERRORS = {
@@ -698,4 +703,92 @@ This might be caused by using hardhat_reset and loadFixture calls in a testcase.
698703
websiteDescription: `Build info not found for contract while compiling Solidity test contracts.`,
699704
},
700705
},
706+
ETHERS: {
707+
METHOD_NOT_IMPLEMENTED: {
708+
number: 1100,
709+
messageTemplate: `Method "{method}" is not implemented`,
710+
websiteTitle: "Method not implemented",
711+
websiteDescription: "Method not implemented",
712+
},
713+
EVENT_NOT_SUPPORTED: {
714+
number: 1101,
715+
messageTemplate: `Event "{event}" is not supported`,
716+
websiteTitle: "Event not supported",
717+
websiteDescription: "Event not supported",
718+
},
719+
ACCOUNT_INDEX_OUT_OF_RANGE: {
720+
number: 1102,
721+
messageTemplate: `Tried to get account with index {accountIndex} but there are only {accountsLength} accounts`,
722+
websiteTitle: "Account index out of range",
723+
websiteDescription: "Account index out of range",
724+
},
725+
BROADCASTED_TX_DIFFERENT_HASH: {
726+
number: 1103,
727+
messageTemplate: `Expected broadcasted transaction to have hash "{txHash}", but got "{broadcastedTxHash}"`,
728+
websiteTitle: "Broadcasted transaction hash mismatch",
729+
websiteDescription: "Broadcasted transaction hash mismatch",
730+
},
731+
CANNOT_GET_ACCOUNT: {
732+
number: 1104,
733+
messageTemplate: `Cannot get account with address "{address}"`,
734+
websiteTitle: "Cannot get account",
735+
websiteDescription: "Cannot get account",
736+
},
737+
INVALID_BLOCK_TAG: {
738+
number: 1105,
739+
messageTemplate: `Invalid block tag "{blockTag}"`,
740+
websiteTitle: "Invalid block tag",
741+
websiteDescription: "Invalid block tag",
742+
},
743+
INVALID_ARTIFACT_FOR_FACTORY: {
744+
number: 1106,
745+
messageTemplate:
746+
"You are trying to create a contract factory from an artifact, but you have not passed a valid artifact parameter.",
747+
websiteTitle: "Invalid artifact for contract factory creation",
748+
websiteDescription: "Invalid artifact for contract factory creation",
749+
},
750+
INVALID_ABSTRACT_CONTRACT_FOR_FACTORY: {
751+
number: 1107,
752+
messageTemplate: `You are trying to create a contract factory for the contract "{contractName}", which is abstract and can't be deployed. If you want to call a contract using "{contractName}" as its interface use the "getContractAt" function instead.`,
753+
websiteTitle: "Invalid abstract contract for contract factory creation",
754+
websiteDescription:
755+
"Invalid abstract contract for contract factory creation",
756+
},
757+
INVALID_ADDRESS_TO_LINK_CONTRACT_TO_LIBRARY: {
758+
number: 1108,
759+
messageTemplate: `You tried to link the contract "{contractName}" with the library "{linkedLibraryName}", but you provided this invalid address: {resolvedAddress}`,
760+
websiteTitle: "Invalid address to link contract",
761+
websiteDescription: "Invalid address to link contract",
762+
},
763+
LIBRARY_NOT_AMONG_CONTRACT_LIBRARIES: {
764+
number: 1109,
765+
messageTemplate: `You tried to link the contract "{contractName}" with the library "{linkedLibraryName}", which is not one of its libraries. Detailed message: {detailedMessage}`,
766+
websiteTitle: "Library is not one of the contract libraries",
767+
websiteDescription: "Library is not one of the contract libraries",
768+
},
769+
AMBIGUOUS_LIBRARY_NAME: {
770+
number: 1110,
771+
messageTemplate: `The library name "{linkedLibraryName}" is ambiguous for the contract "{contractName}". It may resolve to one of the following libraries: "{matchingNeededLibrariesFQNs}". To fix this, choose one of these fully qualified library names and replace where appropriate.`,
772+
websiteTitle: "Ambiguous library name",
773+
websiteDescription: "Ambiguous library name",
774+
},
775+
REFERENCE_TO_SAME_LIBRARY: {
776+
number: 1111,
777+
messageTemplate: `The library names "{linkedLibraryName1}" and "{linkedLibraryName2}" refer to the same library and were given as two separate library links. Remove one of them and review your library links before proceeding.`,
778+
websiteTitle: "Reference to same library",
779+
websiteDescription: "Reference to same library",
780+
},
781+
MISSING_LINK_FOR_LIBRARY: {
782+
number: 1112,
783+
messageTemplate: `The contract "{contractName}" is missing links for the following libraries: "{missingLibraries}". Learn more about linking contracts at (https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-ethers#library-linking).`,
784+
websiteTitle: "Missing links for library",
785+
websiteDescription: "Missing links for library",
786+
},
787+
UNSUPPORTED_TYPE_FOR_DEEP_COPY: {
788+
number: 1113,
789+
messageTemplate: `The value "{value}" with type "{type}" is not supported by the deepCopy function.`,
790+
websiteTitle: "Unsupported type for deep copy",
791+
websiteDescription: "Unsupported type for deep copy",
792+
},
793+
},
701794
} as const;

v-next/hardhat-ethers/.eslintrc.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createConfig } = require("../../config-v-next/eslint.cjs");
2+
3+
module.exports = createConfig(__filename);

v-next/hardhat-ethers/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node modules
2+
/node_modules
3+
4+
# Compilation output
5+
/dist

v-next/hardhat-ethers/.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/dist
3+
/coverage
4+
CHANGELOG.md

v-next/hardhat-ethers/LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Nomic Foundation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

v-next/hardhat-ethers/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# hardhat-ethers
2+
3+
[Hardhat](https://hardhat.org) plugin for integration with [ethers.js](https://github.com/ethers-io/ethers.js/).
4+
5+
### Usage
6+
7+
```ts
8+
const { ethers } = await hre.network.connect();
9+
10+
// ethers functionalities
11+
ethers.isAddress("0x1234567890123456789012345678901234567890");
12+
13+
// ethers.Provider
14+
await ethers.provider.getBlockNumber();
15+
16+
// Hardhat helper methods
17+
await ethers.getSigners();
18+
```
19+
20+
### Tests
21+
22+
Temporary solution to run manual tests until the V3 node is ready.
23+
24+
1. Start a node in Hardhat V2: `npx hardhat node`
25+
2. Run the tests: `pnpm test:tmp`

v-next/hardhat-ethers/package.json

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "@ignored/hardhat-vnext-ethers",
3+
"version": "3.0.0-next.2",
4+
"description": "Hardhat plugin for ethers",
5+
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-ethers",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/NomicFoundation/hardhat",
9+
"directory": "v-next/ethers"
10+
},
11+
"author": "Nomic Foundation",
12+
"license": "MIT",
13+
"type": "module",
14+
"exports": {
15+
".": "./dist/src/index.js",
16+
"./types": "./dist/src/types.js"
17+
},
18+
"keywords": [
19+
"ethereum",
20+
"smart-contracts",
21+
"hardhat",
22+
"ethers.js"
23+
],
24+
"scripts": {
25+
"lint": "pnpm prettier --check && pnpm eslint",
26+
"lint:fix": "pnpm prettier --write && pnpm eslint --fix",
27+
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
28+
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
29+
"test": "node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
30+
"test:tmp": "node --import tsx/esm ./run-tests.ts",
31+
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
32+
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude src/internal/types.ts --exclude src/internal/ui/direct-user-interruption-manager.ts --src src node --import tsx/esm --test --test-reporter=@ignored/hardhat-vnext-node-test-reporter \"test/!(fixture-projects|helpers)/**/*.ts\"",
33+
"pretest": "pnpm build",
34+
"pretest:only": "pnpm build",
35+
"build": "tsc --build .",
36+
"prepublishOnly": "pnpm build",
37+
"clean": "rimraf dist"
38+
},
39+
"files": [
40+
"dist/src/",
41+
"src/",
42+
"CHANGELOG.md",
43+
"LICENSE",
44+
"README.md"
45+
],
46+
"devDependencies": {
47+
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
48+
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
49+
"@nomicfoundation/hardhat-test-utils": "workspace:^",
50+
"@types/debug": "^4.1.4",
51+
"@types/node": "^20.14.9",
52+
"@typescript-eslint/eslint-plugin": "^7.7.1",
53+
"@typescript-eslint/parser": "^7.7.1",
54+
"c8": "^9.1.0",
55+
"eslint": "8.57.0",
56+
"eslint-config-prettier": "9.1.0",
57+
"eslint-import-resolver-typescript": "^3.6.1",
58+
"eslint-plugin-import": "2.29.1",
59+
"eslint-plugin-no-only-tests": "3.1.0",
60+
"expect-type": "^0.19.0",
61+
"prettier": "3.2.5",
62+
"rimraf": "^5.0.5",
63+
"tsx": "^4.11.0",
64+
"typescript": "~5.5.0",
65+
"typescript-eslint": "7.7.1"
66+
},
67+
"dependencies": {
68+
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
69+
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
70+
"debug": "^4.1.1",
71+
"ethers": "^6.13.2"
72+
},
73+
"peerDependencies": {
74+
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.2"
75+
}
76+
}

0 commit comments

Comments
 (0)