This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.
pnpm installCopy the .env.example file in this directory to .env.local (which will be ignored by Git):
cp .env.example .env.localpnpm buildThis command uses hardhat clean to clear cache and delete all artifacts. It then runs hardhat compile to compile the entire project, building fresh artifacts.
We use Prettier for code formatting!
pnpm formatThis will run both pnpm format:ts & pnpm format:sol to write all files with the necessary plugins.
For TypeScript files we use ESLint and for Solidity files we use Solhint. You can run both with:
pnpm lintIf you want to run them individually use pnpm lint:ts or pnpm lint:sol
To check TypeScript for the entire app, run the following command:
pnpm type-checkWe use Slither in our CI pipeline to check and report any potential vulnerabilities in our contracts. You can also run this analyzer locally which will generate a SLITHER.md report. Run the following:
pnpm slitherPlease write tests for all contracts in the src/test/ folder. To run all use:
pnpm testYou can also run a single test using:
hardhat test src/test/{desired_test_script}.test.ts --typecheck --network hardhatNote: All tests should be run on
hardhatnetwork!
For deployment we use the hardhat-deploy plugin. This plugin allows you to write deploy scripts in the src/deploy folder and declare nested deploy environments. Each deploy script in the selected build environment will run sequentially.
Note: Local & Testnet networks are all configured to use an account
PRIVATE_KEYdefined in.envwhile mainnet networks are configured to check for Ledger. You can quickly change these settings inhardhat.config.tsdefiningaccountsorledgerAccounts.
Start a JSON-RPC server on top of Hardhat Network:
npx hardhat nodeDeploy test contracts on Hardhat Network (this will deploy scripts sequentially in src/deploy/hardhat):
pnpm deploy:hardhatTo use DevNets, go to Tenderly and spawn a new DevNet. You will need to copy the RPC details into .env TENDERLY_DEV_NET=<slug>/<devnet-id>
You can now set ETH_NETWORK to "tenderly" or run:
pnpm deploy:tenderlyTo deploy to our preferred testnet, Sepolia:
pnpm deploy:sepoliaNote: hardhat will use an account
PRIVATE_KEYdefined in.env
For mainnet deployment we use Frame to deploy with a Ledger signer.
pnpm deploy:mainnetTo export contracts for use in client repositories, run:
pnpm exportThis will create deployment files in exports/ for both mainnet & sepolia which are git-ignored.
Try running some of the following tasks:
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat node
npx hardhat help
npx hardhat coverage
npx hardhat run src/scripts/<script>.tsTo try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan.
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 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 follow the instructions above to deploy your contract(s).
To verify all deployments on your selected network, run:
pnpm verifyThis will use the etherscan-verify script from hardhat-deploy to quickly verify all deployments!
npx hardhat --network {network} etherscan-verify --api-key {etherscan_api_key}
If you instead want to target a specific deployment to verify:
Then, copy the deployment address and paste it in to replace DEPLOYED_CONTRACT_ADDRESS in this command:
pnpm hardhat verify --network {network} DEPLOYED_CONTRACT_ADDRESSYou can try flattening the contract source code to manually submit for verification:
pnpm hardhat flatten src/contracts/Foo.sol > Flattened.solFor 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.
Email [email protected]
or
Join the Nifty League Discord Server and message a admin