Skip to content

Commit 51a488a

Browse files
committed
chore: setup hardhat
1 parent 37776aa commit 51a488a

File tree

8 files changed

+3040
-454
lines changed

8 files changed

+3040
-454
lines changed

.env.example

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ CREDENTIALS_AES_KEY=CHANGE_ME
88
# Mongo DB URI
99
MONGO_URI=mongodb://localhost/chainjet
1010

11+
# Ethereum Private Key [Warning: Storing production private keys on this file is not recommended]
12+
PRIVATE_KEY_DEV=
13+
1114
# [Optional] Set them if you want to use a Google integration
1215
GOOGLE_CLIENT_ID=
1316
GOOGLE_CLIENT_SECRET=
@@ -67,7 +70,7 @@ CRONOS_RPC_URL=https://evm-cronos.crypto.org
6770
ETHEREUM_RPC_URL=https://rpc.ankr.com/eth
6871
FANTOM_RPC_URL=https://rpc.ftm.tools
6972
GNOSIS_RPC_URL=https://rpc.gnosischain.com
70-
GORLI_RPC_URL=https://goerli.infura.io/v3/
73+
GOERLI_RPC_URL=https://goerli.infura.io/v3/
7174
HARMONY_RPC_URL=https://api.harmony.one
7275
KOVAN_RPC_URL=https://kovan.infura.io/v3/
7376
METIS_RPC_URL=https://andromeda.metis.io/?owner=1088

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
/dist
33
/node_modules
44

5+
# Hardhat
6+
/artifacts
7+
/cache
8+
/typechain-types
9+
510
# Configs
611
.env
712

contracts/lock.sol

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.17;
3+
4+
// Uncomment this line to use console.log
5+
// import "hardhat/console.sol";
6+
7+
contract Lock {
8+
uint public unlockTime;
9+
address payable public owner;
10+
11+
event Withdrawal(uint amount, uint when);
12+
13+
constructor(uint _unlockTime) payable {
14+
require(
15+
block.timestamp < _unlockTime,
16+
"Unlock time should be in the future"
17+
);
18+
19+
unlockTime = _unlockTime;
20+
owner = payable(msg.sender);
21+
}
22+
23+
function withdraw() public {
24+
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
25+
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);
26+
27+
require(block.timestamp >= unlockTime, "You can't withdraw yet");
28+
require(msg.sender == owner, "You aren't the owner");
29+
30+
emit Withdrawal(address(this).balance, block.timestamp);
31+
32+
owner.transfer(address(this).balance);
33+
}
34+
}

hardhat.config.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import '@nomicfoundation/hardhat-toolbox'
2+
import { HardhatUserConfig } from 'hardhat/config'
3+
import { ChainId } from './libs/blockchain/src/types/ChainId'
4+
require('dotenv').config()
5+
6+
const config: HardhatUserConfig = {
7+
solidity: '0.8.17',
8+
networks: {
9+
ethereum: {
10+
chainId: ChainId.ETHEREUM,
11+
url: process.env.ETHEREUM_RPC_URL,
12+
accounts: [process.env.PRIVATE_KEY_DEV!],
13+
},
14+
goerli: {
15+
chainId: ChainId.GOERLI,
16+
url: process.env.GOERLI_RPC_URL,
17+
accounts: [process.env.PRIVATE_KEY_DEV!],
18+
},
19+
polygon: {
20+
chainId: ChainId.POLYGON,
21+
url: process.env.POLYGON_RPC_URL,
22+
accounts: [process.env.PRIVATE_KEY_DEV!],
23+
},
24+
},
25+
}
26+
27+
export default config

libs/blockchain/src/blockchain.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export const blockchainConfigList: () => { networks: { [chainId: number]: IBlock
6767
explorers: [new BlockScoutExplorer('https://blockscout.com/xdai/mainnet/api')],
6868
multicall2Address: '0x67dA5f2FfaDDfF067AB9d5F025F8810634d84287',
6969
},
70-
[ChainId.GÖRLI]: {
71-
key: 'gorli',
72-
url: process.env.GORLI_RPC_URL!,
70+
[ChainId.GOERLI]: {
71+
key: 'goerli',
72+
url: process.env.GOERLI_RPC_URL!,
7373
explorers: [new EtherScanExplorer('https://api-goerli.etherscan.io/api', process.env.ETHERSCAN_KEY!)],
7474
multicall2Address: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696',
7575
},

libs/blockchain/src/types/ChainId.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export enum ChainId {
1616
FANTOM_TESTNET = 4002,
1717
FUSE = 122,
1818
GNOSIS = 100,
19-
GÖRLI = 5,
19+
GOERLI = 5,
2020
HARMONY = 1666600000,
2121
HARMONY_TESTNET = 1666700000,
2222
HECO = 128,

package.json

+15-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"deepmerge": "^4.2.2",
6363
"definitions": "^0.0.2",
6464
"discord-interactions": "^3.2.0",
65-
"ethers": "^5.6.9",
65+
"ethers": "5.7.1",
6666
"express-session": "^1.17.3",
6767
"graphql": "15.8.0",
6868
"graphql-relay": "0.10.0",
@@ -100,9 +100,18 @@
100100
"swagger2openapi": "^6.2.3"
101101
},
102102
"devDependencies": {
103+
"@ethersproject/abi": "5.7.0",
104+
"@ethersproject/providers": "5.7.1",
103105
"@nestjs/cli": "^9.0.0",
104106
"@nestjs/schematics": "^9.0.1",
105107
"@nestjs/testing": "^9.0.8",
108+
"@nomicfoundation/hardhat-chai-matchers": "1.0.3",
109+
"@nomicfoundation/hardhat-network-helpers": "1.0.6",
110+
"@nomicfoundation/hardhat-toolbox": "2.0.0",
111+
"@nomiclabs/hardhat-ethers": "2.1.1",
112+
"@nomiclabs/hardhat-etherscan": "3.1.0",
113+
"@typechain/ethers-v5": "10.1.0",
114+
"@typechain/hardhat": "6.1.3",
106115
"@types/aws4": "^1.5.1",
107116
"@types/bcryptjs": "^2.4.2",
108117
"@types/crypto-js": "^3.1.47",
@@ -133,22 +142,27 @@
133142
"@typescript-eslint/eslint-plugin": "^4.1.1",
134143
"@typescript-eslint/parser": "^4.1.1",
135144
"aws-sdk-mock": "5.7.0",
145+
"chai": "4.3.6",
136146
"eslint": "8.21.0",
137147
"eslint-config-next": "12.2.4",
138148
"eslint-config-prettier": "^8.5.0",
139149
"eslint-plugin-prettier": "^4.2.1",
140150
"ethereum-types": "^3.7.0",
151+
"hardhat": "2.11.2",
152+
"hardhat-gas-reporter": "1.0.9",
141153
"jest": "28.1.3",
142154
"mongodb-memory-server": "^6.6.7",
143155
"openapi3-ts": "^1.4.0",
144156
"postinstall-postinstall": "^2.1.0",
145157
"prettier": "^2.7.1",
158+
"solidity-coverage": "0.8.2",
146159
"supertest": "6.2.4",
147160
"ts-jest": "28.0.7",
148161
"ts-loader": "9.3.1",
149162
"ts-morph": "^15.1.0",
150163
"ts-node": "^10.9.1",
151164
"tsconfig-paths": "^4.1.0",
165+
"typechain": "8.1.0",
152166
"typescript": "^4.7.4"
153167
},
154168
"jest": {

0 commit comments

Comments
 (0)