> For the complete documentation index, see [llms.txt](https://plabs.gitbook.io/plabs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plabs.gitbook.io/plabs-docs/guides/developer-guide.md).

# Developer integration guide

Integrate pERC20 into wallets, dApps, and backend services.

## Integration checklist

* [ ] Connect to correct chain (`chainId` in proofs = pool chain)
* [ ] Implement note scanning (`NoteAdded` + trial-decrypt)
* [ ] Integrate prover (rapidsnark service or WASM)
* [ ] Encode `PrivacyCall` / `BundleAction` (see `bundleCodec.ts`)
* [ ] Handle mint/burn public amounts vs private transfers
* [ ] Optional: relayer for submitter privacy
* [ ] Optional: indexer for faster sync
* [ ] Do **not** assume ERC-20 ABI compatibility

## Key libraries

| Task                | Reference                                              |
| ------------------- | ------------------------------------------------------ |
| ABI encode/decode   | `apps/web/src/issuance/bundleCodec.ts`                 |
| EVM reads           | `apps/web/src/crypto/evmRead.ts`                       |
| Witness build       | `crates/privacybtc-witness/`                           |
| Groth16 prove       | `crates/privacybtc-groth16/`, `privacy-prover` service |
| Contract interfaces | `contracts/interfaces/IPERC20.sol`                     |

## Contract addresses

Query factory → pool mapping on your target chain. Test env addresses in [Performance benchmarks](/plabs-docs/ecosystem/performance.md).

## Testing

```bash
# Unit tests
forge test --match-contract PERC20Test

# Real-proof E2E
forge test --match-contract PERC20E2ETest

# Full stack
e2e/scripts/run_full_e2e.sh
```

## Common pitfalls

| Pitfall                    | Fix                                                |
| -------------------------- | -------------------------------------------------- |
| Wrong `chainId` in sighash | Use pool's chain, not wallet network               |
| Trusting `NoteAdded` alone | Recipient must trial-decrypt to confirm            |
| On-chain `approve`         | Use wallet ZIP-32 flow; no contract method         |
| `pubFields` mismatch       | Must equal top-level calldata fields               |
| Skipping `< Fr` checks     | Reference impl enforces; match in custom verifiers |

## *(expand)*

* REST API for prover-service
* Indexer query schema
* Mobile / hardware wallet considerations

## Next

* [Off-chain services](/plabs-docs/ecosystem/off-chain-services.md)
* [Universal call format](/plabs-docs/privacy-core/universal-call-format.md)
* [ERC-8302](/plabs-docs/privacy-core/perc20/eip-8302.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://plabs.gitbook.io/plabs-docs/guides/developer-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
