Skip to content

Commit de4b87e

Browse files
authored
Merge pull request #4 from solidstate-network/networks
Network and environment variable configuration
2 parents 3947f85 + 2995645 commit de4b87e

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ Compile contracts via Hardhat:
2424
yarn run hardhat compile
2525
```
2626

27-
### Networks
27+
The Hardhat environment relies on the following environment variables. The `dotenv` package will attempt to read them from the `.env` and `.env.secret` files, if they are present.
2828

29-
By default, Hardhat uses the Hardhat Network in-process.
29+
| Key | Description |
30+
| ------------------ | ------------------------------------------------------------- |
31+
| `NODE_URL_MAINNET` | JSON-RPC node URL for `mainnet` network |
32+
| `NODE_URL_TESTNET` | JSON-RPC node URL for `testnet` network |
33+
| `PKEY_TESTNET` | private key for test/development use on `testnet` network |
34+
| `PKEY_MAINNET` | private key for production use on `mainnet` network |
35+
| `REPORT_GAS` | if `true`, a gas report will be generated after running tests |
3036

31-
To use an external network via URL, set the `NODE_URL` environment variable and append commands with `--network generic`:
37+
### Networks
3238

33-
```bash
34-
NODE_URL="[NODE_URL]" yarn run hardhat test --network generic
35-
```
39+
By default, Hardhat uses the Hardhat Network in-process. Two additional networks, `mainnet` and `testnet` are available, and their behavior is determined by the configuration of environment variables.
3640

3741
### Testing
3842

hardhat.config.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import Dotenv from 'dotenv';
99

1010
Dotenv.config();
1111

12+
const {
13+
NODE_URL_MAINNET,
14+
NODE_URL_TESTNET,
15+
PKEY_MAINNET,
16+
PKEY_TESTNET,
17+
REPORT_GAS,
18+
} = process.env;
19+
1220
export default {
1321
solidity: {
1422
version: '0.8.11',
@@ -21,11 +29,14 @@ export default {
2129
},
2230

2331
networks: {
24-
generic: {
25-
url: `${process.env.NODE_URL}`,
26-
accounts: {
27-
mnemonic: `${process.env.MNEMONIC}`,
28-
},
32+
mainnet: {
33+
url: NODE_URL_MAINNET,
34+
accounts: [PKEY_MAINNET],
35+
},
36+
37+
testnet: {
38+
url: NODE_URL_TESTNET,
39+
accounts: [PKEY_TESTNET],
2940
},
3041
},
3142

@@ -35,7 +46,7 @@ export default {
3546
},
3647

3748
gasReporter: {
38-
enabled: process.env.REPORT_GAS === 'true',
49+
enabled: REPORT_GAS === 'true',
3950
},
4051

4152
spdxLicenseIdentifier: {

0 commit comments

Comments
 (0)