mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-04-28 03:00:41 -04:00
Semaphore data
A library to query Semaphore contracts.
This library allows you to query the Semaphore.sol contract data (i.e. groups) using the Semaphore subgraph or Ethers. It can be used on Node.js and browsers. |
|---|
🛠 Install
npm or yarn
Install the @semaphore-protocol/data package with npm:
npm i @semaphore-protocol/data
or yarn:
yarn add @semaphore-protocol/data
📜 Usage
# new SemaphoreSubgraph(networkOrSubgraphURL: Network | string = "goerli"): SemaphoreSubgraph
import { SemaphoreSubgraph } from "@semaphore-protocol/data"
const semaphoreSubgraph = new SemaphoreSubgraph()
// or:
const semaphoreSubgraph = new SemaphoreSubgraph("arbitrum")
// or:
const semaphoreSubgraph = new SemaphoreSubgraph(
"https://api.studio.thegraph.com/query/14377/<your-subgraph>/<your-version>"
)
# getGroupIds(): Promise<string[]>
const groupIds = semaphoreSubgraph.getGroupIds()
# getGroups(options?: GroupOptions): Promise<GroupResponse[]>
const groups = semaphoreSubgraph.getGroups()
// or
const groups = semaphoreSubgraph.getGroups({ members: true, verifiedProofs: true })
# getGroup(groupId: string, options?: GroupOptions): Promise
const group = semaphoreSubgraph.getGroup("42")
// or
const { members, verifiedProofs } = semaphoreSubgraph.getGroup("42", { members: true, verifiedProofs: true })
# new Ethers(networkOrEthereumURL: Network | string = "goerli", options: EthersOptions = {}): SemaphoreEthers
import { SemaphoreEthers } from "@semaphore-protocol/data"
const semaphoreEthers = new SemaphoreEthers()
// or:
const semaphoreEthers = new SemaphoreEthers("homestead", {
address: "semaphore-address",
startBlock: 0
})
// or:
const semaphoreEthers = new SemaphoreEthers("http://localhost:8545", {
address: "semaphore-address"
})
# getGroupIds(): Promise<string[]>
const groupIds = semaphoreEthers.getGroupIds()
# getGroup(groupId: string): Promise
const group = semaphoreEthers.getGroup("42")
# getGroupAdmin(groupId: string): Promise
const admin = semaphoreEthers.getGroupAdmin("42")
# getGroupMembers(groupId: string): Promise<string[]>
const members = semaphoreEthers.getGroupMembers("42")
# getGroupVerifiedProofs(groupId: string): Promise<any[]>
const verifiedProofs = semaphoreEthers.getGroupVerifiedProofs()