Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 9263b49

Browse files
committed
chore: setup hardhat
1 parent 9bc0aeb commit 9263b49

22 files changed

+37327
-3756
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
artifacts
3+
cache
4+
coverage

.eslintrc.js

+24
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:node/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

+10
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ yarn-error.log*
3535

3636
# typescript
3737
*.tsbuildinfo
38+
39+
node_modules
40+
.env
41+
coverage
42+
coverage.json
43+
typechain
44+
45+
#Hardhat files
46+
cache
47+
artifacts

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hardhat.config.ts
2+
scripts
3+
test

.prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
artifacts
3+
cache
4+
coverage*
5+
gasReporterOutput.json

.prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

.solhint.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "solhint:recommended",
3+
"rules": {
4+
"compiler-version": ["error", "^0.8.0"],
5+
"func-visibility": ["warn", { "ignoreConstructors": true }]
6+
}
7+
}

.solhintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+37-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2-
3-
## Getting Started
4-
5-
First, run the development server:
6-
7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
1+
# Advanced Sample Hardhat Project
2+
3+
This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.
4+
5+
The project comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. It also comes with a variety of other tools, preconfigured to work with the project code.
6+
7+
Try running some of the following tasks:
8+
9+
```shell
10+
npx hardhat accounts
11+
npx hardhat compile
12+
npx hardhat clean
13+
npx hardhat test
14+
npx hardhat node
15+
npx hardhat help
16+
REPORT_GAS=true npx hardhat test
17+
npx hardhat coverage
18+
npx hardhat run scripts/deploy.ts
19+
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
20+
npx eslint '**/*.{js,ts}'
21+
npx eslint '**/*.{js,ts}' --fix
22+
npx prettier '**/*.{json,sol,md}' --check
23+
npx prettier '**/*.{json,sol,md}' --write
24+
npx solhint 'contracts/**/*.sol'
25+
npx solhint 'contracts/**/*.sol' --fix
1126
```
1227

13-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14-
15-
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
28+
# Etherscan verification
1629

17-
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
30+
To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.
1831

19-
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
32+
In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
2033

21-
## Learn More
22-
23-
To learn more about Next.js, take a look at the following resources:
24-
25-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
34+
```shell
35+
hardhat run --network ropsten scripts/sample-script.ts
36+
```
2737

28-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
38+
Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
2939

30-
## Deploy on Vercel
40+
```shell
41+
npx hardhat verify --network ropsten DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
42+
```
3143

32-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
44+
# Performance optimizations
3345

34-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
46+
For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations).

contracts/Greeter.sol

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.0;
3+
4+
import "hardhat/console.sol";
5+
6+
contract Greeter {
7+
string private greeting;
8+
9+
constructor(string memory _greeting) {
10+
console.log("Deploying a Greeter with greeting:", _greeting);
11+
greeting = _greeting;
12+
}
13+
14+
function greet() public view returns (string memory) {
15+
return greeting;
16+
}
17+
18+
function setGreeting(string memory _greeting) public {
19+
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
20+
greeting = _greeting;
21+
}
22+
}

hardhat.config.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as dotenv from "dotenv";
2+
3+
import { HardhatUserConfig, task } from "hardhat/config";
4+
import "@nomiclabs/hardhat-waffle";
5+
import "@typechain/hardhat";
6+
import "hardhat-gas-reporter";
7+
import "solidity-coverage";
8+
9+
dotenv.config();
10+
11+
// This is a sample Hardhat task. To learn how to create your own go to
12+
// https://hardhat.org/guides/create-task.html
13+
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
14+
const accounts = await hre.ethers.getSigners();
15+
16+
for (const account of accounts) {
17+
console.log(account.address);
18+
}
19+
});
20+
21+
// You need to export an object to set up your config
22+
// Go to https://hardhat.org/config/ to learn more
23+
24+
const config: HardhatUserConfig = {
25+
defaultNetwork: 'polygon',
26+
networks: {
27+
hardhat: {
28+
chainId: 1337
29+
},
30+
'polygon-mumbai': {
31+
url: "https://rpc-mumbai.matic.today",
32+
//@ts-ignore 2322
33+
accounts: [process.env.PRIVATE_KEY]
34+
},
35+
polygon: {
36+
url: "https://polygon-rpc.com/",
37+
//@ts-ignore 2322
38+
accounts: [process.env.PRIVATE_KEY]
39+
},
40+
localhost: {
41+
url: "http://127.0.0.1:8545"
42+
}
43+
},
44+
solidity: {
45+
version: "0.8.11",
46+
settings: {
47+
optimizer: {
48+
enabled: true
49+
}
50+
}
51+
}
52+
};
53+
54+
export default config;

0 commit comments

Comments
 (0)