This project is a fork of Scaffold-ETH 2 that demonstrates how to build, debug, test, and deploy an Open Action Module on Lens Protocol using Hardhat.
Scaffold-Lens can be used as a Scaffold-ETH 2 Extension, instead of forking the project. You can install it when using create-eth
to create a new project:
npx create-eth@latest -e iPaulPro/scaffold-lens:ext
See the ext branch for the extension-specific docs.
Features:
- ✅ Run a local EVM chain and test contracts locally with Hardhat
- ✅ Deploy the full Lens Protocol on a local network 🆕
- ✅ Debug local contract calls with a graphical interface
- ✅ Create and act on Lens publications with a graphical interface 🆕
- ✅ Deploy an ERC20 token contract used for Open Actions
- ✅ Deploy an Open Action Module contract
- ✅ Deploy a Collect Action Module contract
- ✅ Verify contracts on Etherscan
- 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 network in a terminal from the root directory:yarn chain
This command starts a local Ethereum network using Hardhat. 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 Protocol on the local network as well as the example Open Action and Collect Module contracts. Put your contracts in
packages/hardhat/contracts
. Theyarn deploy:*
commands use the scripts located inpackages/hardhat/deploy
to deploy the contracts to the specified network. -
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
.Copy the burner wallet address from the top-right navbar menu.
You can debug your smart contracts using the Contract Debugger. If you haven't already, from the root directory, start your NextJS app:
yarn start
Then 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.
To debug your Lens Modules, you can use the Open Actions Debugger UI to create and act on publications. The UI is available at http://localhost:3000/lens
, or you can click on the "Open Actions" navigation link in the header.
Scaffold-Lens includes example contracts for Open Actions and Collect Modules in the packages/hardhat/contracts
directory. You can use these contracts as a starting point for your own Lens Modules. The Open Actions page will automatically include any deployed Open Actions and Collect Modules in the dropdowns.
The TipActionModule
corresponds to the example from the Lens Docs. The PayWhatYouWantCollectModule
is an example of an Open Action Collect Module that can be used with the core CollectPublicationAction
Open Action.
The /lens
page will also automatically display any ERC-20 tokens that were deployed locally in the sidebar to make it easier to use these tokens to initialize and act on publications that require token transfers.
- Create a Profile
Before you can create publications, you need to create a profile. Click on the "Add Profile" button in the sidebar and follow the instructions to create a profile. - Create a Publication
Use the textarea in the main content section to create a new publication. You can select an Open Action and Collect Module to use. For example, you can create a new publication with tipping enabled using theTipActionModule
contract. - Act on a Publication
You can act on publications by clicking on the "Act" button in the publication card.
Run the smart contract unit tests from the root directory.
yarn hardhat:test
This 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 Amoy, you'll need to set up a.env.staging
file in thepackages/hardhat
directory. You can use the.env.staging.example
file as a template.Next, generate a new account or add one to deploy the contract(s) from. Additionally, you will need to add your Alchemy API key.
ALCHEMY_API_KEY="" 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 generate
or add the private key of your crypto wallet.yarn generate
will create a random account and add the DEPLOYER_PRIVATE_KEY to the .env file. You can check the generated account withyarn account
. -
Deploy
To deploy theTipActionModule
andPayWhatYouWantCollectModule
to Amoy you can runyarn deploy:testnet
-
Verify
You can verify your smart contract on Etherscan by running:yarn verify:testnet
Follow the same directions for deploying to Amoy, but use the .env
file instead of .env.staging
. Then, add a :mainnet
script entry in the yarn commands, instead of :testnet
and use --network polygonAmoy
.
TipActionModule
and PayWhatYouWantCollectModule
as they are already deployed and verified with the Protocol on mainnet.
If you want to use your own contracts there are a few simple steps.
- Replace the
TipActionModule.sol
and/orPayWhatYouWantCollectModule
contracts in/packages/hardhat/contracts
with your own. - Update the script(s) in
/packages/hardhat/deploy
to deploy your contract(s) instead of the mock contracts. - Change the tag in the
deploy:*
scripts in/packages/hardhat/package.json
to the tag(s) of your contract(s). - (Optional) Remove the
/packages/hardhat/contracts/helpers
directory and related deploy scripts unless you want to use theTestToken
contract for testing and debugging.
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.