Fork of Scaffold-ETH 2 that demonstrates how to build, debug, test, and deploy an Open Action Module on Lens Protocol using Hardhat.
MIT License
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:
Before you begin, you need to install the following tools:
To get started with Scaffold-Lens, follow the steps below:
Install Clone this repo & install dependencies
git 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
. The yarn deploy:*
commands use the scripts located in packages/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 in packages/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.
TipActionModule
contract.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 the packages/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 with yarn account
.
Deploy
To deploy the TipActionModule
and PayWhatYouWantCollectModule
to Amoy you can run
yarn 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
.
⚠️ NOTE: There is no reason to deploy 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.
TipActionModule.sol
and/or PayWhatYouWantCollectModule
contracts in /packages/hardhat/contracts
with your own./packages/hardhat/deploy
to deploy your contract(s) instead of the mock contracts.deploy:*
scripts in /packages/hardhat/package.json
to the tag(s) of your contract(s)./packages/hardhat/contracts/helpers
directory and related deploy scripts unless you want to use the TestToken
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.