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/[email protected] create my-app
Otherwise, install @semaphore-protocol/cli
globally and run the create
command:
npm i -g @semaphore-protocol/[email protected]
semaphore create my-app
The semaphore CLI
can also be used to get group data from a supported network (e.g semaphore get-groups --network goerli
).
To start working on your project, install the dependencies:
- npm
- Yarn
cd my-app
npm i
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 that contract and some tests.
my-app
βββ contracts
βΒ Β βββ Greeter.sol
βββ .env.example
βββ .gitignore
βββ hardhat.config.ts
βββ package.json
βββ README.md
βββ tasks
βΒ Β βββ deploy.ts
βββ test
βΒ Β βββ Greeter.ts
βββ tsconfig.json
The Greeter.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 greeting.
Usageβ
Compileβ
Compile your contracts by running:
- npm
- Yarn
npm run compile
yarn compile
Testβ
Test your contracts by running:
- npm
- Yarn
npm test
yarn test
You can also generate a test coverage report:
- npm
- Yarn
npm run test:coverage
yarn test:coverage
Or a test gas report:
- npm
- Yarn
npm run test:report-gas
yarn test:report-gas
Deployβ
Follow the instructions below to deploy your contracts:
Copy the
.env.example
file as.env
.cp .env.example .env
Add your environment variables.
noteYou should at least set a valid Ethereum URL (e.g. Infura) and a private key with some ethers.
And deploy your contract.
- npm
- Yarn
npm run deploy -- --semaphore <semaphore-address> --group <group-id> --network goerli
yarn deploy --semaphore <semaphore-address> --group <group-id> --network goerli
noteCheck the Semaphore contract addresses here.
cautionThe group id is a number.