hardhat-deploy 2.0.0-next.7 → 2.0.0-next.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +197 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/default.d.ts.map +1 -0
  8. package/dist/config/default.js +5 -0
  9. package/dist/config/default.js.map +1 -0
  10. package/dist/config/get-config.d.ts.map +1 -0
  11. package/dist/config/get-config.js +9 -0
  12. package/dist/config/get-config.js.map +1 -0
  13. package/dist/config/validation.d.ts.map +1 -0
  14. package/dist/config/validation.js +17 -0
  15. package/dist/config/validation.js.map +1 -0
  16. package/dist/generate-types.d.ts +5 -0
  17. package/dist/generate-types.d.ts.map +1 -0
  18. package/dist/generate-types.js +241 -0
  19. package/dist/generate-types.js.map +1 -0
  20. package/dist/helpers.d.ts +34 -0
  21. package/dist/helpers.d.ts.map +1 -0
  22. package/dist/{esm/helpers.js → helpers.js} +106 -73
  23. package/dist/helpers.js.map +1 -0
  24. package/dist/hook-handlers/config.d.ts.map +1 -0
  25. package/dist/hook-handlers/config.js +68 -0
  26. package/dist/hook-handlers/config.js.map +1 -0
  27. package/dist/hook-handlers/solidity.d.ts.map +1 -0
  28. package/dist/hook-handlers/solidity.js +21 -0
  29. package/dist/hook-handlers/solidity.js.map +1 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/{esm/index.js → index.js} +20 -3
  33. package/dist/index.js.map +1 -0
  34. package/dist/postinstall.d.ts +3 -0
  35. package/dist/postinstall.d.ts.map +1 -0
  36. package/dist/postinstall.js +148 -0
  37. package/dist/postinstall.js.map +1 -0
  38. package/dist/{esm/tasks → tasks}/deploy.d.ts +1 -0
  39. package/dist/tasks/deploy.d.ts.map +1 -0
  40. package/dist/tasks/deploy.js +32 -0
  41. package/dist/tasks/deploy.js.map +1 -0
  42. package/dist/{esm/type-extensions.d.ts → type-extensions.d.ts} +2 -2
  43. package/dist/type-extensions.d.ts.map +1 -0
  44. package/dist/type-extensions.js.map +1 -0
  45. package/dist/types.d.ts +13 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/utils/files.d.ts +10 -0
  49. package/dist/utils/files.d.ts.map +1 -0
  50. package/dist/utils/files.js +44 -0
  51. package/dist/utils/files.js.map +1 -0
  52. package/dist/v1-detection.d.ts +12 -0
  53. package/dist/v1-detection.d.ts.map +1 -0
  54. package/dist/v1-detection.js +118 -0
  55. package/dist/v1-detection.js.map +1 -0
  56. package/dist/v1-entry.cjs +92 -0
  57. package/package.json +57 -27
  58. package/src/cli.ts +246 -0
  59. package/src/config/default.ts +6 -0
  60. package/src/config/get-config.ts +12 -0
  61. package/src/config/validation.ts +25 -0
  62. package/src/generate-types.ts +278 -0
  63. package/src/helpers.ts +311 -0
  64. package/src/hook-handlers/config.ts +80 -0
  65. package/src/hook-handlers/solidity.ts +33 -0
  66. package/src/index.ts +53 -0
  67. package/src/postinstall.ts +166 -0
  68. package/src/tasks/deploy.ts +43 -0
  69. package/src/type-extensions.ts +12 -0
  70. package/src/types.ts +9 -0
  71. package/src/utils/files.ts +59 -0
  72. package/src/v1-entry.cjs +92 -0
  73. package/templates/basic/README.md +44 -0
  74. package/templates/basic/contracts/Counter.sol +19 -0
  75. package/templates/basic/contracts/Counter.t.sol +29 -0
  76. package/templates/basic/deploy/01_deploy_counter.ts +13 -0
  77. package/templates/basic/hardhat.config.ts +50 -0
  78. package/templates/basic/package.json +31 -0
  79. package/templates/basic/pnpm-lock.yaml +1643 -0
  80. package/templates/basic/rocketh/config.ts +65 -0
  81. package/templates/basic/rocketh/deploy.ts +20 -0
  82. package/templates/basic/rocketh/environment.ts +22 -0
  83. package/templates/basic/test/Counter.ts +61 -0
  84. package/templates/basic/tsconfig.json +13 -0
  85. package/dist/esm/config/default.d.ts.map +0 -1
  86. package/dist/esm/config/default.js +0 -8
  87. package/dist/esm/config/default.js.map +0 -1
  88. package/dist/esm/config/get-config.d.ts.map +0 -1
  89. package/dist/esm/config/get-config.js +0 -8
  90. package/dist/esm/config/get-config.js.map +0 -1
  91. package/dist/esm/config/validation.d.ts.map +0 -1
  92. package/dist/esm/config/validation.js +0 -16
  93. package/dist/esm/config/validation.js.map +0 -1
  94. package/dist/esm/generate-types.d.ts +0 -6
  95. package/dist/esm/generate-types.d.ts.map +0 -1
  96. package/dist/esm/generate-types.js +0 -198
  97. package/dist/esm/generate-types.js.map +0 -1
  98. package/dist/esm/helpers.d.ts +0 -18
  99. package/dist/esm/helpers.d.ts.map +0 -1
  100. package/dist/esm/helpers.js.map +0 -1
  101. package/dist/esm/hook-handlers/config.d.ts.map +0 -1
  102. package/dist/esm/hook-handlers/config.js +0 -16
  103. package/dist/esm/hook-handlers/config.js.map +0 -1
  104. package/dist/esm/hook-handlers/solidity.d.ts.map +0 -1
  105. package/dist/esm/hook-handlers/solidity.js +0 -15
  106. package/dist/esm/hook-handlers/solidity.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -5
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js.map +0 -1
  110. package/dist/esm/tasks/deploy.d.ts.map +0 -1
  111. package/dist/esm/tasks/deploy.js +0 -21
  112. package/dist/esm/tasks/deploy.js.map +0 -1
  113. package/dist/esm/type-extensions.d.ts.map +0 -1
  114. package/dist/esm/type-extensions.js.map +0 -1
  115. package/dist/esm/types.d.ts +0 -15
  116. package/dist/esm/types.d.ts.map +0 -1
  117. package/dist/esm/types.js.map +0 -1
  118. /package/dist/{esm/config → config}/default.d.ts +0 -0
  119. /package/dist/{esm/config → config}/get-config.d.ts +0 -0
  120. /package/dist/{esm/config → config}/validation.d.ts +0 -0
  121. /package/dist/{esm/hook-handlers → hook-handlers}/config.d.ts +0 -0
  122. /package/dist/{esm/hook-handlers → hook-handlers}/solidity.d.ts +0 -0
  123. /package/dist/{esm/type-extensions.js → type-extensions.js} +0 -0
  124. /package/dist/{esm/types.js → types.js} +0 -0
