Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hardhat Ignition to hardhat-toolbox #4655

Merged
merged 41 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ba67202
Upgrade the viem toolbox and project creation to viem@2
schaable Feb 15, 2024
6f0e3f8
update sample projects to use ignition
zoeyTM Dec 7, 2023
d953a0d
refactor: tweaks for ethers support
kanej Dec 15, 2023
7267bf8
chore: bump chai version in toolbox
kanej Feb 13, 2024
94426aa
Update verification guide to use ignition (#4833)
zoeyTM Feb 13, 2024
eddc2dd
Update scripts guide (#4853)
zoeyTM Feb 14, 2024
f16b22a
chore: exclude next dir from linting check
kanej Feb 16, 2024
bd31eda
chore: tweak the changeset
kanej Feb 16, 2024
2895315
fix errors + improve tutorial docs (missing boilerplate step)
ChristopherDedominici Feb 20, 2024
62b873a
refactor: switch convention for Module file names
kanej Feb 20, 2024
5697002
test: fix broken viem sample project test
kanej Feb 20, 2024
a975a47
error fix: re-add RECOMMENDED_SOLC_VERSION in docs
ChristopherDedominici Feb 20, 2024
65770b2
revert using Ignition in test in sample projects
kanej Feb 22, 2024
93c269f
make typescript sample project tests use explicit `hre.ethers`
kanej Feb 22, 2024
4e0d856
add default unlockTime to sample projects
kanej Feb 22, 2024
a6ed97c
revert scripts change in forking-other-networks
kanej Feb 22, 2024
b057182
revert scripts change in building plugins
kanej Feb 22, 2024
3168356
update the scripts guide intro
kanej Feb 22, 2024
8661dd9
revert scripts removal from hardhat console
kanej Feb 22, 2024
92724da
revert removal of script refs in typescript.md
kanej Feb 22, 2024
cc1aea4
revert contract testing guide
kanej Feb 22, 2024
13cb179
revert testing-contracts in tutorial
kanej Feb 22, 2024
2116e3f
improve tip on verifying
kanej Feb 23, 2024
0ea9d86
Add redirect for removed tasks-and-scripts file
kanej Feb 23, 2024
a1f762b
test: update viem sample with new viem2 api
kanej Feb 23, 2024
d1b0660
chore: bump the project creation version
kanej Feb 23, 2024
50c7fe3
Update peer dependencies in project-creation.ts
schaable Feb 23, 2024
c28a266
Fix code snippets in Testing contracts guide
schaable Feb 23, 2024
94c2fdf
bump the version of hardhat-ignition-ethers to the latest
kanej Feb 23, 2024
b941f02
Fix code snippets in Verifying your contracts
schaable Feb 23, 2024
04be75e
Update docs/src/content/hardhat-runner/docs/guides/verifying.md
kanej Feb 26, 2024
7b21e3a
chore: update the pnpm lock file
kanej Feb 26, 2024
502d6e7
docs: clarify module file in deploying guide
kanej Feb 26, 2024
8f141f0
docs: revert the change to project setup
kanej Feb 26, 2024
48fc9b0
update boilerplate docs
ChristopherDedominici Feb 26, 2024
e029eaf
remove ignition-core as peer dep
kanej Feb 27, 2024
1822c2b
Add default tab for new combination
schaable Mar 5, 2024
ce8f48b
chore: bump the version of Ignition in toolboxes
kanej Mar 11, 2024
67fa3e0
chore: loosen typescript peer dep for viem toolbox
kanej Mar 11, 2024
cc90bbc
test: fix assert.isDefined issue
kanej Mar 14, 2024
26720f8
chore: bump edr version to 0.3.1
kanej Mar 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cyan-ligers-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"hardhat": patch
"@nomicfoundation/hardhat-toolbox": major
"@nomicfoundation/hardhat-toolbox-viem": major
---

Include Hardhat Ignition in the toolboxes.
6 changes: 6 additions & 0 deletions .changeset/silver-waves-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@nomicfoundation/hardhat-toolbox-viem": major
"hardhat": patch
---

Upgraded hardhat-toolbox-viem and project creation to support viem@2
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs/.next
5 changes: 5 additions & 0 deletions docs/redirects.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ const customRedirects = [
destination: "/hardhat-runner/docs/guides/command-line-completion",
permanent: false,
},
{
source: "/hardhat-runner/docs/guides/tasks-and-scripts",
destination: "/hardhat-runner/docs/guides/tasks",
permanent: false,
},
// guides redirects, exceptions go first
{
source:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/hardhat-network/docs/overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ When Hardhat executes your tests, scripts or tasks, an in-process Hardhat Networ

There's no need to make any changes to your tests or scripts.

Hardhat Network is simply another network. If you wanted to be explicit, you could run, for example, `npx hardhat run --network hardhat scripts/my-script.js`.
Hardhat Network is simply another network. If you wanted to be explicit, you could run, for example, `npx hardhat ignition deploy ./ignition/modules/MyModule.ts --network hardhat`.

### Running stand-alone in order to support wallets and other software

Alternatively, Hardhat Network can run in a stand-alone fashion so that external clients can connect to it. This could be a wallet, your Dapp front-end, or a script. To run Hardhat Network in this way, run:
Alternatively, Hardhat Network can run in a stand-alone fashion so that external clients can connect to it. This could be a wallet, your Dapp front-end, or a Hardhat Ignition deployment. To run Hardhat Network in this way, run:

```
$ npx hardhat node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Some examples of things you could achieve by creating a plugin are: running a li

## Extending the Hardhat Runtime Environment

Let’s go through the process of creating a plugin that adds new functionality to the Hardhat Runtime Environment. By doing this, we make sure our new feature is available everywhere. This means your plugin users can access it from tasks, tests, scripts, and the Hardhat console.
Let’s go through the process of creating a plugin that adds new functionality to the Hardhat Runtime Environment. By doing this, we make sure our new feature is available everywhere. This means your plugin users can access it from tasks, tests, scripts and the Hardhat console.

The Hardhat Runtime Environment (HRE) is configured through a queue of extension functions that you can add to using the `extendEnvironment()` function. It receives one parameter which is a callback which will be executed after the HRE is initialized. If `extendEnvironment` is called multiple times, its callbacks will be executed in order.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ Follow these steps to migrate your project to Hardhat Toolbox.
:::tab{value="npm 6"}

```
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomicfoundation/hardhat-ethers @nomicfoundation/hardhat-verify chai@4 ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v6
npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomicfoundation/hardhat-ethers @nomicfoundation/hardhat-verify chai@4 ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v6
kanej marked this conversation as resolved.
Show resolved Hide resolved
```

:::

:::tab{value="yarn"}

```
yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers@1 @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai@4 ethers@5 hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v6
yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-ignition-ethers @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers@1 @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai@4 ethers@5 hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v6
```

:::
Expand Down Expand Up @@ -98,6 +98,8 @@ Follow these steps to migrate your project to Hardhat Toolbox.

- `@nomicfoundation/hardhat-ethers`
- `@nomicfoundation/hardhat-verify`
- `@nomicfoundation/hardhat-ignition`
- `@nomicfoundation/hardhat-ignition-ethers`
kanej marked this conversation as resolved.
Show resolved Hide resolved
- `hardhat-gas-reporter`
- `solidity-coverage`
- `@typechain/hardhat`
Expand Down
48 changes: 18 additions & 30 deletions docs/src/content/hardhat-runner/docs/advanced/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In this guide we will go through the steps of creating a script with Hardhat. For a general overview of using Hardhat refer to the [Getting started guide](../getting-started/index.md).

You can write your own custom scripts that can use all of Hardhat's functionality. A classic use case is writing a deployment script for your smart contracts.
You can write your own custom scripts that can use all of Hardhat's functionality; for example, in this guide, we will work through scripts that print the list of available accounts.

There are two ways of writing a script that accesses the [Hardhat Runtime Environment](../advanced/hardhat-runtime-environment.md).

Expand All @@ -24,44 +24,32 @@ const hre = require("hardhat");

You can get access to all your tasks and plugins. To run these scripts you simply go through node: `node script.js`.

To try this out, let's look at [a fresh Hardhat project](../guides/project-setup.md). Run `npx hardhat init` and go through the steps to create a JavaScript project. When you're done, your project directory should look like this:
To try this out, create a new directory called `scripts` in your project's root directory. Then, inside that directory, create a file called `accounts.js` with the following content:

```
$ ls -l
total 400
drwxr-xr-x 3 fzeoli staff 96 Jul 30 15:27 contracts
-rw-r--r-- 1 fzeoli staff 195 Jul 30 15:27 hardhat.config.js
drwxr-xr-x 502 fzeoli staff 16064 Jul 30 15:31 node_modules
-rw-r--r-- 1 fzeoli staff 194953 Jul 30 15:31 package-lock.json
-rw-r--r-- 1 fzeoli staff 365 Jul 30 15:31 package.json
drwxr-xr-x 3 fzeoli staff 96 Jul 30 15:27 scripts
drwxr-xr-x 3 fzeoli staff 96 Jul 30 15:27 test
```

Inside `scripts/` you will find `deploy.js`. Read through its comments to have a better idea of what it does.
```js
const hre = require("hardhat");

<<< @/../packages/hardhat-core/sample-projects/javascript/scripts/deploy.js
async function main() {
const accounts = await hre.ethers.getSigners();

Now run the script:
for (const account of accounts) {
console.log(account.address);
}
}

```
$ node scripts/deploy.js
Lock with 1 ETH deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
```

By accessing the [Hardhat Runtime Environment](../advanced/hardhat-runtime-environment.md) at the top, you are allowed to run the script in a standalone fashion.

Hardhat always runs the compile task when it's invoked via `npx hardhat run`, but in a standalone fashion you may want to call compile manually to make sure everything is compiled. This can be done by calling `hre.run("compile")`. Add the following line at the beginning of the `main` function and re-run the script with node:
Now run the script:

```js
await hre.run("compile");
```sh
node scripts/accounts.js
```

```
$ node scripts/deploy.js
Nothing to compile
Lock with 1 ETH deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
```
By accessing the [Hardhat Runtime Environment](../advanced/hardhat-runtime-environment.md) at the top, you are allowed to run the script in a standalone fashion.

### Hardhat arguments

Expand Down
76 changes: 53 additions & 23 deletions docs/src/content/hardhat-runner/docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If you are using Windows, we **strongly recommend** using [WSL 2](https://docs.m

:::

We will explore the basics of creating a Hardhat project with a sample contract, tests of that contract, and a script to deploy it.
We will explore the basics of creating a Hardhat project with a sample contract, tests of that contract, and a Hardhat Ignition module to deploy it.

To create the sample project, run `npx hardhat init` in your project folder:

Expand Down Expand Up @@ -151,7 +151,7 @@ If you created a TypeScript project, this task will also generate TypeScript bin

### Testing your contracts

Your project comes with tests that use [Mocha](https://mochajs.org), [Chai](https://www.chaijs.com), and [Ethers.js](https://docs.ethers.org/v6/).
Your project comes with tests that use [Mocha](https://mochajs.org), [Chai](https://www.chaijs.com), [Ethers.js](https://docs.ethers.org/v6/) and [Hardhat Ignition](/ignition).

If you take a look in the `test/` folder, you'll see a test file:

Expand Down Expand Up @@ -239,59 +239,89 @@ Compiled 2 Solidity files successfully

### Deploying your contracts

:::tip

Try [Hardhat Ignition](/ignition) for your deployments! Our new declarative system for deploying smart contracts without getting caught up in execution details.

:::

Next, to deploy the contract we will use a Hardhat script.
Next, to deploy the contract we will use a Hardhat Ignition module.

Inside the `scripts/` folder you will find a file with the following code:
Inside the `ignition/modules` folder you will find a file with the following code:

::::tabsgroup{options="TypeScript,JavaScript"}

:::tab{value="TypeScript"}

<<< @/../packages/hardhat-core/sample-projects/typescript/scripts/deploy.ts
<<< @/../packages/hardhat-core/sample-projects/typescript/ignition/modules/Lock.ts

:::

:::tab{value="JavaScript"}

<<< @/../packages/hardhat-core/sample-projects/javascript/scripts/deploy.js
<<< @/../packages/hardhat-core/sample-projects/javascript/ignition/modules/Lock.js

:::

::::

You can run it using `npx hardhat run`:

::::tabsgroup{options="TypeScript,JavaScript"}

:::tab{value="TypeScript"}

You can deploy it using `npx hardhat ignition deploy ./ignition/modules/Lock.ts`:

```
$ npx hardhat run scripts/deploy.ts
Lock with 0.001ETH deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
$ npx hardhat ignition deploy ./ignition/modules/Lock.ts
Compiled 1 Solidity file successfully (evm target: paris).
You are running Hardhat Ignition against an in-process instance of Hardhat Network.
This will execute the deployment, but the results will be lost.
You can use --network <network-name> to deploy to a different network.

Hardhat Ignition 🚀

Deploying [ LockModule ]

Batch #1
Executed LockModule#Lock

[ LockModule ] successfully deployed 🚀

Deployed Addresses

LockModule#Lock - 0x5FbDB2315678afecb367f032d93F642f64180aa3
```

:::

:::tab{value="JavaScript"}

You can deploy it using `npx hardhat ignition deploy ./ignition/modules/Lock.js`:

```
$ npx hardhat run scripts/deploy.js
Lock with 0.001ETH deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
$ npx hardhat ignition deploy ./ignition/modules/Lock.js
Compiled 1 Solidity file successfully (evm target: paris).
You are running Hardhat Ignition against an in-process instance of Hardhat Network.
This will execute the deployment, but the results will be lost.
You can use --network <network-name> to deploy to a different network.

Hardhat Ignition 🚀

Deploying [ LockModule ]

Batch #1
Executed LockModule#Lock

[ LockModule ] successfully deployed 🚀

Deployed Addresses

LockModule#Lock - 0x5FbDB2315678afecb367f032d93F642f64180aa3
```

:::

::::

To learn more check out the [Hardhat Ignition documentation](/ignition).

### Connecting a wallet or Dapp to Hardhat Network

By default, Hardhat will spin up a new in-memory instance of Hardhat Network on startup. It's also possible to run Hardhat Network in a standalone fashion so that external clients can connect to it. This could be a wallet, your Dapp front-end, or a script.
By default, Hardhat will spin up a new in-memory instance of Hardhat Network on startup. It's also possible to run Hardhat Network in a standalone fashion so that external clients can connect to it. This could be a wallet, your Dapp front-end, or a Hardhat Ignition deployment.

To run Hardhat Network in this way, run `npx hardhat node`:

Expand All @@ -302,24 +332,24 @@ Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

This will expose a JSON-RPC interface to Hardhat Network. To use it connect your wallet or application to `http://127.0.0.1:8545`.

If you want to connect Hardhat to this node, for example to run a deployment script against it, you simply need to run it using `--network localhost`.
If you want to connect Hardhat to this node, for example to run a deployment against it, you simply need to run it using `--network localhost`.

To try this, start a node with `npx hardhat node` and re-run the deployment script using the `network` option:
To try this, start a node with `npx hardhat node` and re-run the deployment using the `network` option:

::::tabsgroup{options="TypeScript,JavaScript"}

:::tab{value="TypeScript"}

```
npx hardhat run scripts/deploy.ts --network localhost
npx hardhat ignition deploy ./ignition/modules/Lock.ts --network localhost
```

:::

:::tab{value="JavaScript"}

```
npx hardhat run scripts/deploy.js --network localhost
npx hardhat ignition deploy ./ignition/modules/Lock.js --network localhost
```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/hardhat-runner/docs/guides/_dirinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ order:
- /test-contracts
- /deploying
- /verifying
- /tasks-and-scripts
kanej marked this conversation as resolved.
Show resolved Hide resolved
- /tasks
- /hardhat-console
- /typescript
- /command-line-completion
Expand Down
26 changes: 14 additions & 12 deletions docs/src/content/hardhat-runner/docs/guides/deploying.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# Deploying your contracts

:::tip
To deploy your contracts, you can use [Hardhat Ignition](/ignition), our declarative deployment system. You can deploy the `Lock` contract from the sample project by using its accompanying Ignition module. An Ignition module is a TypeScript or JavaScript file that allows you to specify what needs to be deployed.

Try [Hardhat Ignition](/ignition) for your deployments! Our new declarative system for deploying smart contracts without getting caught up in execution details.

:::

When it comes to deploying, you can use a deployment system like [Hardhat Ignition](/ignition) or you can deploy your smart contracts using scripts. You can deploy the `Lock` contract from the sample project with a deployment script like this:
In the sample project, the Ignition module `LockModule` which deploys the `Lock` contract, is under the `./ignition/modules` directory and looks like this:

::::tabsgroup{options="TypeScript,JavaScript"}

:::tab{value="TypeScript"}

<<< @/../packages/hardhat-core/sample-projects/typescript/scripts/deploy.ts
<<< @/../packages/hardhat-core/sample-projects/typescript/ignition/modules/Lock.ts

:::

:::tab{value="JavaScript"}

<<< @/../packages/hardhat-core/sample-projects/javascript/scripts/deploy.js
<<< @/../packages/hardhat-core/sample-projects/javascript/ignition/modules/Lock.js

:::

Expand All @@ -32,22 +28,22 @@ You can deploy in the `localhost` network following these steps:
npx hardhat node
```

2. Open a new terminal and deploy the smart contract in the `localhost` network
2. Open a new terminal and deploy the Hardhat Ignition module in the `localhost` network

::::tabsgroup{options="TypeScript,JavaScript"}

:::tab{value="TypeScript"}

```
npx hardhat run --network localhost scripts/deploy.ts
npx hardhat ignition deploy ./ignition/modules/Lock.ts --network localhost
```

:::

:::tab{value="JavaScript"}

```
npx hardhat run --network localhost scripts/deploy.js
npx hardhat ignition deploy ./ignition/modules/Lock.js --network localhost
```

:::
Expand All @@ -57,5 +53,11 @@ You can deploy in the `localhost` network following these steps:
As general rule, you can target any network from your Hardhat config using:

```
npx hardhat run --network <your-network> scripts/deploy.js
npx hardhat ignition deploy ./ignition/modules/Lock.js --network <your-network>
```

If no network is specified, Hardhat Ignition will run against an in-memory instance of Hardhat Network.

In the sample `LockModule` above, two module parameters are used: `unlockTime` which will default to the 1st of Jan 2030 and `lockedAmount` which will default to one Gwei. You can learn more about overriding these values by providing your own module parameters during deployment in our [Deploying a module](/ignition/docs/guides/deploy#defining-parameters-during-deployment) guide.

Read more about Hardhat Ignition generally in the [Hardhat Ignition documentation](/ignition).
4 changes: 2 additions & 2 deletions docs/src/content/hardhat-runner/docs/guides/project-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ The initialized project has the following structure:

```
contracts/
scripts/
ignition/modules/
test/
hardhat.config.js
```

These are the default paths for a Hardhat project.

- `contracts/` is where the source files for your contracts should be.
- `ignition/modules/` is where the Ignition modules that handle contract deployments should be.
- `test/` is where your tests should go.
- `scripts/` is where simple automation scripts go.

If you need to change these paths, take a look at the [paths configuration section](../config/index.md#path-configuration).

Expand Down
Loading
Loading