mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-09 14:48:12 -05:00
143 lines
3.5 KiB
Plaintext
143 lines
3.5 KiB
Plaintext
---
|
|
sidebar_position: 2
|
|
---
|
|
|
|
# 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:
|
|
|
|
```bash
|
|
npx @semaphore-protocol/cli create my-app --template monorepo-ethers
|
|
```
|
|
|
|
Otherwise, install `@semaphore-protocol/cli` globally and run the `create` command:
|
|
|
|
```bash
|
|
npm i -g @semaphore-protocol/cli
|
|
semaphore create my-app --template monorepo-ethers
|
|
```
|
|
|
|
:::info
|
|
The supported templates are: [`contracts-hardhat`](https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli-template-contracts-hardhat), [`monorepo-ethers`](https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli-template-monorepo-ethers), [`monorepo-subgraph`](https://github.com/semaphore-protocol/semaphore/tree/main/packages/cli-template-monorepo-subgraph).
|
|
:::
|
|
|
|
:::info
|
|
The [`semaphore CLI`](https://github.com/semaphore-protocol/semaphore/tree/main/packages/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:
|
|
|
|
```bash
|
|
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:
|
|
|
|
```bash
|
|
cd apps/contracts
|
|
```
|
|
|
|
And compile your contracts:
|
|
|
|
```bash
|
|
yarn compile
|
|
```
|
|
|
|
### Test contracts
|
|
|
|
Test your contracts:
|
|
|
|
```bash
|
|
yarn test
|
|
```
|
|
|
|
Generate a test coverage report:
|
|
|
|
```bash
|
|
yarn test:coverage
|
|
```
|
|
|
|
Or a test gas report:
|
|
|
|
```bash
|
|
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.
|
|
|
|
:::note
|
|
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.
|
|
|
|
```bash
|
|
yarn deploy --semaphore <semaphore-address> --network sepolia
|
|
```
|
|
|
|
:::note
|
|
Check the Semaphore contract addresses [here](/deployed-contracts).
|
|
:::
|
|
|
|
:::caution
|
|
The group id is a number.
|
|
:::
|
|
|
|
### Start app
|
|
|
|
Start the application:
|
|
|
|
```bash
|
|
yarn dev
|
|
```
|
|
|
|
:::info
|
|
If you want to see the code of a comprehensive application built on top of Semaphore see the [boilerplate](https://github.com/semaphore-protocol/boilerplate/tree/main). For more info about the core libraries, keep reading the next guides.
|
|
:::
|