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.
Features:
- ✅ Run a local EVM chain and test contracts locally with Hardhat
- ✅ Deploy a mock ModuleRegistry contract
- ✅ Deploy an ERC20 token contract used for whitelisted tips
- ✅ Deploy an Open Action Module contract
- ✅ Debug local contract calls with a graphical interface
- ✅ Verify contracts on Etherscan
To use the live TipActionModule deployed by Orna, you can find the contract address and ABI from the dedicated repo:
https://github.com/mvanhalen/TipActionModule
It also includes information about the Orna tip indexer API, which allows you to query for tips for a given publication or user.
This repo demonstrates how to debug and test the TipActionModule. Additions to the Orna contract include:
- ✅ Publishes metadata file on Arweave during deployment and sets a
metadataURIfield on the module - ✅ Registers the module with the ModuleRegistry contract during deployment
- ✅ Adds unit tests with Chai
Before you begin, you need to install the following tools:
- Node (v18 LTS)
- 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. -
Start the app
On a second 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. -
Set up environment
To test on a local chain, you'll need to set up a.env.developmentfile in thepackages/hardhatdirectory. You can use the.env.development.examplefile as a template.# This should be the address of the eth-scaffold burner wallet when running locally LENS_HUB=0x19F380b7Bd20c49e48DBD53C732880166C792daELENS_HUBshould be set to the address of the burner wallet, found when running the nextjs app locally. This will allow you to testonlyHubfunctions on the contract.
NOTE: The burner wallet created in the nextjs app is different from the deployer wallet used to deploy the contracts. You can think of the burner as a user wallet.
-
Deploy
On a third terminal, from the root directory, deploy the test contract locally:yarn deploy:local
This command deploys the smart contracts to the local network. The contracts are located in
packages/hardhat/contracts. Theyarn deploy:*commands use the deploy scripts located inpackages/hardhat/deployto deploy the contracts to the network.
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.
- Ensure the
LENS_HUBenvironment variable is set to the address of the burner wallet:LENS_HUB="" - Run the chain and deploy the
TipActionModuleand mock contracts to the local network, and start the app:yarn chain yarn deploy:local yarn start
- Navigate to http://localhost:3000/debug.
- Select the
TestTokencontract and call themintfunction to mint tokens for the burner wallet. - Copy the address of the
TipActionModuleand theapprovespending from theTipActionModule. - Select the
TipActionModulecontract and call theinitializePublicationActionfunction with a receiver address. - Call the
processPublicationActionwith the tip data.
Tip: Use https://abi.hashex.org/ to encode the calldata for the initializePublicationAction and processPublicationAction functions.
Run the smart contract unit tests from the root directory.
yarn hardhat:testThis will run the tests located in packages/hardhat/test with Chai.
NOTE: There is no need to publish your own TipActionModule if all you want is to add tipping support to your app. In that case you should use the verified contract by Orna.
Once you are ready to deploy your smart contracts, there are a few things you need to adjust.
-
Set up environment
To deploy on Mumbai, you'll need to set up a.envfile in thepackages/hardhatdirectory. You can use the.env.examplefile as a template. You'll need to provide the current addresses of the Lens Hub and Module Registry contracts. (These should be provided by Lens Protocol).# These should be provided by https://docs.lens.xyz/docs/deployed-contract-addresses LENS_HUB=0x4fbffF20302F3326B20052ab9C217C44F6480900 MODULE_REGISTRY=0x4BeB63842BB800A1Da77a62F2c74dE3CA39AF7C0Next, generate a new account or add one to deploy the contract(s) from. Additionally you will need to add your Alchemy API key. Note that the key should correspond to the network you're deploying on (in this case, Mumbai).
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 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. -
Deploy
To deploy theTipActionModuleto Mumbai you can runyarn deploy:mumbai
-
Verify
You can verify your smart contract on Etherscan by running:yarn verify
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.