Quick setup
Semaphore provides an official CLI to set up your project with Hardhat. If your NPM version is 5.2 or higher you can use NPX:
npx @semaphore-protocol/cli@^3 create my-app --template monorepo-ethers
Otherwise, install @semaphore-protocol/cli@^3
globally and run the create
command:
npm i -g @semaphore-protocol/cli@^3
semaphore create my-app --template monorepo-ethers
The supported templates are: contracts-hardhat
, monorepo-ethers
, monorepo-subgraph
.
The semaphore CLI
can also be used to get group data from a supported network (e.g semaphore get-groups --network arbitrum-goerli
).
To start working on your project, install the dependencies:
- npm
- Yarn
- pnpm
cd my-app
npm i
cd my-app
yarn
cd my-app
pnpm install
Outputβ
The create
command will create a directory called my-app (or whatever name you choose) inside the current folder. That directory will contain the initial project structure, which includes a simple contract, a task to deploy it, some tests and a Next.js application (the web-app folder) to interact with that contract.
my-app
βββ .yarn
βββ apps
β βββ contracts
β β βββ contracts
| β β βββ Feedback.sol
β β βββ scripts
| β β βββ download-snark-artifacts.ts
β β βββ tasks
| β β βββ deploy.ts
β β βββ test
| β β βββ Feedback.ts
β β βββ hardhat.config.ts
β β βββ package.json
β β βββ tsconfig.json
β βββ web-app
βββ scripts
β βββ copy-contracts-artifacts.ts
βββ .editorconfig
βββ .env
βββ .env.example
βββ .eslintignore
βββ .eslintrc.json
βββ .gitignore
βββ .prettierignore
βββ .prettierrc.json
βββ .yarnrc.yml
βββ package.json
βββ README.md
βββ tsconfig.json
The Feedback.sol
contract creates a Semaphore group, allows users to join that group with their Semaphore identity, and finally allows group members to send an anonymous feedback.
Usageβ
Compile contractsβ
Go to the contracts
folder:
cd apps/contracts
And compile your contracts:
- npm
- Yarn
- pnpm
npm run compile
yarn compile
pnpm compile
Test contractsβ
Test your contracts:
- npm
- Yarn
- pnpm
npm test
yarn test
pnpm test
Generate a test coverage report:
- npm
- Yarn
- pnpm
npm run test:coverage
yarn test:coverage
pnpm test:coverage
Or a test gas report:
- npm
- Yarn
- pnpm
npm run test:report-gas
yarn test:report-gas
pnpm test:report-gas
Deploy contractsβ
Follow the instructions below to deploy your contracts:
In the project root folder:
-
Add your environment variables in the
.env
file.noteYou should at least set a valid Infura API Key (you could use Alchemy as well) and a private key with some ethers.
-
Go to the
apps/contracts
folder and deploy your contract.- npm
- Yarn
- pnpm
npm run deploy -- --semaphore <semaphore-address> --group <group-id> --network arbitrum-goerli
yarn deploy --semaphore <semaphore-address> --group <group-id> --network arbitrum-goerli
pnpm deploy --semaphore <semaphore-address> --group <group-id> --network arbitrum-goerli
noteCheck the Semaphore contract addresses here.
cautionThe group id is a number.
Start appβ
Start the application:
- npm
- Yarn
- pnpm
npm run dev
yarn dev
pnpm dev