This repository contains a boilerplate for developing smart contracts on the Lens Network with tooling for Hardhat and Foundry.
The common use case for this environment is for developing and deploying with Hardhat (which is more stable for ZKSync tooling), and using Foundry for running tests as described here.
- Node.js: >= v20
- Yarn: v3.2.4
If you use nvm to manage your Node.js versions, you can run:
nvm useto switch to the correct Node.js version.
See the installation guide for other ways to install Node.js.
Enable Corepack, if it isn't already; this will add the Yarn binary to your PATH:
corepack enableSee the installation guide for other ways to install Yarn.
Install dependencies:
yarn installCreate a .env file copying the .env.example file:
cp .env.example .envUpdate the .env file with the correct values.
yarn compileyarn cleanyarn lintRun tests on the Hardhat Network powered by a [ZKsync In-memory Node]((https://docs.zksync.io/build/test-and-debug/in-memory-node).
yarn testTo run tests on a specific network:
yarn test [--network <network-name>]
For example, to run Hardhat tests (*.test.ts) on the lensTestnet network:
yarn test --network lensTestnetTip
zkSync In-memory Node currently supports only the L2 node. If contracts also need L1, use another testing environment like Dockerized Node.
A faster alternative for test running is to utilize Foundry to run tests on the Hardhat project.
First install the ZKSync Foundry library:
curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bashSwitch to Foundry ZKSync version:
foundryup-zksyncTo run Foundry tests (*.t.sol) on the lensTestnet network, compile contract source:
FOUNDRY_PROFILE=zksync forge compile --zksyncThen run tests:
FOUNDRY_PROFILE=zksync forge test --zksyncyarn deploy --script <deploy-script.ts> --network <network-name>For example:
yarn deploy --script deploy-token.ts --network lensTestnetlensTestnet: Lens Development Network (37111).hardhat: runs on a ZKsync In-Memory Node for testing.
Lens Network Hardhat Boilerplate MIT licensed