Semaphore Subgraph
The Graph is an indexing protocol for querying networks like Ethereum and IPFS. Our subgraphs allow you to get data from the Semaphore.sol smart contract. |
|---|
Networks
You can access any subgraph supported by Semaphore with the following URL: https://api.studio.thegraph.com/query/14377/semaphore-<network-name>/v4.5.0.
Supported networks:
sepoliaethereumoptimismoptimism-sepoliaarbitrumarbitrum-sepoliamaticmatic-amoybase-sepoliabaselinea-sepolialineascroll-sepoliagnosis-chiadognosis
🛠 Install
Clone this repository:
git clone https://github.com/semaphore-protocol/semaphore.git
and install the dependencies:
cd semaphore/apps/subgraph && yarn
Usage
The subgraph definition consists of a few files:
subgraph.template.yaml: a YAML file containing the subgraph manifest,schema.graphql: a GraphQL schema that defines what data is stored for the subgraph, and how to query it via GraphQL,src/semaphore.ts: AssemblyScript code that translates from the event data to the entities defined in the schema.
Code generation
Generate AssemblyScript types for the subgraph (required every time the schema changes):
yarn codegen <network>
It also generates a subgraph.yaml file for your specific network.
Testing
After generating the types and subgraph.yaml file, test your subgraph:
yarn test
Deployment
TheGraph Studio
Set the authorization code that links your account on thegraph.com:
yarn auth <access-token>
Deploy the subgraph to the TheGraph Studio:
yarn deploy <subgraph-name>
Local
Start services required for TheGraph node by running:
docker compose up
Start a local Hardhat node and deploy the Semaphore contract:
# CWD = /semaphore/packages/contracts
yarn start --hostname 0.0.0.0
yarn deploy --network localhost
Create the subgraph.yaml file for your local network and create/deploy your subgraph:
yarn codegen localhost
yarn create-local
yarn deploy-local
Once the subgraph is published it will start indexing. You can query the subgraph using the following GraphQL endpoint:
http://127.0.0.1:8000/subgraphs/name/semaphore/graphql