Saltar al contenido principal
Versi贸n: V4-beta

Getting started

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 create my-app --template monorepo-ethers

Otherwise, install @semaphore-protocol/cli globally and run the create command:

npm i -g @semaphore-protocol/cli
semaphore create my-app --template monorepo-ethers
informaci贸n

The supported templates are: contracts-hardhat, monorepo-ethers, monorepo-subgraph.

informaci贸n

The semaphore CLI can also be used to get group data from a supported network (e.g. semaphore get-groups --network sepolia).

To start working on your project, install the dependencies:

cd my-app
yarn

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
鈹 鈹 鈹斺攢鈹 tasks
| 鈹 鈹 鈹斺攢鈹 deploy.ts
鈹 鈹 鈹斺攢鈹 test
| 鈹 鈹 鈹斺攢鈹 Feedback.ts
鈹 鈹 鈹斺攢鈹 hardhat.config.ts
鈹 鈹 鈹斺攢鈹 package.json
鈹 鈹 鈹斺攢鈹 tsconfig.json
鈹 鈹斺攢鈹 web-app
鈹溾攢鈹 .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:

yarn compile

Test contracts

Test your contracts:

yarn test

Generate a test coverage report:

yarn test:coverage

Or a test gas report:

yarn test:report-gas

Deploy contracts

Follow the instructions below to deploy your contracts:

In the project root folder:

  1. Add your environment variables in the .env file.

    nota

    You should at least set a valid Infura API Key (you could use Alchemy as well) and a private key with some ethers.

  2. Go to the apps/contracts folder and deploy your contract.

    yarn deploy --semaphore <semaphore-address> --group <group-id> --network sepolia
    nota

    Check the Semaphore contract addresses here.

    precauci贸n

    The group id is a number.

Start app

Start the application:

yarn dev
informaci贸n

If you want to see the code of a comprehensive application built on top of Semaphore see the boilerplate. For more info about the core libraries, keep reading the next guides.