Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22, 24]
steps:
- uses: actions/checkout@v5
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build
run: pnpm build
- name: Test
run: pnpm test
- name: Lint
run: pnpm lint
16 changes: 0 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
# Node modules
/node_modules

# Compilation output
/dist

# pnpm deploy output
/bundle

# test coverage output
coverage

# all the tmp folders in the fixture projects
/test/fixture-projects/tmp/

# Hardhat project files
/artifacts
/cache
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# Hardhat 3 plugin template

This repository is a template for creating a Hardhat 3 plugin.

## Getting started

> This repository is structured as a pnpm monorepo, so make sure you have [`pnpm`](https://pnpm.io/) installed first

To get started, clone the repository and run:

```sh
pnpm install
pnpm build
```

This will install all the dependencies and build the plugin.

You can now run the tests of the plugin with:

```sh
pnpm test
```

And try the plugin out in `packages/example-project` with:

```sh
cd packages/example-project
pnpm hardhat my-task
```

which should print `Hola, Hardhat!`.

## Understanding the repository structure

### Monorepo structure

This repository is structured as a pnpm monorepo with the following packages:

- `packages/plugin`: The plugin itself.
- `packages/example-project`: An example Hardhat 3 project that uses the plugin.

All the development will happen in the `packages/plugin` directory, while `packages/example-project` is a playground to experiment with your plugin, and manually test it.

### Github Actions setup

This repository is setup with a Github Actions workflow. You don't need to do anything to set it up, it runs your on every push to `main`, on pull requests, and when manual triggered.

The workflow is equivalent to running this steps in the root of the repository:

```sh
pnpm install
pnpm build
pnpm test
pnpm lint
```

It runs using Node.js versions 22 and 24, on an `ubuntu-latest` runner.

## Development tips

- We recommend leaving a terminal with `pnpm watch` running in the root of the repository. That way, things will normally be rebuilt by the time you try them out in `packages/example-project`.
5 changes: 0 additions & 5 deletions TODO.md

This file was deleted.

61 changes: 8 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,12 @@
{
"name": "hardhat-plugin-template",
"version": "1.0.0",
"description": "Hardhat 3 plugin template",
"license": "MIT",
"type": "module",
"types": "dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js"
},
"keywords": [
"ethereum",
"smart-contracts",
"hardhat",
"hardhat3",
"hardhat-plugin"
],
"name": "hardhat3-plugin-template",
"private": true,
"scripts": {
"lint": "pnpm prettier --check && pnpm eslint",
"lint:fix": "pnpm prettier --write && pnpm eslint --fix",
"eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier": "prettier \"**/*.{ts,js,md,json}\"",
"test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude \"src/**/{types,type-extensions}.ts\" --src src node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
"pretest": "pnpm build",
"pretest:only": "pnpm build",
"build": "tsc --build .",
"prepublishOnly": "pnpm build",
"clean": "rimraf dist"
},
"files": [
"dist/src/",
"src/",
"CHANGELOG.md",
"LICENSE",
"README.md"
],
"devDependencies": {
"@eslint/js": "^9.35.0",
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0",
"@tsconfig/node22": "^22.0.2",
"@types/node": "^20.14.9",
"c8": "^9.1.0",
"eslint": "^9.35.0",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-import": "^2.32.0",
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"tsx": "^4.19.3",
"typescript": "~5.8.0",
"typescript-eslint": "^8.43.0"
},
"peerDependencies": {
"hardhat": "^3.0.6"
"build": "pnpm --recursive build",
"clean": "pnpm --recursive clean",
"lint": "pnpm --recursive lint",
"lint:fix": "pnpm --recursive lint:fix",
"test": "pnpm --recursive test",
"watch": "pnpm --filter ./packages/plugin watch"
}
}
12 changes: 12 additions & 0 deletions packages/example-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Node modules
/node_modules

# Compilation output
/dist

# test coverage output
/coverage

# Hardhat files
/artifacts
/cache
38 changes: 38 additions & 0 deletions packages/example-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# A Hardhat 3 project that uses your plugin

This is an example project that uses your plugin.

## Getting started

To run this project, you need to install the dependencies and build the plugin:

```sh
pnpm install
pnpm build
```

Then, you can run hardhat with:

```sh
pnpm hardhat my-task
```

You can also run an example script with:

```sh
pnpm hardhat run scripts/example-script.ts
```

And the project's solidity tests with:

```sh
pnpm hardhat test
```

## What's inside the project?

This project is similar to what you get when initializing a Hardhat 3 project with `npx hardhat --init`, but without any of the Hardhat toolboxes.

This means that you don't have `ethers,` `viem`, `mocha`, nor the Node.js test runner plugins.

Please install whichever dependency or plugin you need in here. This package won't be published, so you have complete freedom to do whatever you want.
19 changes: 19 additions & 0 deletions packages/example-project/contracts/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Counter {
uint public x;

event Increment(uint by);

function inc() public {
x++;
emit Increment(1);
}

function incBy(uint by) public {
require(by > 0, "incBy: increment should be positive");
x += by;
emit Increment(by);
}
}
32 changes: 32 additions & 0 deletions packages/example-project/contracts/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import {Counter} from "./Counter.sol";
import {Test} from "forge-std/Test.sol";

contract CounterTest is Test {
Counter counter;

function setUp() public {
counter = new Counter();
}

function test_InitialValue() public view {
require(counter.x() == 0, "Initial value should be 0");
}

function testFuzz_Inc(uint8 x) public {
for (uint8 i = 0; i < x; i++) {
counter.inc();
}
require(
counter.x() == x,
"Value after calling inc x times should be x"
);
}

function test_IncByZero() public {
vm.expectRevert();
counter.incBy(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { HardhatUserConfig } from "hardhat/config";
import myPlugin from "./src/index.js";
import myPlugin from "hardhat-plugin-template";

export default {
plugins: [myPlugin],
solidity: "0.8.29",
myConfig: {
greeting: "Hola",
},
} satisfies HardhatUserConfig;
18 changes: 18 additions & 0 deletions packages/example-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "example-project",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsc --build",
"watch": "tsc --build . --watch"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/node": "^22.11.0",
"hardhat": "^3.0.6",
"hardhat-plugin-template": "workspace:*",
"typescript": "~5.8.0",
"forge-std": "github:foundry-rs/forge-std#v1.9.4"
}
}
17 changes: 17 additions & 0 deletions packages/example-project/scripts/example-script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { network } from "hardhat";

console.log("Running example script");
const { provider } = await network.connect();

const accounts = await provider.send("eth_accounts", []);

console.log("Accounts:", accounts);

console.log(`Sending 1wei from ${accounts[0]} to ${accounts[1]}...`);

const tx = await provider.request({
method: "eth_sendTransaction",
params: [{ from: accounts[0], to: accounts[1], value: "0x1" }],
});

console.log(`Successfully sent transaction with hash ${tx}`);
1 change: 1 addition & 0 deletions tsconfig.json → packages/example-project/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sourceMap": true,
"composite": true,
"incremental": true,
"isolatedModules": true,
"typeRoots": ["${configDir}/node_modules/@types"]
},
"exclude": ["${configDir}/dist", "${configDir}/node_modules"]
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Node modules
/node_modules

# Compilation output
/dist

# test coverage output
/coverage

# Hardhat files
/artifacts
/cache
File renamed without changes.
File renamed without changes.
Loading