Skip to main content
Version: next

Subgraph

The Graph is a protocol for indexing networks like Ethereum and IPFS. Site owners publish subgraphs that expose site data for anyone to query. UniRep's subgraph allows you to retrieve data from the Unirep.sol smart contract.

info

The Graph protocol uses the GraphQL query language. For examples, see the GraphQL API documentation.

Deployment

UniRep subgraph version 2.0.0 is deployed on the following networks:

NetworkAPI
Sepoliahttps://api.studio.thegraph.com/query/48080/sepolia/v2.0.0
Arbitrum SepoliaNOT SUPPORTED YET
Avalanche Fujihttps://api.studio.thegraph.com/query/48080/fuji/v2.0.0

Query Examples

  1. Query the first 100 attesters (by default, sorted by id).
info

id is computed by

event.transaction.hash.concatI32(event.logIndex.toI32())
query MyQuery {
attesters {
attesterId
blockNumber
epochLength
startTimestamp
transactionHash
}
}
  1. Query the first 100 users from a certain attester ID (by default, sorted by id).
query MyQuery {
users(
where: {
attesterId: "812064237485286466066480536294992408637941768146"
}
) {
commitment
}
}
  1. Query the first 100 state tree leaves, sorted by index.
query MyQuery {
stateTreeLeaves(
orderBy: index
where: {
attesterId: "812064237485286466066480536294992408637941768146"
epoch: "1"
}
) {
leaf
}
}
  1. Query the first 1000 state tree leaves, sorted by index.
query MyQuery {
stateTreeLeaves(
first: 1000
orderBy: index
where: {
attesterId: "812064237485286466066480536294992408637941768146"
epoch: "1"
}
) {
leaf
}
}
  1. Query the next 1000 state tree leaves, sorted by index.
query MyQuery {
stateTreeLeaves(
skip: 1000
first: 1000
orderBy: index
where: {
attesterId: "812064237485286466066480536294992408637941768146"
epoch: "1"
}
) {
leaf
}
}

Schema

Attestation

  • id: An id to avoid data collision
  • epoch: The epoch in which an attestation occurred
  • epochKey: The receiver's epoch key
  • attesterId: The attester address
  • fieldIndex: The index of the data field that was changed
  • change: The change number of the data
  • blockNumber: The block number in which the attestation transaction occurred
  • blockTimestamp: The timestamp of the block in which the attestation transaction occurred
  • transactionHash: The attestation transaction hash

StateTreeLeaf

  • id: An id to avoid data collision
  • epoch: The epoch in which the state tree leaf was emitted
  • leaf: The emitted state tree leaf
  • index: The index of the state tree leaf in the epoch
  • attesterId: The attester address
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

EpochTreeLeaf

  • id: An id to avoid data collision
  • epoch: The epoch in which the epoch tree leaf was emitted
  • leaf: The emitted epoch tree leaf
  • index: The index of the epoch tree leaf in the epoch
  • attesterId: The attester address
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

HistoryTreeLeaf

  • id: An id to avoid data collision
  • leaf: The emitted history tree leaf
  • attesterId: The attester address
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

Epoch

  • id: An id to avoid data collision
  • number: The number of the ended epoch
  • attesterId: The attester address
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

Nullifier

  • id: An id to avoid data collision
  • epoch: The epoch in which the nullifier was emitted
  • attesterId: The attester address
  • nullifier: The nullifier that was used to prevent a double user state transition
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

User

  • id: An id to avoid data collision
  • commitment: The Semaphore identity commitment
  • epoch: The epoch in which the user signed up
  • attesterId: The address of the attester the user signed up to
  • leafIndex: The state tree leaf of the signup event
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash

Attester

  • id: An id to avoid data collision
  • attesterId: The attester address
  • startTimestamp: The start time of the attester's first epoch
  • epochLength: The length of the attester's epochs
  • blockNumber: The block number in which the transaction occurred
  • blockTimestamp: The timestamp of the block in which the transaction occurred
  • transactionHash: The transaction hash