Skip to content

Fork of Scaffold-ETH 2 that demonstrates how to build, debug, test, and deploy an Open Action Module on Lens Protocol using Hardhat.

License

Notifications You must be signed in to change notification settings

0xMycaleum/scaffold-lens-playground

 
 

Repository files navigation

🏗 Scaffold-ETH 2 Scaffold-Lens

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

Using the TipActionModule Contract

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 metadataURI field on the module
  • ✅ Registers the module with the ModuleRegistry contract during deployment
  • ✅ Adds unit tests with Chai

Contents

Requirements

Before you begin, you need to install the following tools:

Quickstart

To get started with Scaffold-Lens, follow the steps below:

  1. Install
    Clone this repo & install dependencies

    git clone https://github.com/iPaulPro/scaffold-lens
    cd scaffold-lens
    yarn install
  2. 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.

  3. 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 in packages/nextjs/scaffold.config.ts.

  4. Set up environment
    To test on a local chain, you'll need to set up a .env.development file in the packages/hardhat directory. You can use the .env.development.example file as a template.

    # This should be the address of the eth-scaffold burner wallet when running locally
    LENS_HUB=0x19F380b7Bd20c49e48DBD53C732880166C792daE

    LENS_HUB should be set to the address of the burner wallet, found when running the nextjs app locally. This will allow you to test onlyHub functions on the contract.

    Screenshot of nextjs client

    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.

  5. 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. The yarn deploy:* commands use the deploy scripts located in packages/hardhat/deploy to deploy the contracts to the network.

Debugging

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.

Debugging contracts

  1. Ensure the LENS_HUB environment variable is set to the address of the burner wallet:
    LENS_HUB=""
  2. Run the chain and deploy the TipActionModule and mock contracts to the local network, and start the app:
    yarn chain
    yarn deploy:local
    yarn start
  3. Navigate to http://localhost:3000/debug.
  4. Select the TestToken contract and call the mint function to mint tokens for the burner wallet.
  5. Copy the address of the TipActionModule and the approve spending from the TipActionModule.
  6. Select the TipActionModule contract and call the initializePublicationAction function with a receiver address.
  7. Call the processPublicationAction with the tip data.

Tip: Use https://abi.hashex.org/ to encode the calldata for the initializePublicationAction and processPublicationAction functions.

Testing

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.

Deploying to Mumbai

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.

  1. Set up environment
    To deploy on Mumbai, you'll need to set up a .env file in the packages/hardhat directory. You can use the .env.example file 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=0x4BeB63842BB800A1Da77a62F2c74dE3CA39AF7C0

    Next, 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 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.

  2. Deploy
    To deploy the TipActionModule to Mumbai you can run

    yarn deploy:mumbai
  3. Verify
    You can verify your smart contract on Etherscan by running:

    yarn verify

About Scaffold-ETH 2

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.

About

Fork of Scaffold-ETH 2 that demonstrates how to build, debug, test, and deploy an Open Action Module on Lens Protocol using Hardhat.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 84.4%
  • Solidity 14.1%
  • JavaScript 1.4%
  • Other 0.1%