Skip to content

Commit ea2ac8f

Browse files
committed
Initial commit
0 parents  commit ea2ac8f

18 files changed

+4174
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_style = space
8+
indent_size = 2
9+
insert_final_newline = true
10+
trim_trailing_whitespace = false

.gitignore

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/dist
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# next.js build output
60+
.next
61+
62+
# environment variables
63+
.env

.mocharc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": "ts-node/register/files",
3+
"ignore": ["test/fixture-projects/**/*"],
4+
"timeout": 6000
5+
}

.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
3+
node_js:
4+
- "8"
5+
- "10"
6+
- "11"
7+
8+
install:
9+
- npm ci
10+
11+
script:
12+
- npm run test
13+
- npm run lint
14+
15+
cache: npm
16+
17+
branches:
18+
only:
19+
- master

LICENSE

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

MIGRATION.md

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Buidler to Hardhat plugin migration guide
2+
3+
This is a short guide explaining how to turn a Buidler plugin into a Hardhat one.
4+
5+
## Updating its dependencies
6+
7+
### Core package
8+
9+
References to the `@nomiclabs/buidler` package should be replaced with the `hardhat` package in your `package.json`, and your `import`s or `require`s.
10+
11+
For example, you would import the `extendEnvironment` function this way:
12+
13+
```typescript
14+
import { extendEnvironment } from "hardhat/config";
15+
```
16+
17+
### Plugins
18+
19+
Similarly, references to buidler plugins should be replaced with their corresponding hardhat plugins.
20+
For example, `@nomiclabs/buidler-ethers` would be `@nomiclabs/hardhat-ethers`.
21+
22+
## Adapting your plugin's source code
23+
24+
The first change you need to make, is to stop exporting a function in your plugin's `index.ts`. Place your function's body at the top-level of your `index.ts` file.
25+
26+
Then, replace all types or imported names that include `Buidler` with `Hardhat` in your plugin source code.
27+
28+
For example, the `BuidlerRuntimeEnvironment` should be replaced with the `HardhatRuntimeEnvironment`. We suggest using `hre` instead of `bre` as its variable name.
29+
30+
### Artifacts
31+
32+
The `readArtifact` and `readArtifactSync` functions were moved to the `HardhatRuntimeEnvironment` so you must replace their uses like this:
33+
34+
```js
35+
const tokenArtifact = await hre.artifacts.readArtifact("Token");
36+
```
37+
38+
The artifact format is now supplemented with build information and debug artifacts in Hardhat which allows you to read things like contract symbols. See the [documentation](https://hardhat.org/docs/artifacts) for more information.
39+
40+
## Updating your plugin's tests
41+
42+
Apart from updating types and names, fixture projects need their `buidler.config.js` renamed to `hardhat.config.js`.
43+
44+
### Changes needed to your test projects' config
45+
46+
The compiler configuration is now expected in the `solidity` field instead of `solc`. Note that Hardhat projects allow multiple solidity versions in its compilation pipeline. For more information see its [documentation](https://hardhat.org/docs/compilation).
47+
48+
Besides that, the compiler settings now go inside a `settings` field. For example, a configuration like this:
49+
50+
```
51+
module.exports = {
52+
solc: {
53+
version: "0.7.2"
54+
optimizer: {
55+
enabled: true,
56+
runs: 200
57+
}
58+
}
59+
}
60+
```
61+
62+
needs to be replaced with this:
63+
64+
```js
65+
module.exports = {
66+
solidity: {
67+
version: "0.7.2"
68+
settings: {
69+
optimizer: {
70+
enabled: true,
71+
runs: 200
72+
}
73+
}
74+
}
75+
}
76+
```
77+
78+
## Adapting your type extensions
79+
80+
Hardhat introduced a few changes in how type extensions are created and used.
81+
82+
These are the necessary changes to update your plugin.
83+
84+
First, you need rename your `src/type-extenstions.d.ts` file to `src/type-extensions.ts`.
85+
86+
Then, you need to add an `import "./type-extensions";` in your `src/index.ts` file, or the main entrypoint to your plugin as defined in your `package.json`.
87+
88+
### Extending Hardhat types
89+
90+
Hardhat types are meant to be imported from `hardhat/types`, but when extending them,
91+
you should import them from the module that declares them.
92+
93+
For example, if you want you use the `HardhatRuntimeEnvironment` type, you should import it with:
94+
95+
```typescript
96+
import { HardhatRuntimeEnvironment } from "hardhat/types";
97+
```
98+
99+
But if you want to extend it, you should import the module that declares it
100+
instead, which is `hardhat/types/runtime`.
101+
102+
```typescript
103+
import "hardhat/types/runtime";
104+
105+
declare module "hardhat/types/runtime" {
106+
export interface HardhatRuntimeEnvironment {
107+
newField: number;
108+
}
109+
}
110+
```
111+
112+
### Adapting your config extensions
113+
114+
Config types are handled slightly differently in Hardhat.
115+
116+
For each config element/type, there's two Typescript types defined. One
117+
that ends with `UserConfig`, that represents the user's input, and another
118+
one that ends with just `Config`, which represents the configuration values
119+
after any resolution and default values have been applied. The first kind of
120+
types is used by users when writing their config. The second one is used
121+
during the execution of tasks, tests and scripts, and is present in the
122+
Hardhat Runtime Environment.
123+
124+
For example, `HardhatUserConfig` represents the entire config written by the
125+
user, and all of its fields are optional. `HardhatConfig`, is the result
126+
of resolving/normalizing it, and applying default values. None of its fields
127+
are optional.
128+
129+
Some types have been renamed to match this new pattern:
130+
131+
- `ProjectPaths` is now `ProjectPathsUserConfig`
132+
- `Networks` is now `NetworksUserConfig`
133+
- Both have their resolved versions: `ProjectPathsConfig` and
134+
`NetworksConfig`, respectively.
135+
136+
You can find an example of how to properly extend these types,
137+
resolve/normalize the users's config, and apply default values in the
138+
`src/type-extensions.ts` and `src/index.ts` files.
139+
140+
### How type extensions are loaded in Hardhat
141+
142+
Previously, type extensions were loaded by plugin users by adding references to a plugin-owned `type-extensions.d.ts` in their `tsconfig.json`.
143+
144+
Now, they're loaded automatically when importing the plugin in a hardhat config file. For example:
145+
146+
```typescript
147+
import "@nomiclabs/hardhat-ethers"
148+
```
149+
150+
This is enough to import the type extensions included in the `@nomiclabs/hardhat-ethers` plugin.
151+
152+
## Adapting your `README.md`
153+
154+
Make sure to update the README to point to the new Hardhat site (https://hardhat.org), and that the Typescript Support section has been updated.

README-TEMPLATE.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# hardhat-example-plugin
2+
3+
_A one line description of the plugin_
4+
5+
[Hardhat](https://hardhat.org) plugin example.
6+
7+
## What
8+
9+
<_A longer, one paragraph, description of the plugin_>
10+
11+
This plugin will help you with world domination by implementing a simple tic-tac-toe in the terminal.
12+
13+
## Installation
14+
15+
<_A step-by-step guide on how to install the plugin_>
16+
17+
```bash
18+
npm install <your npm package name> [list of peer dependencies]
19+
```
20+
21+
Import the plugin in your `hardhat.config.js`:
22+
23+
```js
24+
require("<your plugin npm package name>");
25+
```
26+
27+
Or if you are using TypeScript, in your `hardhat.config.ts`:
28+
29+
```ts
30+
import "<your plugin npm package name>";
31+
```
32+
33+
34+
## Required plugins
35+
36+
<_The list of all the required Hardhat plugins if there are any_>
37+
38+
- [@nomiclabs/hardhat-web3](https://github.com/nomiclabs/hardhat/tree/master/packages/hardhat-web3)
39+
40+
## Tasks
41+
42+
<_A description of each task added by this plugin. If it just overrides internal
43+
tasks, this may not be needed_>
44+
45+
This plugin creates no additional tasks.
46+
47+
<_or_>
48+
49+
This plugin adds the _example_ task to Hardhat:
50+
```
51+
output of `npx hardhat help example`
52+
```
53+
54+
## Environment extensions
55+
56+
<_A description of each extension to the Hardhat Runtime Environment_>
57+
58+
This plugin extends the Hardhat Runtime Environment by adding an `example` field
59+
whose type is `ExampleHardhatRuntimeEnvironmentField`.
60+
61+
## Configuration
62+
63+
<_A description of each extension to the HardhatConfig or to its fields_>
64+
65+
This plugin extends the `HardhatUserConfig`'s `ProjectPathsUserConfig` object with an optional
66+
`newPath` field.
67+
68+
This is an example of how to set it:
69+
70+
```js
71+
module.exports = {
72+
paths: {
73+
newPath: "new-path"
74+
}
75+
};
76+
```
77+
78+
## Usage
79+
80+
<_A description of how to use this plugin. How to use the tasks if there are any, etc._>
81+
82+
There are no additional steps you need to take for this plugin to work.
83+
84+
Install it and access ethers through the Hardhat Runtime Environment anywhere
85+
you need it (tasks, scripts, tests, etc).

0 commit comments

Comments
 (0)