This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem.
pnpm install
Copy the .env.example
file in this directory to .env.local
(which will be ignored by Git):
cp .env.example .env.local
pnpm build
This 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 format
This 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 lint
If 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-check
We 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 slither
Please write tests for all contracts in the src/test/
folder. To run all use:
pnpm test
You can also run a single test using:
hardhat test src/test/{desired_test_script}.test.ts --typecheck --network hardhat
Note: All tests should be run on
hardhat
network!
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_KEY
defined in.env
while mainnet networks are configured to check for Ledger. You can quickly change these settings inhardhat.config.ts
definingaccounts
orledgerAccounts
.
Start a JSON-RPC server on top of Hardhat Network:
npx hardhat node
Deploy test contracts on Hardhat Network (this will deploy scripts sequentially in src/deploy/hardhat
):
pnpm deploy:hardhat
To 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:tenderly
To deploy to our preferred testnet, Sepolia:
pnpm deploy:sepolia
Note: hardhat will use an account
PRIVATE_KEY
defined in.env
For mainnet deployment we use Frame to deploy with a Ledger signer.
pnpm deploy:mainnet
To export contracts for use in client repositories, run:
pnpm export
This 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>.ts
To 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 verify
This 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_ADDRESS
You can try flattening the contract source code to manually submit for verification:
pnpm hardhat flatten src/contracts/Foo.sol > Flattened.sol
For 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