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
- โ Deploy a Collect Action Module contract
- โ Debug local contract calls with a graphical interface
- โ 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
. -
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
.Copy the burner wallet address from the top-right navbar menu.
-
Set up environment
Openconfig.ts
in thepackages/hardhat
directory and setLENS_HUB
to the address of the burner wallet provided by the nextjs project. -
Deploy
On a third terminal, from the root directory, deploy the Lens contracts locally:yarn deploy:lens
This command deploys the full Lens Protocol on the local network. 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.
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.
- Run the chain and deploy the
YourActionModule
and mock contracts to the local network, and start the app:yarn chain yarn deploy:action:local yarn start
- Navigate to http://localhost:3000/debug.
- Select the
TestToken
contract and call themint
function to mint tokens for the burner wallet. - Copy the address of the
YourActionModule
and theapprove
spending from theYourActionModule
. - Select the
YourActionModule
contract and call theinitializePublicationAction
function with a receiver address. - Call the
processPublicationAction
with the call data.
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 theYourActionModule
to Amoy you can runyarn deploy:action: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
and :mainnet
in the yarn commands, instead of :testnet
. You will also need to set the ALCHEMY_API_KEY
with a valid API key.
If you want to use your own contracts there are a few simple steps.
- Replace the
YourActionModule.sol
contract 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.