This project is a fork of Scaffold-ETH 2 for building dapps with Lens V3 on Lens Chain.
Features:
- ✅ Run a local ZKsync chain and test contracts locally with Hardhat
- ✅ Deploy the full V3 Lens Protocol on a local network
- ✅ Debug Lens V3 contracts on a Lens Testnet
- ✅ Debug contracts with a graphical interface
- ✅ Deploy a Lens Account Action contract
- ✅ Deploy a Lens Post Rule contract
- ✅ Verify contracts on Lens Block Explorer
- Requirements
- Quickstart
- Debugging
- Unit Testing
- Deploying to Testnet
- Using your own contracts
- About Scaffold-ETH 2
Before you begin, you need to install the following tools:
- Node (>= v18.17)
- Yarn (v1 or v2+)
- Git
To get started with Scaffold-Lens, follow the steps below:
-
Install
Clone this repo & install dependenciesgit clone https://github.com/iPaulPro/scaffold-lens cd scaffold-lens yarn install -
Start a chain
Run a local Lens Chain in a terminal from the root directory:yarn chain
This command starts a local zkSync node using Hardhat and the hardhat-zksync plugin. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in
hardhat.config.ts. -
Deploy
On a second terminal, from the root directory, deploy the Lens contracts locally:yarn deploy
This command deploys the full Lens Social Protocol on the local network as well as the example Action and Rule contracts. Put your contracts in
packages/hardhat/contracts. -
Start the app
On a third terminal, from the root directory, start your NextJS app:yarn start
Visit your app on:
http://localhost:3000. You can interact with your smart contracts using the contract component and review all transactions in the block explorer. You can tweak the app config inpackages/nextjs/scaffold.config.ts.
You can debug your smart contracts using the Contract Debugger. If you haven't already, from the root directory, start your NextJS app:
yarn startThen navigate to http://localhost:3000/debug to open the debugger. You can now call functions on your smart contracts and debug them in the browser.
Run the smart contract unit tests from the root directory.
yarn hardhat:testThis will run the tests located in packages/hardhat/test with Chai.
Once you are ready to deploy your smart contracts, there are a few things you need to adjust.
-
Set up environment
To deploy on Lens Testnet, you'll need to set up a.env.stagingfile in thepackages/hardhatdirectory. You can use the.env.staging.examplefile as a template.Next, generate a new account or add one to deploy the contract(s) from.
DEPLOYER_PRIVATE_KEY=""The deployer wallet is the account that will deploy your contracts. Additionally, the deployer account will be used to execute any function calls that are part of your deployment script.
You can generate a random account / private key with
yarn generateor add the private key of your crypto wallet.yarn generatewill create a random account and add the DEPLOYER_PRIVATE_KEY to the .env file. You can check the generated account withyarn account. -
Ensure your deployer account has sufficient $GRASS tokens needed to deploy the contract(s) on the Lens Testnet. You can get free $GRASS tokens from Alchemy or Lenscan.
-
Deploy
To deploy theAccountVerificationActionandFollowingOnlyPostRuleto Lens Testnet you can runyarn deploy:testnet
To deploy your contracts to Lens Chain, you will need to follow similar steps as for the testnet, but with a few adjustments:
-
Set up environment
Create a.envfile in thepackages/hardhatdirectory using the.env.exampleas a template.Set the
DEPLOYER_PRIVATE_KEYto the private key of your deployer account. -
Add a script Add a script for deploying to mainnet that uses the production environment, something like:
{ "scripts": { "deploy:mainnet": "hardhat deploy-zksync --network lensMainnet --tags YourContractName,generateTsAbis" } } -
Deploy
To deploy your contract to Lens Chain you can then runyarn deploy:mainnet
If you want to use your own contracts there are a few simple steps.
- Replace the
AccountVerificationAction.soland/orFollowingOnlyPostRule.solcontracts in/packages/hardhat/contractswith your own. - Update the script(s) in
/packages/hardhat/deployto deploy your contract(s) instead of the sample contracts. - Change the tag in the
deploy:testnetscript in/packages/hardhat/package.jsonto the tag(s) of your contract(s).
Scaffold-ETH is an open-source toolkit for building Ethereum dapps, built using NextJS, RainbowKit, Hardhat, Wagmi, and Typescript.
Learn more about Scaffold-ETH 2 and read the docs here.