@@ -0,0 +1,33 @@
1
+ import type {HookContext, SolidityHooks} from 'hardhat/types/hooks';
2
+
3
+ import {generateTypes} from '../generate-types.js';
4
+
5
+ export default async (): Promise<Partial<SolidityHooks>> => {
6
+ const handlers: Partial<SolidityHooks> = {
7
+ async onCleanUpArtifacts(
8
+ context: HookContext,
9
+ artifactPaths: string[],
10
+ next: (nextContext: HookContext, artifactPaths: string[]) => Promise<void>
11
+ ) {
12
+ let artifactPathsToProcess = [context.config.paths.artifacts];
13
+ // if (context.config.generateTypedArtifacts.externalArtifacts) {
14
+ // artifactPathsToProcess = artifactPathsToProcess.concat(
15
+ // context.config.generateTypedArtifacts.externalArtifacts
16
+ // );
17
+ // }
18
+
19
+ if (artifactPaths.length > 0) {
20
+ await generateTypes(
21
+ {
22
+ artifacts: artifactPathsToProcess,
23
+ },
24
+ context.config.generateTypedArtifacts
25
+ );
26
+ }
27
+
28
+ return next(context, artifactPaths);
29
+ },
30
+ };
31
+
32
+ return handlers;
33
+ };
package/src/index.ts ADDED
@@ -0,0 +1,53 @@
1
+ import {setupLogger} from 'named-logs-console';
2
+ import type {HardhatPlugin} from 'hardhat/types/plugins';
3
+ import {task} from 'hardhat/config';
4
+
5
+ import './type-extensions.js';
6
+ import {ArgumentType} from 'hardhat/types/arguments';
7
+ import type {Environment} from 'rocketh/types';
8
+ import type {NetworkConnection} from 'hardhat/types/network';
9
+
10
+ // const deployTask = import.meta.resolve('./tasks/deploy.js').replace('.ts', '.js');
11
+ // console.log({deployTask});
12
+
13
+ setupLogger(['rocketh', '@rocketh/node'], {
14
+ enabled: true,
15
+ level: 3,
16
+ });
17
+
18
+ const hardhatPlugin: HardhatPlugin = {
19
+ id: 'hardhat-deploy',
20
+ hookHandlers: {
21
+ config: () => import('./hook-handlers/config.js'),
22
+ solidity: () => import('./hook-handlers/solidity.js'),
23
+ },
24
+ tasks: [
25
+ task('deploy', 'Deploy contracts')
26
+ // .addFlag('skipGasReport', 'if set, skip gas report')
27
+ .addFlag({name: 'skipPrompts', description: 'if set, skip any prompts'})
28
+ .addOption({
29
+ name: 'saveDeployments',
30
+ description: 'if set, save deployments',
31
+ defaultValue: '',
32
+ type: ArgumentType.STRING,
33
+ })
34
+ .addOption({
35
+ name: 'tags',
36
+ description: 'specify which tags to deploy',
37
+ defaultValue: '',
38
+ type: ArgumentType.STRING,
39
+ })
40
+ .setAction(() => import('./tasks/deploy.js'))
41
+ .build(),
42
+ ],
43
+ npmPackage: 'hardhat-deploy',
44
+ };
45
+
46
+ export default hardhatPlugin;
47
+
48
+ export function getHardhatConnection(env: Environment): NetworkConnection<'generic'> {
49
+ if (!env.extra?.connection) {
50
+ throw new Error('Hardhat deploy connection not found in the environment');
51
+ }
52
+ return env.extra.connection as NetworkConnection<'generic'>;
53
+ }
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Attempt to detect if user is in a v1 environment
4
+ // This script should be lightweight and fail gracefully
5
+
6
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
7
+ import { join, dirname } from 'path';
8
+ import { execSync } from 'child_process';
9
+
10
+
11
+ const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1.html';
12
+ const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
13
+ const MARKER_FILE = '.hardhat-deploy-v2-notice';
14
+
15
+ // Find the project root by navigating up from node_modules
16
+ function findProjectRoot(currentPath: string): string {
17
+ let path = currentPath;
18
+
19
+ while (path !== '/' && path !== '') {
20
+ // Check if we're inside node_modules
21
+ if (path.includes('node_modules')) {
22
+ path = dirname(path);
23
+ continue;
24
+ }
25
+
26
+ // Check if this directory has a package.json (likely project root)
27
+ if (existsSync(join(path, 'package.json'))) {
28
+ return path;
29
+ }
30
+
31
+ path = dirname(path);
32
+ }
33
+
34
+ // Fallback to current directory
35
+ return currentPath;
36
+ }
37
+
38
+ async function checkEnvironment() {
39
+ // Postinstall runs in the package directory, need to find the actual project root
40
+ const projectRoot = findProjectRoot(process.cwd());
41
+ let v1Detected = false;
42
+ let reasons: string[] = [];
43
+
44
+ // Check for hardhat version via command line
45
+ try {
46
+ const output = execSync('hardhat --version', { encoding: 'utf-8', stdio: 'pipe', cwd: projectRoot });
47
+ // Output format is like "hardhat, version 2.x.x" or "hardhat, version 3.x.x"
48
+ const match = output.match(/hardhat, version (\d+\.\d+\.\d+)/);
49
+ if (match) {
50
+ const hardhatVersion = match[1];
51
+ if (hardhatVersion.startsWith('2.')) {
52
+ v1Detected = true;
53
+ reasons.push(`hardhat ${hardhatVersion} detected (v2 requires hardhat 3.x)`);
54
+ }
55
+ }
56
+ } catch (e) {
57
+ // Hardhat not installed yet - that's fine
58
+ }
59
+
60
+ // Check for v1-style config patterns
61
+ try {
62
+ const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
63
+
64
+ for (const configFile of configFiles) {
65
+ const configPath = join(projectRoot, configFile);
66
+ if (existsSync(configPath)) {
67
+ const content = readFileSync(configPath, 'utf-8');
68
+
69
+ if (content.includes('namedAccounts')) {
70
+ v1Detected = true;
71
+ reasons.push(`'namedAccounts' found in ${configFile}`);
72
+ }
73
+
74
+ if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
75
+ v1Detected = true;
76
+ reasons.push(`require('hardhat-deploy') found in ${configFile}`);
77
+ }
78
+
79
+ if (content.includes('module.exports')) {
80
+ v1Detected = true;
81
+ reasons.push(`CommonJS 'module.exports' found in ${configFile}`);
82
+ }
83
+ }
84
+ }
85
+ } catch (e) {
86
+ // Config check failed - continue silently
87
+ }
88
+
89
+ if (v1Detected) {
90
+ printV1Warning(reasons);
91
+ createMarkerFile(projectRoot, reasons);
92
+ } else {
93
+ printWelcome();
94
+ }
95
+ }
96
+
97
+ function createMarkerFile(projectRoot: string, reasons: string[]) {
98
+ const markerPath = join(projectRoot, MARKER_FILE);
99
+ const content = `HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED
100
+
101
+ This file was created because hardhat-deploy v2 detected v1 patterns in your project.
102
+ You can delete this file after reading.
103
+
104
+ Detected issues:
105
+ ${reasons.map((r) => ` - ${r}`).join('\n')}
106
+
107
+ To resolve this, either:
108
+
109
+ 1. Install hardhat-deploy v1 instead:
110
+ npm uninstall hardhat-deploy
111
+ ${V1_INSTALL_CMD}
112
+
113
+ 2. Migrate your project to v2:
114
+ ${MIGRATION_URL}
115
+
116
+ For more information, see the migration guide.
117
+ `;
118
+
119
+ try {
120
+ writeFileSync(markerPath, content, 'utf-8');
121
+ } catch (e) {
122
+ // Failed to write marker file - continue anyway
123
+ }
124
+ }
125
+
126
+ function printV1Warning(reasons: string[]) {
127
+ const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
128
+
129
+ console.log(`
130
+ ╔══════════════════════════════════════════════════════════════════════════════╗
131
+ ║ ║
132
+ ║ ⚠️ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
133
+ ║ ║
134
+ ╚══════════════════════════════════════════════════════════════════════════════╝
135
+
136
+ Your project appears to be using hardhat-deploy v1 patterns:
137
+
138
+ ${reasonsList}
139
+
140
+ hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x.
141
+
142
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
143
+
144
+ OPTION 1: Install v1 instead (recommended for existing v1 projects)
145
+
146
+ npm uninstall hardhat-deploy
147
+ ${V1_INSTALL_CMD}
148
+
149
+ OPTION 2: Migrate to v2
150
+
151
+ See: ${MIGRATION_URL}
152
+
153
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
154
+
155
+ A marker file '${MARKER_FILE}' has been created in your project root.
156
+ `);
157
+ }
158
+
159
+ function printWelcome() {
160
+ console.log(`
161
+ ✓ hardhat-deploy v2 installed successfully!
162
+ Documentation: https://rocketh.dev/hardhat-deploy/
163
+ `);
164
+ }
165
+
166
+ checkEnvironment().catch(() => {});
@@ -0,0 +1,43 @@
1
+ import {NewTaskActionFunction} from 'hardhat/types/tasks';
2
+ import {loadAndExecuteDeploymentsFromFiles} from '@rocketh/node';
3
+ import {generateForkConfig} from '../helpers.js';
4
+ import {setupLogger} from 'named-logs-console';
5
+
6
+ interface RunActionArguments {
7
+ saveDeployments: string;
8
+ skipPrompts: boolean;
9
+ tags?: string;
10
+ }
11
+
12
+ const runScriptWithHardhat: NewTaskActionFunction<RunActionArguments> = async (args, hre) => {
13
+ let saveDeployments = true;
14
+ let skipPrompts = args.skipPrompts ? true : false;
15
+
16
+ const {connection, environment, isFork, provider} = await generateForkConfig({hre});
17
+
18
+ const isMemoryNetwork = connection.networkConfig.type == 'edr-simulated';
19
+ if (isMemoryNetwork) {
20
+ skipPrompts = true;
21
+ saveDeployments = false;
22
+ }
23
+ if (args.saveDeployments != '') {
24
+ saveDeployments = args.saveDeployments == 'true' ? true : false;
25
+ }
26
+ const tags = args.tags && args.tags != '' ? args.tags : undefined;
27
+
28
+ setupLogger(['rocketh', '@rocketh/node'], {
29
+ enabled: true,
30
+ level: 3,
31
+ });
32
+
33
+ await loadAndExecuteDeploymentsFromFiles({
34
+ provider,
35
+ environment: environment,
36
+ saveDeployments: isFork ? false : saveDeployments,
37
+ askBeforeProceeding: skipPrompts ? false : true,
38
+ tags: tags?.split(','),
39
+ // reportGasUse: args.skipGasReport ? false : true,
40
+ extra: {connection},
41
+ });
42
+ };
43
+ export default runScriptWithHardhat;
@@ -0,0 +1,12 @@
1
+ import 'hardhat/types/config';
2
+ import {ArtifactGenerationConfig, ArtifactGenerationUserConfig} from './types.js';
3
+
4
+ declare module 'hardhat/types/config' {
5
+ export interface HardhatUserConfig {
6
+ generateTypedArtifacts?: ArtifactGenerationUserConfig;
7
+ }
8
+
9
+ export interface HardhatConfig {
10
+ readonly generateTypedArtifacts: ArtifactGenerationConfig;
11
+ }
12
+ }
package/src/types.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type ArtifactGenerationUserConfig = {
2
+ // externalArtifacts?: string[];
3
+ destinations?: {mode?: 'javascript' | 'typescript'; folder?: string}[];
4
+ };
5
+
6
+ export type ArtifactGenerationConfig = {
7
+ // externalArtifacts: string[];
8
+ destinations: {mode: 'javascript' | 'typescript'; folder: string}[];
9
+ };
@@ -0,0 +1,59 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ export type FileTraversed = {
5
+ name: string;
6
+ path: string;
7
+ relativePath: string;
8
+ mtimeMs: number;
9
+ directory: boolean;
10
+ };
11
+
12
+ export function traverse(
13
+ dir: string,
14
+ result: any[] = [],
15
+ topDir?: string,
16
+ filter?: (name: string, stats: any) => boolean // TODO any is Stats
17
+ ): Array<FileTraversed> {
18
+ fs.readdirSync(dir).forEach((name) => {
19
+ const fPath = path.resolve(dir, name);
20
+ const stats = fs.statSync(fPath);
21
+ if ((!filter && !name.startsWith('.')) || (filter && filter(name, stats))) {
22
+ const fileStats = {
23
+ name,
24
+ path: fPath,
25
+ relativePath: path.relative(topDir || dir, fPath),
26
+ mtimeMs: stats.mtimeMs,
27
+ directory: stats.isDirectory(),
28
+ };
29
+ if (fileStats.directory) {
30
+ result.push(fileStats);
31
+ return traverse(fPath, result, topDir || dir, filter);
32
+ }
33
+ result.push(fileStats);
34
+ }
35
+ });
36
+ return result;
37
+ }
38
+
39
+ // from https://github.com/sindresorhus/slash
40
+ /*
41
+ MIT License
42
+
43
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50
+ */
51
+ export function slash(path: string) {
52
+ const isExtendedLengthPath = path.startsWith('\\\\?\\');
53
+
54
+ if (isExtendedLengthPath) {
55
+ return path;
56
+ }
57
+
58
+ return path.replace(/\\/g, '/');
59
+ }
@@ -0,0 +1,92 @@
1
+ // This file serves as a CommonJS entry point for hardhat v2
2
+ // It detects v1 users and shows them a migration message
3
+
4
+ const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1.html';
5
+ const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
6
+
7
+ function getHardhatVersion() {
8
+ try {
9
+ const {execSync} = require('child_process');
10
+ // Run hardhat --version to get the version
11
+ const output = execSync('hardhat --version', {encoding: 'utf-8', stdio: 'pipe'});
12
+ return output.trim();
13
+ } catch (e) {
14
+ console.error(e);
15
+ return 'unknown';
16
+ }
17
+ }
18
+
19
+ function detectV1Patterns() {
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const reasons = [];
23
+
24
+ // Check hardhat.config for v1 patterns
25
+ const configFiles = ['hardhat.config.js', 'hardhat.config.cjs', 'hardhat.config.ts'];
26
+
27
+ for (const configFile of configFiles) {
28
+ const configPath = path.join(process.cwd(), configFile);
29
+ if (fs.existsSync(configPath)) {
30
+ try {
31
+ const content = fs.readFileSync(configPath, 'utf-8');
32
+
33
+ if (content.includes('namedAccounts')) {
34
+ reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern`);
35
+ }
36
+
37
+ if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
38
+ reasons.push(
39
+ `Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`,
40
+ );
41
+ }
42
+
43
+ if (content.includes('module.exports')) {
44
+ reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
45
+ }
46
+ } catch (e) {
47
+ // Failed to read config - continue
48
+ }
49
+ }
50
+ }
51
+
52
+ return reasons;
53
+ }
54
+
55
+ function throwV1Error() {
56
+ const hardhatVersion = getHardhatVersion();
57
+ const reasons = detectV1Patterns();
58
+
59
+ let reasonsList = '';
60
+ if (reasons.length > 0) {
61
+ reasonsList = '\nYour project uses hardhat-deploy v1 patterns:\n\n' + reasons.map((r) => ` • ${r}`).join('\n');
62
+ }
63
+
64
+ throw new Error(`
65
+ ╔══════════════════════════════════════════════════════════════════════════════╗
66
+ ║ HARDHAT-DEPLOY V2 - INCOMPATIBLE WITH HARDHAT V2 ║
67
+ ╚══════════════════════════════════════════════════════════════════════════════╝
68
+
69
+ hardhat-deploy v2 requires hardhat 3.x, but you are using hardhat ${hardhatVersion}.${reasonsList}
70
+
71
+ hardhat-deploy v2 has MAJOR breaking changes and uses ESM modules.
72
+
73
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
74
+
75
+ OPTION 1: Install hardhat-deploy v1 (recommended for hardhat v2 projects)
76
+
77
+ npm uninstall hardhat-deploy
78
+ ${V1_INSTALL_CMD}
79
+
80
+ OPTION 2: Upgrade to hardhat 3.x and hardhat-deploy v2
81
+
82
+ Migration guide: ${MIGRATION_URL}
83
+
84
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85
+ `);
86
+ }
87
+
88
+ // Throw error immediately when loaded by hardhat v2
89
+ throwV1Error();
90
+
91
+ // Export a dummy function to satisfy hardhat's plugin loading
92
+ module.exports = function () {};
@@ -0,0 +1,44 @@
1
+ # Sample Hardhat 3 Project (`node:test`)
2
+
3
+ This project showcases a Hardhat 3 project using the [hardhat-deploy](https://github.com/wighawag/hardhat-deploy) plugin (along with the [rocketh](https://github.com/wighawag/rocketh) deployment system) and the native Node.js test runner (`node:test`) .
4
+
5
+ To learn more about hardhat-deploy and rocketh, please visit the [documentation](https://rocketh.dev).
6
+
7
+ ## Project Overview
8
+
9
+ This example project includes:
10
+
11
+ - A simple Hardhat configuration file.
12
+ - Foundry-compatible Solidity unit tests.
13
+ - Built-in mechanism to load deployments in test via hardhat-deploy and rocketh.
14
+
15
+ ## Usage
16
+
17
+ ### Running Tests
18
+
19
+ To run all the tests in the project, execute the following command:
20
+
21
+ ```bash
22
+ pnpm hardhat test
23
+ ```
24
+
25
+ You can also selectively run the Solidity or `node:test` tests:
26
+
27
+ ```bash
28
+ pnpm hardhat test solidity
29
+ pnpm hardhat test nodejs
30
+ ```
31
+
32
+ ### Deploying Contracts
33
+
34
+ To deploy the contracts to an in-memory network, run:
35
+
36
+ ```bash
37
+ pnpm hardhat deploy
38
+ ```
39
+
40
+ To deploy the contracts to a specific network, use the `--network` option:
41
+
42
+ ```bash
43
+ pnpm hardhat deploy --network <network-name>
44
+ ```
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.28;
3
+
4
+ contract Counter {
5
+ uint public x;
6
+
7
+ event Increment(uint by);
8
+
9
+ function inc() public {
10
+ x++;
11
+ emit Increment(1);
12
+ }
13
+
14
+ function incBy(uint by) public {
15
+ require(by > 0, "incBy: increment should be positive");
16
+ x += by;
17
+ emit Increment(by);
18
+ }
19
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {Counter} from "./Counter.sol";
5
+ import {Test} from "forge-std/Test.sol";
6
+
7
+ contract CounterTest is Test {
8
+ Counter counter;
9
+
10
+ function setUp() public {
11
+ counter = new Counter();
12
+ }
13
+
14
+ function test_InitialValue() public view {
15
+ require(counter.x() == 0, "Initial value should be 0");
16
+ }
17
+
18
+ function testFuzz_Inc(uint8 x) public {
19
+ for (uint8 i = 0; i < x; i++) {
20
+ counter.inc();
21
+ }
22
+ require(counter.x() == x, "Value after calling inc x times should be x");
23
+ }
24
+
25
+ function test_IncByZero() public {
26
+ vm.expectRevert();
27
+ counter.incBy(0);
28
+ }
29
+ }
@@ -0,0 +1,13 @@
1
+ import { deployScript, artifacts } from "../rocketh/deploy.js";
2
+
3
+ export default deployScript(
4
+ async ({ deploy, namedAccounts }) => {
5
+ const { deployer } = namedAccounts;
6
+
7
+ await deploy("Counter", {
8
+ account: deployer,
9
+ artifact: artifacts.Counter,
10
+ });
11
+ },
12
+ { tags: ["Counter", "Counter_deploy"] },
13
+ );
@@ -0,0 +1,50 @@
1
+ import { configVariable, defineConfig } from "hardhat/config";
2
+ import hardhatNodeTestRunnerPlugin from "@nomicfoundation/hardhat-node-test-runner";
3
+ import hardhatKeyStorePlugin from "@nomicfoundation/hardhat-keystore";
4
+ import hardhatNetworkHelpersPlugin from "@nomicfoundation/hardhat-network-helpers";
5
+ import hardhatViemPlugin from "@nomicfoundation/hardhat-viem";
6
+ import hardhatViemAssertionsPlugin from "@nomicfoundation/hardhat-viem-assertions";
7
+ import HardhatDeploy from "hardhat-deploy";
8
+
9
+ export default defineConfig({
10
+ plugins: [
11
+ hardhatNodeTestRunnerPlugin,
12
+ hardhatKeyStorePlugin,
13
+ hardhatNetworkHelpersPlugin,
14
+ HardhatDeploy,
15
+ hardhatViemPlugin,
16
+ hardhatViemAssertionsPlugin
17
+ ],
18
+ solidity: {
19
+ profiles: {
20
+ default: {
21
+ version: "0.8.28",
22
+ },
23
+ production: {
24
+ version: "0.8.28",
25
+ settings: {
26
+ optimizer: {
27
+ enabled: true,
28
+ runs: 200,
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ networks: {
35
+ hardhatMainnet: {
36
+ type: "edr-simulated",
37
+ chainType: "l1",
38
+ },
39
+ hardhatOp: {
40
+ type: "edr-simulated",
41
+ chainType: "op",
42
+ },
43
+ sepolia: {
44
+ type: "http",
45
+ chainType: "l1",
46
+ url: configVariable("SEPOLIA_RPC_URL"),
47
+ accounts: [configVariable("SEPOLIA_PRIVATE_KEY")],
48
+ },
49
+ },
50
+ });
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "template-hardhat-node-test-runner",
3
+ "version": "0.0.0",
4
+ "description": "A TypeScript Hardhat project using Node Test Runner",
5
+ "type": "module",
6
+ "devDependencies": {
7
+ "@nomicfoundation/hardhat-keystore": "^3.0.3",
8
+ "@nomicfoundation/hardhat-network-helpers": "^3.0.3",
9
+ "@nomicfoundation/hardhat-node-test-runner": "^3.0.8",
10
+ "@nomicfoundation/hardhat-viem": "^3.0.2",
11
+ "@nomicfoundation/hardhat-viem-assertions": "^3.0.5",
12
+ "@rocketh/deploy": "^0.17.9",
13
+ "@rocketh/doc": "^0.17.18",
14
+ "@rocketh/export": "^0.17.18",
15
+ "@rocketh/node": "^0.17.18",
16
+ "@rocketh/proxy": "^0.17.13",
17
+ "@rocketh/read-execute": "^0.17.9",
18
+ "@rocketh/verifier": "^0.17.18",
19
+ "@rocketh/viem": "^0.17.6",
20
+ "@types/node": "^25.0.10",
21
+ "forge-std": "foundry-rs/forge-std#v1.9.4",
22
+ "hardhat": "^3.1.5",
23
+ "hardhat-deploy": "workspace:*",
24
+ "rocketh": "^0.17.14",
25
+ "typescript": "~5.9.3",
26
+ "viem": "^2.43.0"
27
+ },
28
+ "scripts": {
29
+ "test": "hardhat test"
30
+ }
31
+ }