bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 37쪽
Program](https://docs.avnu.fi/docs/paymaster/propulsion-program) - Gas subsidies up to \$1M
* [starknet.js Paymaster Guide](https://starknetjs.com/docs/guides/account/paymaster)
</Tab>
<Tab title="Cartridge Paymaster">
Use Cartridge's paymaster when using the **Cartridge** wallet strategy (**web:** Controller; **React Native:** native session via `starkzap-native` when supported). Sponsorship is **policy-bound** — calls that match approved policies (and eligible session / SNIP-9 paths) can be paymastered; other calls may require user fees.
## When to Use Cartridge Paymaster
* ✅ Using **Cartridge** for wallet connection (web or native)
* ✅ Building gaming applications with explicit **policies** for contract calls
* ✅ Want paymastered execution for **matching** session calls after policy approval
* ✅ Want minimal extra paymaster configuration compared with AVNU for those paths
## How It Works
Cartridge combines sessions with a paymaster service so **approved** execution paths can be sponsored. This is not a guarantee that every arbitrary `execute()` is gasless — scope your **policies** to the calls you intend to sponsor.
### Session-Based Paymastered Transactions
According to the [Cartridge Controller architecture](https://docs.cartridge.gg/controller/architecture#how-paymastered-transactions-work), Cartridge uses session-based transactions with the paymaster:
1. **User approves policies once** - Defines what contracts/methods can be called
2. **Session is registered** - Can be registered without signature for eligible paymastered transactions
3. **Matching transactions** - When you call `account.execute()` for calls that fit the session / SNIP-9 flow:
* SDK validates the session is active
* Constructs an `OutsideExecution` message (meta-transaction via SNIP-9) where applicable
* Signs the message with the session key
* Sends the signed payload to Cartridge's paymaster service
* The paymaster may submit the transaction on-chain and pay gas fees
**React Native:** use [React Native Integration](/build/starkzap/react-native): Metro `withStarkzap` and **register** the native Cartridge adapter before connecting. Sponsored execution on native is often tied to **`feeMode: { type: "paymaster" }`** on the session wallet. Native Cartridge does not support `gasToken`.
### Policies for Paymaster
Policies define what contracts and methods can be called in paymastered transactions. Users approve these policies once when connecting; **calls that match** those policies can be sponsored:
```typescript theme={null}
const policies = [
{ target: "0xTOKEN_CONTRACT", method: "transfer" },
{ target: "0xGAME_CONTRACT", method: "play_card" },
{ target: "0xGAME_CONTRACT", method: "claim_rewards" },
];
```
Calls outside those policies are not guaranteed to be paymastered and may need user-paid fees or additional approval.
### Register Session Without Signature
For eligible paymastered transactions, sessions can sometimes be registered with reduced friction once policies are approved. Behavior can differ between **web** and **native** builds — follow [Cartridge Controller](/build/starkzap/integrations/cartridge-controller) and [React Native Integration](/build/starkzap/react-native).
```typescript theme={null}
const onboard = await sdk.onboard({
strategy: OnboardStrategy.Cartridge,
cartridge: {
policies: [
{ target: "0xTOKEN_CONTRACT", method: "transfer" },
],
},
// Native flows may default to deploy: "never"; pass deploy: "if_needed" if you need deployment checks
});
const wallet = onboard.wallet;
```
## Integration
Connect with Cartridge and define policies. **Matching** calls can be sponsored per Cartridge rules; on **native**, you may pass **`feeMode: { type: "paymaster" }`** where your wallet/session supports it.
```typescript theme={null}
import { StarkZap, OnboardStrategy } from "starkzap";
const sdk = new StarkZap({ network: "mainnet" });
const onboard = await sdk.onboard({
strategy: OnboardStrategy.Cartridge,
cartridge: {
policies: [
{ target: "0xTOKEN_CONTRACT", method: "transfer" },
{ target: "0xGAME_CONTRACT", method: "play_card" },
],
},
});
const wallet = onboard.wallet;
const tx = await wallet.execute([call]);
await tx.wait();
```
## Key Advantages
* ✅ **Low friction for games** - Policy-first flows after user approval
* ✅ **Session-based** - Approved paths can execute without a popup per tx
* ✅ **No AVNU key** for Cartridge-native sponsorship paths
* ✅ **Web and (when supported) React Native** - Same policy concepts; native needs adapter registration
## Comparison with AVNU Paymaster
| Feature | Cartridge Paymaster | AVNU Paymaster |
| - | - | - |
| **Setup** | Policies + Cartridge session | SDK `paymaster` config (+ API key for gasfree) |
| **API Key** | Not used for Cartridge path | Required for AVNU gasfree mode |
| **Use Case** | Gaming / session UX | Privy, private key, general sponsorship |
| **Strategy** | Cartridge (web or native) | Privy or Private Key (typical) |
| **Sponsorship scope** | Policy-matching session calls | Configured paymaster modes |
## Resources
* [Cartridge Controller Documentation](https://docs.cartridge.gg/controller/overview)
* [Cartridge Architecture](https://docs.cartridge.gg/controller/architecture#how-paymastered-transactions-work) - How paymastered transactions work
* [Cartridge Integration Guide](/build/starkzap/integrations/cartridge-controller) - Detailed integration instructions
</Tab>
</Tabs>
## Choosing the Right Paymaster
**Use AVNU Paymaster if:**
* You're using Privy or Private Key strategies
* You want control over gas sponsorship
* You need gasless mode (user pays in tokens)
**Use Cartridge Paymaster if:**
* You're using **Cartridge** (web Controller or native session)
* You're building gaming applications with **explicit policies**
* You want paymastered execution for **matching** session calls after policy approval
## Next Steps
* Learn about [AVNU Paymaster Integration](/build/starkzap/integrations/avnu-paymaster) for detailed setup
* Learn about [Cartridge Controller Integration](/build/starkzap/integrations/cartridge-controller) for gaming applications
* Configure your [SDK Configuration](/build/starkzap/configuration) with paymaster settings
# Choosing a privacy protocol
Source: https://docs.starknet.io/build/starkzap/privacy/overview
Starkzap supports two independent privacy protocols—the STRK20 privacy pool and Tongo. Compare what each hides and pick the right one for your integration.
## Overview
Starkzap supports two privacy protocols. They are **independent implementations, not two backends behind one interface** — they have different state models, different proving setups, and different submission paths. You pick one per integration and code against it directly.
* **[STRK20 privacy pool](/build/starkzap/privacy/strk20)** — one pool for every token. Your balance is a set of private **notes**. A remote proving service builds a proof, and a relayer submits it, so your account never appears on-chain.
* **[Tongo](/build/starkzap/privacy/tongo)** — one contract per token. Your balance is a single **encrypted number** on your own account. Proofs are generated locally, and you submit the transaction yourself.
The names matter more than the words "privacy" and "confidential", which are near-synonyms in English but point at different protocols here. Say **STRK20** or **Tongo**.
## Comparison
| | STRK20 privacy pool | Tongo |
| - | - | - |
| **Hides** | Amounts, sender, and recipient | Amounts |
| **State model** | Private notes you spend | One encrypted balance per account |
| **Contracts** | One pool, all tokens | One contract per token |
| **Proving** | Remote proving service | Local, in your process |
| **Submission** | The paymaster's relayer — your account stays off-chain | Your own account |
| **Batching** | Never — the proof belongs to the transaction | Yes, through `wallet.tx()` |
| **You get back** | `send()` executes and returns a transaction hash | `Call[]` that you batch and send |
| **Keys** | Viewing key derived from your signing key | A separate Tongo private key you hold |
| **Wallets** | Private-key login only | Any wallet |
| **Install** | GitHub Packages, auth required, Node 24+ | npm, no auth |
| **Status** | Prerelease. Deposits need StarkWare access; the rest is self-hostable | Available |
## Which one to use
**Choose STRK20** when you need to hide *who* transacts, not just how much. Because a relayer submits the transaction, the sender's address, nonce, and gas payment stay off-chain. That is the property Tongo does not offer.
**Choose Tongo** when hiding amounts is enough, and you want an integration you can ship today: it installs from npm with no access request, works with any wallet, proves locally with no external service, and batches with your other calls in a single transaction.
<Info>
Starkzap does not offer a shared abstraction over the two. Quoting the SDK itself: Tongo keeps an encrypted *balance* per account and proves locally, while the privacy pool spends *notes* and needs a remote prover whose output rides on the transaction rather than inside a call. There is no shared interface to code against.
</Info>
## What neither protocol hides
Both protocols privatize what happens *between* entering and leaving. Entering and leaving are public in both.
<Warning>
Deposits and withdrawals are public. Withdrawing to the address you deposited from puts both ends of the pool on one address, which is enough to link them — so a fresh address is what preserves the gap.
</Warning>
Neither protocol hides that you interacted with it at all, and neither hides the timing or the token. Treat them as tools for unlinking a source from a destination, not as cloaks over your whole on-chain history.
## Next steps
<CardGroup>
<Card title="STRK20 privacy pool" icon="user-secret" href="/build/starkzap/privacy/strk20">
Hide amounts, sender, and recipient. Notes, a remote prover, and relayer submission.
</Card>
<Card title="Tongo" icon="lock" href="/build/starkzap/privacy/tongo">
Hide amounts. Encrypted balances, local proving, batches with your other calls.
</Card>
</CardGroup>
# STRK20 privacy pool
Source: https://docs.starknet.io/build/starkzap/privacy/strk20
Deposit, transfer, and withdraw privately through the STRK20 privacy pool—private notes, a remote proving service, and relayer submission that keeps your account off-chain
## Overview
The **STRK20 privacy pool** is a single contract that holds balances for every token. Your balance in it is not a number on your account but a set of private **notes**, and you spend them by proving you own them rather than by signing a call.
<Warning>
**Deposits require access from StarkWare.** Every deposit is screened against sanctions lists through [Elliptic](https://www.elliptic.co/). That screening runs on credentials StarkWare administers, so the proving service behind it is not an open endpoint. Contact StarkWare to deposit.
Everything else you can run yourself. Transfers, withdrawals and the discovery service can be self-hosted from the open-source components. See [Running your own services](#running-your-own-services). The SDK is a prerelease (`0.14.x-rc`) published to GitHub Packages and requires Node 24 or later.
</Warning>
Three things make it different from every other Starkzap module:
* **A remote proving service** builds a validity proof for each private transaction. The proof travels as transaction-level fields, not inside a call, so a privacy operation can **never** be batched with other calls and cannot go through the [transaction builder](/build/starkzap/tx-builder).
* **A relayer submits it.** No user signature is involved. The pool authorises the transaction from the proof alone. Your address, nonce, and gas payment stay off-chain, unless you wrap public calls with `invoke`.
* **A viewing key**, derived from your signing key, lets you find your own notes and lets others send to you.
The client handles the fee, the proving block and the submission. So `send()` executes for you and returns a transaction hash. It does not return calls.
For how this compares to Tongo, see [Choosing a privacy protocol](/build/starkzap/privacy/overview).
## Prerequisites and installation
The privacy SDK is an optional peer dependency published to **GitHub Packages**, not npm. Point the `@starkware-libs` scope at that registry in your project's `.npmrc`:
```txt theme={null}
@starkware-libs:registry=https://npm.pkg.github.com
```
Reads require authentication even though the package is public. Put a token with `read:packages` in your **`~/.npmrc`** — never in the committed project file:
```txt theme={null}
//npm.pkg.github.com/:_authToken=YOUR_TOKEN
```
Then install:
```bash theme={null}
npm install @starkware-libs/starknet-privacy-sdk
```
<Note>
The OHTTP transport needs WebCrypto. On Node that means **Node 24 or later**. The installer does not enforce this, so an older Node fails at runtime. On **React Native**, Hermes provides no `crypto.subtle` at all, so OHTTP needs a library that supplies one; see [React Native](/build/starkzap/react-native).
</Note>
### Supported wallets
Privacy needs a **private-key login**. `connectPrivacy` takes a `Wallet` rather than a `WalletInterface`, because a Cartridge wallet cannot derive a viewing key at all.
The viewing key is derived from the account key **inside the signer**, so the signer has to implement `deriveViewingKey`. `StarkSigner` does. The Privy and Cartridge signers can only sign, so they cannot produce the key.
Starkzap refuses those signers **before any network call**. The user-facing reason, as the example app phrases it:
> The privacy pool needs a private-key login: the viewing key is derived from the account key inside the signer, which the Privy and Cartridge signers cannot do.
A custom signer opts in by implementing `deriveViewingKey`. `deriveAccountLeafViewingKey` implements the profile for you. It comes from the **root** entry, not `starkzap/privacy`, so a signer needs no privacy types:
```typescript theme={null}
import { deriveAccountLeafViewingKey, type ViewingKeyContext } from "starkzap";
class MySigner implements SignerInterface {
async deriveViewingKey(context: ViewingKeyContext): Promise<string> {
return deriveAccountLeafViewingKey(this.privateKey, context);
}
}
```
Failing that, supply your own `viewingKeyDerivation`.
## Configuration
Privacy lives at its own entry point, **`starkzap/privacy`**. Its config is passed to `connectPrivacy`, not to `StarkZap`. `poolContractAddress`, `prover`, `discovery` and `paymaster` are required. `connectPrivacy` throws without a paymaster.
<Note>
Import from `starkzap/privacy`, not from the root. The privacy types name the privacy SDK, which is an optional peer. Exporting them from the root would make that peer mandatory for everyone.
</Note>
```typescript theme={null}
import { StarkZap } from "starkzap";
import { connectPrivacy } from "starkzap/privacy";
const sdk = new StarkZap({ network: "mainnet" });
const wallet = await sdk.connectWallet({ account: { signer } });
const privacy = await connectPrivacy(wallet, {
poolContractAddress: POOL,
prover: PROVER,
discovery: DISCOVERY,
paymaster: {
url: "https://my-app.example.com/api/paymaster/mainnet",
fee: { mode: "sponsored" },
// Ceiling on what one quote may withdraw for its fee, in base units of the
// fee token, and the forwarder addresses allowed to receive it. Both come
// from your paymaster operator.
maxFee: 10n ** 19n,
allowedFeeRecipients: [FORWARDER],
},
});
```
`connectPrivacy` caches one client per wallet, so repeated calls are cheap and the user is asked to sign once. A failure is not cached, so you can retry after fixing the cause. Later calls return the cached client and ignore the config you pass them.
| Field | Required | Purpose |
| - | - | - |
| `poolContractAddress` | Yes | The pool contract. Folded into the viewing key as a felt, so `0x040…` and `0x40…` are the same pool. |
| `prover` | Yes | Proving service base URL, or a `ProofProviderInterface` instance. A prover you host covers transfers and withdrawals. **Deposits** also need the screening step, which only StarkWare's prover performs. |
| `discovery` | Yes | Discovery service base URL, or a `DiscoveryProviderInterface` instance. You can host this yourself. |
| `paymaster` | In practice | Where and how private transactions are submitted. See the table below. |
| `ohttp` | No | Envelope-encrypts requests to the two services. Defaults to on. |
| `viewingKeyDerivation` | No | Replace the default derivation scheme. |
The `paymaster` block:
| Field | Required | Purpose |
| - | - | - |
| `url` | Yes | Endpoint that submits private transactions. Point it at a proxy that holds your API key, not at the paymaster directly. Use one proxy per network, because each AVNU deployment whitelists only its own pool. |
| `fee` | Yes | How the pool fee is paid. There is no default. See [Fee modes](#fee-modes). |
| `tip` | No | Transaction priority: `"slow"`, `"normal"`, or `"fast"`. AVNU fills in `"normal"` when omitted. |
| `maxFee` | Yes | Refuse a quote whose fee exceeds this, in base units of the fee token. This is the only limit on what a bad endpoint can withdraw from your shielded balance. There is no default. Size it for your fee mode, see [Fee modes](#fee-modes). |
| `allowedFeeRecipients` | Yes | Forwarder addresses allowed to receive the fee. A quote naming any other address is refused. An empty list refuses every quote. Get the address from your paymaster operator, per network, and update it when they rotate the forwarder. Compared by value, so padding does not matter. |
| `fetch` | No | Transport override. Defaults to the global `fetch`. Wrap it to add auth headers, cookies, retries, a timeout or tracing. |
There are **no built-in per-network presets** for the pool or the services. Supply them per chain yourself.
### Running your own services
Both services are open source, so `prover` and `discovery` can point at infrastructure you operate.
| Component | Where to get it |
| - | - |
| Discovery service | [`deploy/discovery-service/`](https://github.com/starkware-libs/starknet-privacy/tree/main/deploy/discovery-service) in the protocol repo — Dockerfile plus local and multi-platform build instructions. The service itself is [`crates/discovery-service/`](https://github.com/starkware-libs/starknet-privacy/tree/main/crates/discovery-service). |
| Proving service | [`snip-36-prover-backend`](https://github.com/starknet-innovation/snip-36-prover-backend) — proves [SNIP-36](https://community.starknet.io/t/snip-36-in-protocol-proof-verification/116123) virtual-block execution with the stwo-cairo prover, which is the mechanism the pool's proofs use. |
Deposits are the exception. The prover does not screen deposits itself. It calls a [`proof-interceptor`](https://github.com/starkware-libs/starknet-privacy/tree/main/proof-interceptor) sidecar, which sends each deposit address to an [`elliptic-proxy`](https://github.com/starkware-libs/starknet-privacy/tree/main/elliptic-proxy) that holds Elliptic credentials. The client does not see the screening. An allowed transaction returns a proof as usual. A blocked one returns JSON-RPC error `10000`. Running that path needs Elliptic access, which StarkWare provides when it onboards you.
<Note>
The prover backend lives under a different organisation and describes itself as developer tooling, so treat it as a reference implementation rather than a supported production deployment. Check that its API matches the `prover` contract your SDK version expects before relying on it.
</Note>
### Keep OHTTP on
<Warning>
With `ohttp` disabled, your viewing key reaches the proving and discovery services in plaintext — inside TLS, but readable by whoever operates them. Turn it off only if the server does not s프로젝트로 돌아가기