Skip to content

Instantly share code, notes, and snippets.

@leonpw
Created December 8, 2022 12:43
Show Gist options
  • Save leonpw/c9de5aee411699a4f7c150edf9b98dee to your computer and use it in GitHub Desktop.
Save leonpw/c9de5aee411699a4f7c150edf9b98dee to your computer and use it in GitHub Desktop.
Inits a default hardhat tempolate with TS and Mocha
mkdir project
cd project
yarn init -2
yarn config set nodeLinker node-modules
yarn add hardhat --dev
rm README.md
yarn hardhat init
yarn add mocha --dev
code .

Environment setup

.mocharc.json file:

{
  "require": "hardhat/register",
  "timeout": 40000,
  "_": ["tests/**/*.ts"]
}
Suggested renaming:
// Renaming "test" folder
mv test tests
If using Yarn Berry with PnP:
// Setting up yarn sdk for vscode
yarn dlx @yarnpkg/sdks vscode
// Press ctrl+shift+p in a TypeScript file
// Choose "Select TypeScript Version"
// Pick "Use Workspace Version"

hardhat.config.ts file:

{
const config: HardhatUserConfig = {
...
  paths: { tests: "tests" },
...
  }
}

tsconfig.json file:


...
  "include": ["./scripts", "./tests", "./typechain"],
  "files": ["./hardhat.config.ts"],
...

Create env file in root project folder

.env file:

MNEMONIC="here is where your twelve words mnemonic should be put my friend"
PRIVATE_KEY="<your private key here if you don't have a mnemonic seed>"
INFURA_API_KEY="********************************"
INFURA_API_SECRET="********************************"
ALCHEMY_API_KEY="********************************"
ETHERSCAN_API_KEY="********************************"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment