|
49 | 49 | </h4>
|
50 | 50 | </div>
|
51 | 51 |
|
52 |
| -| This library provides tools for querying and interacting with the [`Semaphore.sol`](https://github.com/semaphore-protocol/semaphore/blob/main/packages/contracts/contracts/Semaphore.sol) smart contract. It supports both the Semaphore subgraph and direct Ethereum network connections via Ethers. Designed for use in both Node.js and browser environments, it facilitates the management of group data and verification processes within the Semaphore protocol. | |
53 |
| -| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 52 | +| This library provides tools for querying and interacting with the [`Semaphore.sol`](https://github.com/semaphore-protocol/semaphore/blob/main/packages/contracts/contracts/Semaphore.sol) smart contract. It supports the Semaphore subgraph and direct Ethereum network connections via Ethers or Viem. Designed for use in both Node.js and browser environments, it facilitates the management of group data and verification processes within the Semaphore protocol. | |
| 53 | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
54 | 54 |
|
55 | 55 | ## 🛠 Install
|
56 | 56 |
|
@@ -187,3 +187,59 @@ const isMember = await semaphoreEthers.isGroupMember(
|
187 | 187 | "16948514235341957898454876473214737047419402240398321289450170535251226167324"
|
188 | 188 | )
|
189 | 189 | ```
|
| 190 | + |
| 191 | +### Using Viem for Direct Blockchain Interaction |
| 192 | + |
| 193 | +**Initialize a Semaphore Viem instance** |
| 194 | + |
| 195 | +```typescript |
| 196 | +import { SemaphoreViem } from "@semaphore-protocol/data" |
| 197 | + |
| 198 | +const semaphoreViem = new SemaphoreViem() |
| 199 | + |
| 200 | +// or: |
| 201 | +const semaphoreViemOnSepolia = new SemaphoreViem("sepolia", { |
| 202 | + address: "semaphore-address", |
| 203 | + startBlock: 0n |
| 204 | +}) |
| 205 | + |
| 206 | +// or: |
| 207 | +const localViemInstance = new SemaphoreViem("http://localhost:8545", { |
| 208 | + address: "semaphore-address" |
| 209 | +}) |
| 210 | +``` |
| 211 | + |
| 212 | +With your SemaphoreViem instance, you can: |
| 213 | + |
| 214 | +**Fetch Group IDs** |
| 215 | + |
| 216 | +```typescript |
| 217 | +const groupIds = await semaphoreViem.getGroupIds() |
| 218 | +``` |
| 219 | + |
| 220 | +**Fetch Group Details** |
| 221 | + |
| 222 | +```typescript |
| 223 | +const group = await semaphoreViem.getGroup("42") |
| 224 | +``` |
| 225 | + |
| 226 | +**Fetch Group Members** |
| 227 | + |
| 228 | +```typescript |
| 229 | +const members = await semaphoreViem.getGroupMembers("42") |
| 230 | +``` |
| 231 | + |
| 232 | +**Fetch Validated Proofs** |
| 233 | + |
| 234 | +```typescript |
| 235 | +const validatedProofs = await semaphoreViem.getGroupValidatedProofs("42") |
| 236 | +``` |
| 237 | + |
| 238 | +**Check Group Membership** |
| 239 | + |
| 240 | +```typescript |
| 241 | +const isMember = await semaphoreViem.isGroupMember( |
| 242 | + "42", |
| 243 | + "16948514235341957898454876473214737047419402240398321289450170535251226167324" |
| 244 | +) |
| 245 | +``` |
0 commit comments