|
1 | | -# `openscan-hardhat-links` |
| 1 | +# @openscan/hardhat-plugin |
2 | 2 |
|
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. |
4 | 4 |
|
5 | | -## Installation |
| 5 | +Learn more at <https://openscan.eth.link> |
6 | 6 |
|
7 | | -To install this plugin, run the following command: |
| 7 | +## Installation |
8 | 8 |
|
9 | 9 | ```bash |
10 | | -npm install --save-dev openscan-hardhat-links |
| 10 | +npm install --save-dev @openscan/hardhat-plugin |
11 | 11 | ``` |
12 | 12 |
|
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: |
14 | 16 |
|
15 | 17 | ```ts |
| 18 | +import openScanPlugin from "@openscan/hardhat-plugin"; |
16 | 19 | import { defineConfig } from "hardhat/config"; |
17 | | -import openScanPlugin from "openscan-hardhat-links"; |
18 | 20 |
|
19 | 21 | export default defineConfig({ |
20 | 22 | plugins: [openScanPlugin], |
| 23 | + solidity: "0.8.29", |
21 | 24 | networks: { |
22 | | - ... |
| 25 | + localhost: { |
| 26 | + type: "http", |
| 27 | + url: "http://127.0.0.1:8545", |
| 28 | + }, |
23 | 29 | }, |
24 | 30 | openScan: { |
25 | | - url: "http://localhost:3030", |
26 | | - chainId: 31337, |
| 31 | + url: "http://localhost:3030", // default |
| 32 | + chainId: 31337, // default |
27 | 33 | }, |
28 | 34 | }); |
29 | | - |
30 | 35 | ``` |
31 | 36 |
|
| 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 | + |
32 | 44 | ## Features |
33 | 45 |
|
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: |
35 | 49 |
|
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 |
40 | 53 |
|
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. |
46 | 67 |
|
47 | 68 | ## Usage |
48 | 69 |
|
49 | | -### 1. Start the node |
| 70 | +### 1. Start the Hardhat node |
50 | 71 |
|
51 | 72 | ```bash |
52 | 73 | npx hardhat node |
53 | 74 | ``` |
54 | 75 |
|
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. |
56 | 77 |
|
57 | | -### 2. Deploy contracts with Ignition |
| 78 | +### 2. Deploy contracts |
58 | 79 |
|
59 | | -In a separate terminal: |
| 80 | +With Hardhat Ignition: |
60 | 81 |
|
61 | 82 | ```bash |
62 | 83 | npx hardhat ignition deploy ignition/modules/Counter.ts --network localhost |
63 | 84 | ``` |
64 | 85 |
|
65 | | -### 3. Deploy contracts with script |
| 86 | +Or with a script: |
66 | 87 |
|
67 | 88 | ```bash |
68 | 89 | npx hardhat run scripts/deploy.ts --network localhost |
69 | 90 | ``` |
70 | 91 |
|
71 | | -### 4. Send transactions with script |
| 92 | +### 3. Send transactions |
72 | 93 |
|
73 | 94 | ```bash |
74 | 95 | npx hardhat run scripts/send-tx.ts --network localhost |
75 | 96 | ``` |
76 | 97 |
|
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. |
96 | 99 |
|
97 | 100 | ## Requirements |
98 | 101 |
|
99 | 102 | - 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) |
102 | 105 |
|
103 | 106 | ## Troubleshooting |
104 | 107 |
|
105 | | -### Port 8545 or 3030 Already in Use |
| 108 | +### Port 3030 Already in Use |
106 | 109 |
|
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: |
108 | 111 |
|
109 | 112 | ```bash |
110 | | -kill -9 $(lsof -t -i:8545) |
111 | | -kill -9 $(lsof -t -i:3030) |
| 113 | +lsof -i :3030 |
112 | 114 | ``` |
| 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 |
0 commit comments