Skip to content

Commit 621a82a

Browse files
authored
Merge pull request #9 from MatiasOS/dev
Release v1.3.0
2 parents e7ac5b0 + 2bd2404 commit 621a82a

6 files changed

Lines changed: 118 additions & 114 deletions

File tree

README.md

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,70 @@
1-
# Hardhat 3 plugin template
1+
# @openscan/hardhat-plugin
22

3-
This repository is a template for creating a Hardhat 3 plugin.
3+
A Hardhat 3 plugin that automatically launches a local [OpenScan Explorer](https://openscan.eth.link) and adds clickable transaction links to your terminal.
44

5-
## Getting started
6-
7-
> This repository is structured as a pnpm monorepo, so make sure you have [`pnpm`](https://pnpm.io/) installed first
8-
9-
To get started, clone the repository and run:
10-
11-
```sh
12-
pnpm install
13-
pnpm build
14-
```
5+
![OpenScan hardhat logs](image.png)
156

16-
This will install all the dependencies and build the plugin.
7+
![OpenScan Call Tree](image-1.png)
178

18-
You can now run the tests of the plugin with:
9+
## Features
1910

20-
```sh
21-
pnpm test
22-
```
11+
- **Local block explorer** — auto-launches on `hardhat node` and opens your browser
12+
- **Clickable terminal links** — transaction hashes, addresses, and blocks are OSC 8 hyperlinks to the explorer
13+
- **Contract deployment tracking** — matches bytecode to artifacts so the explorer shows contract names, ABIs, and source code
14+
- **Works with Hardhat Ignition and raw deploy scripts**
2315

24-
And try the plugin out in `packages/example-project` with:
16+
## Quick Start
2517

26-
```sh
27-
cd packages/example-project
28-
pnpm hardhat node
18+
```bash
19+
npm install --save-dev @openscan/hardhat-plugin
2920
```
3021

31-
This will automatically:
22+
Add the plugin to your `hardhat.config.ts`:
3223

33-
- Launch the OpenScan Explorer webapp on <http://localhost:3030>
34-
- Open your browser to the explorer
35-
- Log transaction links with OpenScan URLs
24+
```ts
25+
import { defineConfig } from "hardhat/config";
26+
import openScanPlugin from "@openscan/hardhat-plugin";
3627

37-
![OpenScan hardhat logs](image.png)
38-
39-
## Understanding the repository structure
40-
41-
### Monorepo structure
42-
43-
This repository is structured as a pnpm monorepo with the following packages:
4428

45-
- `packages/plugin`: The plugin itself.
46-
- `packages/example-project`: An example Hardhat 3 project that uses the plugin.
29+
export default defineConfig({
30+
plugins: [openScanPlugin],
31+
solidity: "0.8.29",
32+
});
33+
```
4734

48-
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.
35+
Start a node:
4936

50-
### Plugin template structure
37+
```bash
38+
npx hardhat node
39+
```
5140

52-
The `packages/plugin` directory has a complete plugin example. It includes:
41+
The OpenScan Explorer will launch at <http://localhost:3030> and your browser will open automatically.
5342

54-
- A `README.md` file that documents the plugin.
55-
- A `src/index.ts` file that defines and exports the plugin.
56-
- A network Hook Handler, which is in `src/hooks/network.ts`, which shows how to define them, and prints OpenScan links.
43+
## Documentation
5744

58-
### Github Actions setup
45+
See the [plugin README](packages/plugin/README.md) for full configuration options, usage examples, and troubleshooting.
5946

60-
This repository is setup with a Github Actions workflow. You don't need to do anything to set it up, it runs on every push to `main`, on pull requests, and when manually triggered.
47+
## Contributing
6148

62-
The workflow is equivalent to running this steps in the root of the repository:
49+
This repository is a pnpm monorepo. Make sure you have [`pnpm`](https://pnpm.io/) installed.
6350

6451
```sh
6552
pnpm install
6653
pnpm build
6754
pnpm test
68-
pnpm lint
6955
```
7056

71-
It runs using Node.js 24, on an `ubuntu-latest` runner.
57+
### Monorepo structure
58+
59+
- `packages/plugin` — the plugin source code
60+
- `packages/example-project` — a Hardhat 3 project for manual testing
61+
62+
Running `pnpm watch` in the root is useful during development — it rebuilds the plugin as you edit, so changes are picked up when you test in `packages/example-project`.
63+
64+
### CI
65+
66+
GitHub Actions runs on every push to `main` and on pull requests: install, build, test, and lint using Node.js 24.
7267

73-
## Development setup
68+
## License
7469

75-
- This repository includes a setup of typescript and eslint, based on the official recommendation of each project, and a a few custom rules that help building Hardhat plugins.
76-
- It also includes `prettier` to format the code, with its default configuration.
77-
- There are npm scripts in the root that should be enough to build, lint, test, etc.
78-
- Running `pnpm watch` can be helpful when using the example project. If you keep a terminal running it, things will normally be rebuilt by the time you try them out in `packages/example-project`.
70+
MIT

image-1.png

599 KB
Loading

packages/example-project/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# A Hardhat 3 project that uses your plugin
1+
# A Hardhat 3 project that uses @openscan/hardhat-plugin
22

3-
This is an example project that uses your plugin.
3+
This is an example project that uses the OpenScan plugin.
44

55
## Getting started
66

@@ -45,10 +45,10 @@ pnpm run deploy
4545
pnpm run send-tx
4646
```
4747

48-
All transactions will be logged with clickable OpenScan links in the console. Check the code is verified
48+
All transactions will be logged with clickable OpenScan links in the console.
4949

5050
## What's inside the project?
5151

52-
This is a minimal Hardhat 3 project that only has the built-in functionality of Hardhat and your plugin.
52+
This is a minimal Hardhat 3 project that only has the built-in functionality of Hardhat and the OpenScan plugin.
5353

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

packages/plugin/README.md

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,124 @@
1-
# `openscan-hardhat-links`
1+
# @openscan/hardhat-plugin
22

3-
A Hardhat plugin that automatically launches the OpenScan Explorer webapp and adds OpenScan links to all transaction logs.
3+
A Hardhat 3 plugin that automatically launches the OpenScan Explorer webapp and adds clickable OpenScan links to transaction logs in your terminal.
44

5-
## Installation
5+
Learn more at <https://openscan.eth.link>
66

7-
To install this plugin, run the following command:
7+
## Installation
88

99
```bash
10-
npm install --save-dev openscan-hardhat-links
10+
npm install --save-dev @openscan/hardhat-plugin
1111
```
1212

13-
In your `hardhat.config.ts` file, import the plugin and add it to the `plugins` array:
13+
## Configuration
14+
15+
In your `hardhat.config.ts`, import the plugin and add it to the `plugins` array:
1416

1517
```ts
18+
import openScanPlugin from "@openscan/hardhat-plugin";
1619
import { defineConfig } from "hardhat/config";
17-
import openScanPlugin from "openscan-hardhat-links";
1820

1921
export default defineConfig({
2022
plugins: [openScanPlugin],
23+
solidity: "0.8.29",
2124
networks: {
22-
...
25+
localhost: {
26+
type: "http",
27+
url: "http://127.0.0.1:8545",
28+
},
2329
},
2430
openScan: {
25-
url: "http://localhost:3030",
26-
chainId: 31337,
31+
url: "http://localhost:3030", // default
32+
chainId: 31337, // default
2733
},
2834
});
29-
3035
```
3136

37+
### Options
38+
39+
| Option | Type | Default | Description |
40+
| --------- | -------- | ------------------------- | -------------------------------- |
41+
| `url` | `string` | `"http://localhost:3030"` | URL where the explorer is served |
42+
| `chainId` | `number` | `31337` | Chain ID for the explorer links |
43+
3244
## Features
3345

34-
This plugin provides two main features:
46+
### Automatic Explorer Launch
47+
48+
When the first network connection is established (e.g. via `npx hardhat node`), the plugin:
3549

36-
1. **Automatic OpenScan Explorer Launch**: When you start the Hardhat node, the plugin automatically:
37-
- Launches a local OpenScan Explorer webapp on port 3030
38-
- Opens your default browser to <http://localhost:3030>
39-
- Serves the explorer from the plugin's built-in webapp
50+
1. Checks if port 3030 is available
51+
2. Starts a local HTTP server serving the OpenScan Explorer webapp
52+
3. Opens your default browser to the explorer
4053

41-
2. **OpenScan Links in Logs**: All transaction-related logs include clickable OpenScan links:
42-
- Transaction hashes → OpenScan transaction view
43-
- Addresses → OpenScan address view
44-
- Blocks → OpenScan block view
45-
- Contract deployments → OpenScan contract view
54+
The explorer serves contract artifacts (ABIs, source code, deployment addresses) so you can inspect deployed contracts directly in the browser. It supports both Hardhat Ignition deployments and raw deployment scripts.
55+
56+
### Clickable Transaction Links
57+
58+
The plugin intercepts JSON-RPC requests and logs clickable terminal links (via OSC 8 hyperlinks) for:
59+
60+
- **`eth_sendTransaction`** — logs links to the transaction, sender, and recipient addresses
61+
- **`eth_getTransactionReceipt`** — logs links to the transaction, block, sender, recipient, and deployed contract address (if applicable)
62+
- **`eth_accounts`** — logs links to each account address
63+
64+
### Contract Deployment Tracking
65+
66+
When contracts are deployed (transactions with no `to` address), the plugin matches the creation bytecode against compiled artifacts in your project. This allows the explorer to display the contract name, ABI, and source code for deployed contracts — even without Hardhat Ignition.
4667

4768
## Usage
4869

49-
### 1. Start the node
70+
### 1. Start the Hardhat node
5071

5172
```bash
5273
npx hardhat node
5374
```
5475

55-
The OpenScan Explorer will automatically launch and your browser will open to the explorer interface.
76+
The OpenScan Explorer will automatically launch and your browser will open.
5677

57-
### 2. Deploy contracts with Ignition
78+
### 2. Deploy contracts
5879

59-
In a separate terminal:
80+
With Hardhat Ignition:
6081

6182
```bash
6283
npx hardhat ignition deploy ignition/modules/Counter.ts --network localhost
6384
```
6485

65-
### 3. Deploy contracts with script
86+
Or with a script:
6687

6788
```bash
6889
npx hardhat run scripts/deploy.ts --network localhost
6990
```
7091

71-
### 4. Send transactions with script
92+
### 3. Send transactions
7293

7394
```bash
7495
npx hardhat run scripts/send-tx.ts --network localhost
7596
```
7697

77-
All transactions will be logged with clickable OpenScan links in the console. Check that the code is verified
78-
79-
## How It Works
80-
81-
### Webapp Launch
82-
83-
The plugin hooks into Hardhat's network lifecycle using the `newConnection` hook. When the Hardhat node starts:
84-
85-
1. The hook detects the first network connection
86-
2. Checks if port 3030 is available (fails fast if not)
87-
3. Starts a custom HTTP server serving static files from the built-in explorer webapp
88-
4. Opens your default browser to the explorer URL
89-
5. Logs a success message with a clickable link
90-
91-
The webapp continues running as long as the Hardhat node is active and automatically cleans up when the node stops.
92-
93-
### Transaction Logging
94-
95-
The plugin uses the `onRequest` network hook to intercept all JSON-RPC requests. For relevant methods (like `eth_sendTransaction`, `eth_getTransactionReceipt`, etc.), it extracts transaction hashes, addresses, and block numbers, then outputs clickable OpenScan links to the console.
98+
All transactions will be logged with clickable OpenScan links in the terminal.
9699

97100
## Requirements
98101

99102
- Hardhat 3.x
100-
- Node.js 24+
101-
- Port 3030 must be available
103+
- Node.js 24
104+
- Port 3030 must be available (the explorer is hardcoded to this port — the `url` option only affects terminal link URLs, not the server port)
102105

103106
## Troubleshooting
104107

105-
### Port 8545 or 3030 Already in Use
108+
### Port 3030 Already in Use
106109

107-
If you see an error about port 8545 or 3030 being in use, you need to free up that port:
110+
If the explorer fails to start, check what is using the port:
108111

109112
```bash
110-
kill -9 $(lsof -t -i:8545)
111-
kill -9 $(lsof -t -i:3030)
113+
lsof -i :3030
112114
```
115+
116+
Then stop the conflicting process, or if it's a leftover Hardhat/OpenScan process:
117+
118+
```bash
119+
kill $(lsof -t -i:3030)
120+
```
121+
122+
## License
123+
124+
MIT

packages/plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openscan/hardhat-plugin",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Hardhat 3 plugin to use openscan explorer",
55
"license": "MIT",
66
"type": "module",
@@ -35,7 +35,7 @@
3535
"README.md"
3636
],
3737
"dependencies": {
38-
"@openscan/explorer": "1.2.3-alpha"
38+
"@openscan/explorer": "1.2.5-alpha"
3939
},
4040
"devDependencies": {
4141
"@eslint/js": "^9.35.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)