Skip to content

feat: add new cli using SemaphoreViem #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/cli-template-monorepo-viem/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120
indent_size = 4

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions packages/cli-template-monorepo-viem/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEFAULT_NETWORK=hardhat
ETHEREUM_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
REPORT_GAS=false
COINMARKETCAP_API_KEY=
ETHERSCAN_API_KEY=
56 changes: 56 additions & 0 deletions packages/cli-template-monorepo-viem/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# IDE
.vscode
.idea

# Dependency directories
node_modules/

# Output of 'npm pack'
*.tgz

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Yarn Integrity file
.yarn-integrity

# vercel
.vercel

# dotenv environment variable files
.env

# Optional npm cache directory
.npm
.DS_Store

# yarn v3
.pnp.*
.pnp.js
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
49 changes: 49 additions & 0 deletions packages/cli-template-monorepo-viem/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# dependencies
node_modules
package-lock.json
yarn.lock
.yarn

# testing
coverage
coverage.json

# docs
docs

# production
dist
build
contract-artifacts

# Hardhat files
artifacts
cache
typechain-types

# github
.github/ISSUE_TEMPLATE

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Next.js
.next/
out/

# The Graph
generated

# Auto Generated PWA files
**/public/sw.js
**/public/workbox-*.js
**/public/worker-*.js
**/public/sw.js.map
**/public/workbox-*.js.map
**/public/worker-*.js.map
5 changes: 5 additions & 0 deletions packages/cli-template-monorepo-viem/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"arrowParens": "always",
"trailingComma": "none"
}
893 changes: 893 additions & 0 deletions packages/cli-template-monorepo-viem/.yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/cli-template-monorepo-viem/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.0.cjs
56 changes: 56 additions & 0 deletions packages/cli-template-monorepo-viem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Semaphore Hardhat + Next.js + SemaphoreEthers template

This project is a complete application that demonstrates a basic Semaphore use case. It comes with a sample contract, a test for that contract and a sample task that deploys that contract. It also contains a frontend to play around with the contract.

## Install

### Install dependencies

```bash
yarn
```

## 📜 Usage

### Local server

You can start your app locally with:

```bash
yarn dev
```

### Deploy the contract

1. Go to the `apps/contracts` directory and deploy your contract:

```bash
yarn deploy --semaphore <semaphore-address> --network sepolia
```

2. Update your `apps/web-app/.env.production` file with your new contract address and the group id.

3. Copy your contract artifacts from `apps/contracts/artifacts/contracts/` folder to `apps/web-app/contract-artifacts` folder manually.

> [!NOTE]
> Check the Semaphore contract addresses [here](https://docs.semaphore.pse.dev/deployed-contracts).

### Code quality and formatting

Run [ESLint](https://eslint.org/) and [solhint](https://github.com/protofire/solhint) to analyze the code and catch bugs:

```bash
yarn lint
```

Run [Prettier](https://prettier.io/) to check formatting rules:

```bash
yarn prettier
```

Or to automatically format the code:

```bash
yarn prettier:write
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# dependencies
node_modules

# testing
coverage
coverage.json

# hardhat
artifacts
cache
typechain-types

# misc
.DS_Store
*.pem



Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"env": {
"es6": true
},
"extends": ["airbnb-base", "airbnb-typescript/base", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"project": ["./tsconfig.json", "./packages/**/tsconfig.json"]
},
"plugins": ["@typescript-eslint"],
"rules": {
"no-underscore-dangle": "off",
"import/no-extraneous-dependencies": "off",
"no-bitwise": "off",
"no-await-in-loop": "off",
"no-restricted-syntax": "off",
"no-console": ["warn", { "allow": ["info", "warn", "error", "log"] }],
"@typescript-eslint/lines-between-class-members": "off",
"no-param-reassign": "off"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:default"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@semaphore-protocol/contracts/interfaces/ISemaphore.sol";

contract Feedback {
ISemaphore public semaphore;

uint256 public groupId;

constructor(address semaphoreAddress) {
semaphore = ISemaphore(semaphoreAddress);

groupId = semaphore.createGroup();
}

function joinGroup(uint256 identityCommitment) external {
semaphore.addMember(groupId, identityCommitment);
}

function sendFeedback(
uint256 merkleTreeDepth,
uint256 merkleTreeRoot,
uint256 nullifier,
uint256 feedback,
uint256[8] calldata points
) external {
ISemaphore.SemaphoreProof memory proof = ISemaphore.SemaphoreProof(
merkleTreeDepth,
merkleTreeRoot,
nullifier,
feedback,
groupId,
points
);

semaphore.validateProof(groupId, proof);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "@nomicfoundation/hardhat-toolbox"
import "@semaphore-protocol/hardhat"
import { getHardhatNetworks } from "@semaphore-protocol/utils"
import { config as dotenvConfig } from "dotenv"
import { HardhatUserConfig } from "hardhat/config"
import { resolve } from "path"
import "./tasks/deploy"

dotenvConfig({ path: resolve(__dirname, "../../.env") })

const config: HardhatUserConfig = {
solidity: "0.8.23",
defaultNetwork: process.env.DEFAULT_NETWORK || "hardhat",
networks: {
hardhat: {
chainId: 1337
},
...getHardhatNetworks(process.env.ETHEREUM_PRIVATE_KEY)
},
gasReporter: {
currency: "USD",
enabled: process.env.REPORT_GAS === "true",
coinmarketcap: process.env.COINMARKETCAP_API_KEY
},
typechain: {
target: "ethers-v6"
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY
},
sourcify: {
enabled: true
}
}

export default config
56 changes: 56 additions & 0 deletions packages/cli-template-monorepo-viem/apps/contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "monorepo-viem-contracts",
"private": true,
"scripts": {
"dev": "hardhat node & yarn deploy --network localhost",
"compile": "hardhat compile",
"deploy": "yarn compile && hardhat deploy",
"verify": "hardhat verify",
"test": "hardhat test",
"test:report-gas": "REPORT_GAS=true hardhat test",
"test:coverage": "hardhat coverage",
"typechain": "hardhat typechain",
"lint": "eslint . --ext .js,.ts && solhint 'contracts/**/*.sol'",
"prettier": "prettier -c --plugin=prettier-plugin-solidity .",
"prettier:write": "prettier -w --plugin=prettier-plugin-solidity ."
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@semaphore-protocol/core": "4.12.0",
"@semaphore-protocol/hardhat": "4.12.0",
"@semaphore-protocol/utils": "4.12.0",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/eslint": "^8",
"@types/mocha": ">=9.1.0",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"chai": "^4.2.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"ethers": "^6.13.4",
"hardhat": "^2.20.1",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^4.1.1",
"solidity-coverage": "^0.8.1",
"ts-node": "^10.9.2",
"typechain": "^8.3.0",
"typescript": "^5.3.3"
},
"dependencies": {
"@semaphore-protocol/contracts": "4.12.0"
},
"packageManager": "yarn@4.1.0"
}
Loading
Loading