Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dotenv in favor of configuration variables #178

10 changes: 0 additions & 10 deletions .env.example

This file was deleted.

13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: "CI"

env:
DOTENV_CONFIG_PATH: "./.env.example"
HARDHAT_VAR_MNEMONIC: "test test test test test test test test test test test junk"
HARDHAT_VAR_INFURA_API_KEY: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
# Uncomment the following lines to set your configuration variables using
# GitHub secrets (https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions)
# HARDHAT_VAR_MNEMONIC: ${{ secrets.Mnemonic }}
# HARDHAT_VAR_INFURA_API_KEY: ${{ secrets.InfuraApiKey }}
# HARDHAT_VAR_ARBISCAN_API_KEY: ${{ secrets.ArbiscanApiKey }}
# HARDHAT_VAR_BSCSCAN_API_KEY: ${{ secrets.BscscanApiKey }}
# HARDHAT_VAR_ETHERSCAN_API_KEY: ${{ secrets.EtherscanApiKey }}
# HARDHAT_VAR_OPTIMISM_API_KEY: ${{ secrets.OptimismApiKey }}
# HARDHAT_VAR_POLYGONSCAN_API_KEY: ${{ secrets.PolygonscanApiKey }}
# HARDHAT_VAR_SNOWTRACE_API_KEY: ${{ secrets.SnowtraceApiKey }}

on:
workflow_dispatch:
Expand Down
3 changes: 0 additions & 3 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
istanbulReporter: ["html", "lcov"],
providerOptions: {
mnemonic: process.env.MNEMONIC,
},
PaulRBerg marked this conversation as resolved.
Show resolved Hide resolved
skipFiles: ["test"],
};
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,35 @@ request made to the `main` branch.

Note though that to make this work, you must use your `INFURA_API_KEY` and your `MNEMONIC` as GitHub secrets.

For more information on how to set up GitHub secrets, check out the
[docs](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions).

You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).

## Usage

### Pre Requisites

Before being able to run any command, you need to create a `.env` file and set a BIP-39 compatible mnemonic as an
environment variable. You can follow the example in `.env.example`. If you don't already have a mnemonic, you can use
this [website](https://iancoleman.io/bip39/) to generate one.

Then, proceed with installing dependencies:
First, you need to install the dependencies:

```sh
$ pnpm install
```

Then, you need to set up all the required
[Hardhat Configuration Variables](https://hardhat.org/hardhat-runner/docs/guides/configuration-variables). You might
also want to install some that are optional.

To assist with the setup process, run `pnpm dlx hardhat vars setup`. To set a particular value, such as a BIP-39
mnemonic variable, execute this:

```sh
$ pnpm dlx hardhat vars set MNEMONIC
? Enter value: ‣ here is where your twelve words mnemonic should be put my friend
```

If you do not already have a mnemonic, you can generate one using this [website](https://iancoleman.io/bip39/).

### Compile

Compile the smart contracts with Hardhat:
Expand Down
34 changes: 12 additions & 22 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import "@nomicfoundation/hardhat-toolbox";
import { config as dotenvConfig } from "dotenv";
import "hardhat-deploy";
import type { HardhatUserConfig } from "hardhat/config";
import { vars } from "hardhat/config";
import type { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path";

import "./tasks/accounts";
import "./tasks/greet";
import "./tasks/taskDeploy";

const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
// Run 'npx hardhat vars setup' to see the list of variables that need to be set

// Ensure that we have all the environment variables we need.
const mnemonic: string | undefined = process.env.MNEMONIC;
if (!mnemonic) {
throw new Error("Please set your MNEMONIC in a .env file");
}

const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
if (!infuraApiKey) {
throw new Error("Please set your INFURA_API_KEY in a .env file");
}
const mnemonic: string = vars.get("MNEMONIC");
const infuraApiKey: string = vars.get("INFURA_API_KEY");

const chainIds = {
"arbitrum-mainnet": 42161,
Expand Down Expand Up @@ -66,14 +56,14 @@ const config: HardhatUserConfig = {
},
etherscan: {
apiKey: {
arbitrumOne: process.env.ARBISCAN_API_KEY || "",
avalanche: process.env.SNOWTRACE_API_KEY || "",
bsc: process.env.BSCSCAN_API_KEY || "",
mainnet: process.env.ETHERSCAN_API_KEY || "",
optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
polygon: process.env.POLYGONSCAN_API_KEY || "",
polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
sepolia: process.env.ETHERSCAN_API_KEY || "",
arbitrumOne: vars.get("ARBISCAN_API_KEY", ""),
avalanche: vars.get("SNOWTRACE_API_KEY", ""),
bsc: vars.get("BSCSCAN_API_KEY", ""),
mainnet: vars.get("ETHERSCAN_API_KEY", ""),
optimisticEthereum: vars.get("OPTIMISM_API_KEY", ""),
polygon: vars.get("POLYGONSCAN_API_KEY", ""),
polygonMumbai: vars.get("POLYGONSCAN_API_KEY", ""),
sepolia: vars.get("ETHERSCAN_API_KEY", ""),
},
},
gasReporter: {
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
"@typescript-eslint/parser": "^5.44.0",
"chai": "^4.3.7",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"ethers": "^6.4.0",
"fs-extra": "^10.1.0",
"hardhat": "^2.12.2",
"hardhat": "^2.19.0",
"hardhat-deploy": "^0.11.29",
"hardhat-gas-reporter": "^1.0.9",
"lodash": "^4.17.21",
Expand All @@ -38,7 +37,7 @@
"rimraf": "^4.1.2",
"solhint": "^3.4.0",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"solidity-coverage": "^0.8.5",
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.2.0",
Expand Down Expand Up @@ -69,7 +68,7 @@
"lint": "pnpm lint:sol && pnpm lint:ts && pnpm prettier:check",
"lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
"postinstall": "DOTENV_CONFIG_PATH=./.env.example pnpm typechain",
"postcompile": "pnpm typechain",
PaulRBerg marked this conversation as resolved.
Show resolved Hide resolved
"prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"",
"task:deployGreeter": "hardhat task:deployGreeter",
Expand Down
Loading