Skip to content

Commit 4a41b15

Browse files
committed
init
0 parents  commit 4a41b15

20 files changed

+502
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
env: {
3+
browser: false,
4+
es2021: true,
5+
mocha: true,
6+
node: true,
7+
},
8+
plugins: ['@typescript-eslint'],
9+
extends: [
10+
'standard',
11+
'plugin:prettier/recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
],
14+
parser: '@typescript-eslint/parser',
15+
parserOptions: {
16+
ecmaVersion: 12,
17+
},
18+
rules: {
19+
'node/no-unsupported-features/es-syntax': [
20+
'error',
21+
{ ignores: ['modules'] },
22+
],
23+
},
24+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
singleQuote: true,
3+
bracketSpacing: true,
4+
overrides: [
5+
{
6+
files: '*.sol',
7+
options: {
8+
printWidth: 120,
9+
tabWidth: 4,
10+
singleQuote: false,
11+
explicitTypes: 'always',
12+
},
13+
},
14+
],
15+
};

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hardhat Create App Template
2+
3+
```npx hardhat-create-app myApp```

bin/hardhat-create-app.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs-extra');
4+
const path = require('path');
5+
const { spawnSync, execSync } = require('child_process');
6+
7+
const projectName = process.argv[2];
8+
9+
if (!projectName) {
10+
console.error('No project name specified');
11+
process.exit(1);
12+
}
13+
14+
const root = path.resolve(projectName);
15+
16+
fs.ensureDirSync(root);
17+
process.chdir(root);
18+
19+
console.log(`Creating a new Hardhat project in ${root}.`);
20+
21+
// Initialize a new npm project
22+
console.log('Initializing a new npm project...');
23+
spawnSync('npm', ['init', '-y'], { stdio: 'inherit' });
24+
25+
// Install Hardhat and initialize a new TypeScript project
26+
console.log('Installing Hardhat...');
27+
spawnSync('npm', ['install', 'hardhat'], { stdio: 'inherit' });
28+
29+
console.log('Initializing a new Hardhat TypeScript project...');
30+
const result = execSync(
31+
'HARDHAT_CREATE_TYPESCRIPT_PROJECT_WITH_DEFAULTS=true npx hardhat',
32+
{
33+
stdio: 'inherit',
34+
}
35+
);
36+
37+
console.log('Installing Hardhat Plugins...');
38+
spawnSync(
39+
'npm',
40+
[
41+
'install',
42+
'--save-dev',
43+
'-f',
44+
'solhint',
45+
'prettier',
46+
'prettier-plugin-solidity',
47+
'hardhat-deploy',
48+
'@types/chai',
49+
'@types/mocha',
50+
'@types/node',
51+
'dotenv',
52+
'@nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers',
53+
'@openzeppelin/contracts',
54+
'hardhat-contract-sizer',
55+
'hardhat-gas-reporter',
56+
],
57+
{ stdio: 'inherit' }
58+
);
59+
60+
// Add the "compile" script to package.json
61+
console.log("Adding the 'compile' script to package.json...");
62+
const packageJsonPath = path.join(root, 'package.json');
63+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
64+
packageJson.scripts.compile = 'hardhat compile';
65+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
66+
67+
// Edit the hardhat.config.ts
68+
console.log('Editing the hardhat.config.ts...');
69+
const configPath = path.join(root, 'hardhat.config.ts');
70+
const configContent = fs.readFileSync(configPath, 'utf-8');
71+
let modifiedContent = configContent.replace(
72+
'};',
73+
`
74+
networks: {
75+
hardhat: {
76+
forking: {
77+
url: nodeUrl('matic') ?? '',
78+
blockNumber: 37377259, // Latest as of 28.12.2022
79+
},
80+
},
81+
matic: {
82+
url: nodeUrl('matic'),
83+
accounts: accounts('matic'),
84+
},
85+
mumbai: {
86+
url: nodeUrl('mumbai'),
87+
accounts: accounts('mumbai'),
88+
},
89+
rinkeby: {
90+
url: nodeUrl('rinkeby'),
91+
accounts: accounts('rinkeby'),
92+
},
93+
},
94+
gasReporter: {
95+
enabled: process.env.REPORT_GAS !== undefined,
96+
currency: 'USD',
97+
token: 'MATIC',
98+
gasPriceApi:
99+
'https://api.polygonscan.com/api?module=proxy&action=eth_gasPrice',
100+
coinmarketcap: process.env.COINMARKETCAP_API_KEY,
101+
},
102+
etherscan: {
103+
apiKey: {
104+
mainnet: process.env.ETHERSCAN_API_KEY || '',
105+
rinkeby: process.env.ETHERSCAN_API_KEY || '',
106+
polygon: process.env.POLYGONSCAN_API_KEY || '',
107+
polygonMumbai: process.env.POLYGONSCAN_API_KEY || '',
108+
},
109+
},
110+
mocha: {
111+
timeout: 0,
112+
},
113+
namedAccounts: {
114+
deployer: {
115+
default: 0,
116+
},
117+
proxyAdminOwner: {
118+
default: 1,
119+
},
120+
bob: {
121+
default: 5,
122+
},
123+
alice: {
124+
default: 6,
125+
},
126+
mat: {
127+
default: 7,
128+
},
129+
},
130+
};
131+
`
132+
);
133+
134+
modifiedContent = modifiedContent.replace(
135+
`import "@nomicfoundation/hardhat-toolbox";`,
136+
`import '@nomicfoundation/hardhat-toolbox';
137+
import 'hardhat-deploy';
138+
import 'hardhat-gas-reporter';
139+
import 'hardhat-contract-sizer';
140+
import { nodeUrl, accounts } from './utils/network';
141+
import * as dotenv from 'dotenv';
142+
import './tasks/acl';
143+
144+
dotenv.config();
145+
`
146+
);
147+
fs.writeFileSync(configPath, modifiedContent);
148+
149+
// Copy files to the project directory
150+
console.log('Copying files to the project directory...');
151+
fs.copySync(path.resolve(__dirname, '../files'), `${root}/`);
152+
153+
console.log(`
154+
Success! Created ${projectName} at ${root}.
155+
156+
Inside that directory, you can run several commands:
157+
158+
npm run compile
159+
Compiles the contracts.
160+
161+
npm run test
162+
Runs the tests.
163+
164+
npm run test:watch
165+
Runs the tests in watch mode.
166+
167+
We suggest that you begin by typing:
168+
169+
cd ${projectName}
170+
npm run test
171+
172+
Happy hacking!
173+
`);

files/.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MNEMONIC_MUMBAI=
2+
MNEMONIC_MATIC=
3+
MNEMONIC_RINKEBY=
4+
5+
ETH_NODE_URI_MUMBAI=
6+
ETH_NODE_URI_MATIC=
7+
ETH_NODE_URI_RINKEBY=
8+
9+
ETHERSCAN_API_KEY=""
10+
POLYGONSCAN_API_KEY=""
11+
12+
COINMARKETCAP_API_KEY=""
13+
14+
REPORT_GAS=true

files/.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
artifacts
3+
cache
4+
coverage

files/.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
env: {
3+
browser: false,
4+
es2021: true,
5+
mocha: true,
6+
node: true,
7+
},
8+
plugins: ['@typescript-eslint'],
9+
extends: [
10+
'standard',
11+
'plugin:prettier/recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
],
14+
parser: '@typescript-eslint/parser',
15+
parserOptions: {
16+
ecmaVersion: 12,
17+
},
18+
rules: {
19+
'node/no-unsupported-features/es-syntax': [
20+
'error',
21+
{ ignores: ['modules'] },
22+
],
23+
},
24+
};

0 commit comments

Comments
 (0)