Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 34쪽

n data The key that lets you find and decrypt your own notes, and lets others send to you. Starkzap derives it from your signing key rather than storing it, so it survives a wallet reinstall with nothing to back up. The pool keeps the first key an account registers and it cannot be replaced. ### Proving service **Web2 Equivalent:** An external service that notarizes a claim The remote service that builds the cryptographic proof for each private transaction. It also screens deposits. Named `prover` in configuration. ### Discovery service **Web2 Equivalent:** A search index over encrypted data The service that indexes encrypted on-chain state so your wallet can find its own notes. Named `discovery` in configuration. ### Relayer **Web2 Equivalent:** A courier who posts your letter for you The party that submits your private transaction. Because the relayer sends it, the relayer's address appears on-chain instead of yours — that is what keeps your account off-chain. Distinct from the **forwarder**, which is the party that receives the fee. ### Pool fee **Web2 Equivalent:** A service charge, separate from postage A fee the pool charges, withdrawn from your private balance inside the proof. It is separate from gas, and transaction simulation does not include it — so quote it and show it to users explicitly. ### Screening **Web2 Equivalent:** A sanctions check at account opening A check the proving service runs against deposit sources before producing a proof. A rejection is final; if screening is unavailable, deposits fail closed rather than proceeding unchecked. ## Common Patterns ### Checking a Balance **Web2 Equivalent:** `SELECT balance FROM accounts WHERE user_id = ?` ```typescript theme={null} const balance = await wallet.balanceOf(STRK); // Like: const balance = await db.query('SELECT balance...'); ``` ### Sending Tokens **Web2 Equivalent:** `UPDATE accounts SET balance = balance - amount WHERE user_id = ?` ```typescript theme={null} await wallet.transfer(STRK, [{ to: recipient, amount }]); // Like: await paymentService.sendMoney(userId, recipientId, amount); ``` ### Waiting for Confirmation **Web2 Equivalent:** Polling an API until a job completes ```typescript theme={null} const tx = await wallet.transfer(...); await tx.wait(); // Wait for blockchain confirmation // Like: await pollUntilComplete(jobId); ``` ## Still Confused? If you're still unsure about a term, think of it this way: * **Blockchain** = A distributed database that everyone can read/write * **Wallet** = A user account on that database * **Transaction** = A write operation to that database * **Token** = A number in that database representing value The SDK abstracts away most of the complexity—you mostly just need to know: 1. Connect a wallet (like logging in) 2. Check balances (like querying a database) 3. Send tokens (like making an API call) # Installation Source: https://docs.starknet.io/build/starkzap/installation Install Starkzap and its dependencies ## Installation Install Starkzap using npm or yarn: ```bash theme={null} npm install starkzap ``` or ```bash theme={null} yarn add starkzap ``` <Info> Building for React Native/Expo? Use [React Native Integration](/build/starkzap/react-native) and install `starkzap-native` instead of using `starkzap` directly in your mobile app. </Info> ### Dependencies The SDK depends on: * [`starknet`](https://www.npmjs.com/package/starknet) (v10+) - Starknet.js core library * `@starknet-io/starknet-types-0103` - RPC spec 0.10.3 type declarations, referenced by Starkzap's published types Both are installed automatically when you install `starkzap`. #### Peer dependencies by feature All peer dependencies are **optional** to keep the package lean. Install only what you need: | Feature | Included in | Peer Dependencies | | - | - | - | | **Ethereum bridging** (deposit / withdraw to Ethereum) | `starkzap`,<br />`starkzap-native` | `ethers@^6.16.0` | | **Solana bridging** (deposit / withdraw to Solana via Hyperlane) | `starkzap`,<br />`starkzap-native` | `@solana/web3.js@^1.98.4`, `@hyperlane-xyz/sdk@^14.4.0`, `@hyperlane-xyz/registry@^19.4.0`, `@hyperlane-xyz/utils@^14.4.0` | | **Cartridge Controller wallet** (web-only) | `starkzap` | `@cartridge/controller@^0.13.13` | | **AVNU swaps & DCA** (`AvnuSwapProvider`, `AvnuDcaProvider`) | `starkzap`,<br />`starkzap-native` | `@avnu/avnu-sdk@^4.2.0` | | **Tongo confidential transfers** | `starkzap`,<br />`starkzap-native` | `@fatsolutions/tongo-sdk@^1.5.0` | | **STRK20 privacy pool** | `starkzap`,<br />`starkzap-native` | `@starkware-libs/starknet-privacy-sdk@^0.14.3-rc.5` — see [the extra setup below](#strk20-privacy-pool) | | **React Native / Expo** | `starkzap-native` | `react-native-get-random-values@^1.11.0`, `fast-text-encoding@^1.0.6`, `@ethersproject/shims@^5.7.0`, `buffer@^6.0.3` | <Note> Two features are reached through their own entry points rather than the package root: **Cartridge** from `starkzap/cartridge`, and the **STRK20 privacy pool** from `starkzap/privacy` (`starkzap-native/privacy` on React Native). Their types name the optional peer, and carrying them on the root entry would make that peer mandatory for everyone — so the subpath is what keeps it optional. Everything else, bridging and Tongo included, imports from the root. </Note> <Note> These are the ranges Starkzap declares as peer dependencies. Installing an older minor within the same major (`ethers@6.0.0`, say) satisfies the docs but not the peer range, and npm reports a conflict — so install at least the versions listed. </Note> ```bash theme={null} # Ethereum bridging npm install ethers # Solana bridging npm install @solana/web3.js @hyperlane-xyz/sdk @hyperlane-xyz/registry @hyperlane-xyz/utils # Cartridge Controller (only for Web) npm install @cartridge/controller # AVNU swaps & DCA (only needed for AvnuSwapProvider / AvnuDcaProvider; Ekubo needs nothing extra) npm install @avnu/avnu-sdk # Tongo confidential transfers npm install @fatsolutions/tongo-sdk # React Native / Expo (use starkzap-native instead of starkzap) npm install starkzap-native react-native-get-random-values fast-text-encoding @ethersproject/shims buffer ``` #### STRK20 privacy pool The privacy SDK is not on npm, so it needs two extra steps before `npm install` works. <Warning> Installing the SDK is not enough to deposit. Deposit screening runs through Elliptic under a StarkWare API key, so the proving service that performs it is not public — contact StarkWare for deposit access. Transfers, withdrawals, and the discovery service can be self-hosted. See [STRK20 privacy pool](/build/starkzap/privacy/strk20). </Warning> Point the `@starkware-libs` scope at GitHub Packages 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} # STRK20 privacy pool (requires Node 24+) npm install @starkware-libs/starknet-privacy-sdk ``` <Note> Node 24 or later is required for the WebCrypto APIs the OHTTP transport relies on. This is not enforced by the installer, so an older Node fails at runtime rather than at install time. </Note> ## Next Steps Once installed, configure the SDK: 1. Set up [Configuration](/build/starkzap/configuration) for networks, RPC providers, and optional features 2. If you are building a mobile app, follow [React Native Integration](/build/starkzap/react-native) for `starkzap-native` + Metro setup 3. Then check out the [Quick Start Guide](/build/starkzap/quick-start) to get your first wallet integration working in minutes # AVNU Paymaster Source: https://docs.starknet.io/build/starkzap/integrations/avnu-paymaster Paymaster integration for covering transaction gas costs on behalf of users <img alt="AVNU Paymaster integration hero" /> ## Overview [AVNU Paymaster](https://docs.avnu.fi/docs/paymaster/index) enables two modes of gas payment on Starknet: * **Gasfree**: You sponsor all gas costs for your users * **Gasless**: Users pay gas in any supported token (USDC, USDT, etc.) instead of STRK AVNU pioneered paymaster on Starknet and powers 50+ dApps. Starkzap integrates seamlessly with AVNU Paymaster for sponsored transactions. <Info> **For complete setup instructions and detailed configuration**, see the [Paymasters Guide](/build/starkzap/paymasters) which covers both AVNU Paymaster and Cartridge's built-in paymaster with step-by-step instructions, code examples, and best practices. </Info> ## Quick Reference ### When to Use AVNU Paymaster * ✅ Using **Privy** strategy for wallet connection * ✅ Using **Private Key** strategy (server-side) * ✅ Want to sponsor all gas fees for users (gasfree mode) * ✅ Want users to pay gas in tokens instead of STRK (gasless mode) ### Basic Configuration ```typescript theme={null} import { StarkZap } from "starkzap"; const sdk = new StarkZap({ network: "mainnet", paymaster: { nodeUrl: "https://starknet.paymaster.avnu.fi", headers: { "x-paymaster-api-key": "your-api-key-here" }, }, }); ``` ### Supported Tokens (Gasless Mode) USDC, USDT, DAI, ETH, STRK, WBTC, solvBTC, LBTC, EKUBO, NSTR, LORDS, wstETH, and more. ## Resources * [Paymasters Guide](/build/starkzap/paymasters) - Complete setup and configuration guide * [AVNU Paymaster Documentation](https://docs.avnu.fi/docs/paymaster/index) * [AVNU Portal](https://portal.avnu.fi) - Get your API key * [Propulsion Program](https://docs.avnu.fi/docs/paymaster/propulsion-program) - Gas subsidies up to \$1M # Cartridge Controller Source: https://docs.starknet.io/build/starkzap/integrations/cartridge-controller Use Cartridge Controller with network-safe session configuration <img alt="Cartridge controller integration hero" /> ## Overview [Cartridge Controller](https://docs.cartridge.gg/controller/overview) is specialized for gaming applications and provides a powerful abstraction layer for managing account access and ownership on Starknet. Cartridge enables: * **Social Login**: Users can sign in with social accounts (Google, Twitter, etc.) * **Passkey Authentication**: Biometric authentication (Face ID, Touch ID, Windows Hello) * **Policy-Based Access**: Define policies for what contracts/methods can be called * **Delegated Transactions**: Users can approve transactions without managing keys directly * **Built-in Paymaster**: **Policy-bound sponsorship** — Cartridge can sponsor fees for calls that match **approved policies** (and eligible session / SNIP-9 paths), not every arbitrary transaction. Starkzap integrates with Cartridge for gaming-style flows: **web** uses `@cartridge/controller`; **React Native / Expo** uses `starkzap-native` with a **native session adapter** (register it before connecting) when your package version supports native Cartridge. ## StarkZap integration When StarkZap connects Cartridge, it forwards your SDK network configuration (for example `rpcUrl` and `chainId`) into the Cartridge flow so you typically configure the network once on `new StarkZap(...)`. <Warning> **Network alignment is not auto-validated.** You must use the same `rpcUrl` / `chainId` (or `network` preset) you intend the Cartridge session and paymaster to target. The SDK forwards these values but does **not** verify that some other tab, deep link, or preset was opened on a different chain. Mismatches often show up as SNIP-9 or paymaster errors. </Warning> You do not need to pass chain settings again when calling `sdk.connectCartridge()` or `sdk.onboard({ strategy: "cartridge" })` on the same `StarkZap` instance. ## Web (browser) vs React Native | | **Web** | **React Native / Expo** | | - | - | - | | Package | `starkzap` + `@cartridge/controller` | `starkzap-native` (depends on `starkzap`) | | UX | Controller popup / embedded flow | In-app browser / deep link **session** flow | | Before connect | Install `@cartridge/controller` | [React Native setup](/build/starkzap/react-native): Metro `withStarkzap`, **register** the native Cartridge adapter when your SDK version exports it | | Import | `import { StarkZap } from "starkzap"` | `import { StarkZap } from "starkzap-native"` | ## React Native / Expo (native Cartridge session) 1. Follow [React Native Integration](/build/starkzap/react-native) for Metro (`withStarkzap`) and dependencies. 2. **Register** the native Cartridge adapter once at startup before `connectCartridge` / `onboard({ strategy: "cartridge" })` (for example `registerCartridgeTsAdapter` / `registerCartridgeNativeAdapter` — exact exports depend on your `starkzap-native` version). 3. Pass **policies** and/or a Cartridge **preset** that resolves policies for your chain. 4. **Onboarding:** native Cartridge often defaults to **`deploy: "never"`** or recommends it when deployment differs from the browser Controller; pass `deploy: "if_needed"` explicitly if you need core-style deployment checks. 5. **Sponsored execution** on native is tied to the session wallet (commonly **`feeMode: { type: "paymaster" }`** only; `gasToken` is not supported on native Cartridge). See the `examples/tic-tac-toe` app in the [Starkzap repository](https://github.com/keep-starknet-strange/starkzap) when available for a full Expo reference. ## Why Use Cartridge? * ✅ **Perfect for Gaming**: Specialized for gaming applications with session-based transactions * ✅ **Gasless-style UX for approved calls**: Built-in paymaster can sponsor **policy-matching** transactions after users approve policies * ✅ **Better UX**: No seed phrases or private key management * ✅ **Social Login**: Users sign in with familiar accounts (Google, Twitter, etc.) * ✅ **Biometric Auth**: Face ID, Touch ID, Windows Hello support * ✅ **Policy Control**: Define what contracts/methods users can interact with * ✅ **Session Management**: Users approve policies once, then transactions happen automatically <Info> **Key value:** Unlike Privy or private-key flows (which often use AVNU Paymaster for sponsorship), Cartridge can sponsor **policy-approved** calls through its paymaster/session stack—so matching game or token operations stay gasless after users approve policies. Other calls may still require user fees or extra steps. </Info> ## Setup (web browser) ### 1. Install Cartridge Controller For **web**, install the Controller peer used by `starkzap`: ```bash theme={null} npm install @cartridge/controller ``` ### 2. Initialize SDK ```typescript theme={null} import { StarkZap, OnboardStrategy } from "starkzap"; const sdk = new StarkZap({ network: "mainnet" }); ``` ## Integration (web) ### Basic Connection Connect a wallet using Cartridge Controller. Define policies that specify what contracts/methods can be called, and all matching transactions will be automatically sponsored (gasless) by Cartridge's built-in paymaster: ```typescript theme={null} const onboard = await sdk.onboard({ strategy: OnboardStrategy.Cartridge, cartridge: { policies: [ { target: "0xTOKEN_CONTRACT", method: "transfer", }, { target: "0xGAME_CONTRACT", method: "play_card", }, ], }, deploy: "if_needed", }); const wallet = onboard.wallet; ``` ### Using Policies Policies define what contracts and methods can be called in paymastered transactions. Users approve these policies once when connecting, and then all transactions matching those policies are automatically sponsored by Cartridge's paymaster: ```typescript theme={null} const policies = [ // Allow transfers from a specific token contract { target: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", // STRK method: "transfer", }, // Allow game operations { target: "0xGAME_CONTRACT", method: "play_card", }, { target: "0xGAME_CONTRACT", method: "claim_rewards", }, // Allow staking operations { target: "0xSTAKING_CONTRACT", method: "enter_delegation_pool", }, ]; const wallet = await sdk.connectCartridge({ policies }); // All transactions matching these policies are automatically paymastered // No user approval needed for individual transactions ``` ### Session Registration When users connect and approve policies, a session is automatically registered. For paymastered transactions, sessions can be registered without requiring additional signatures—the initial policy approval is sufficient. This enables seamless, gasless transaction execution: ```typescript theme={null} // User connects and approves policies const onboard = await sdk.onboard({ strategy: OnboardStrategy.Cartridge, cartridge: { policies }, }); // Session is automatically registered // All transactions matching policies are paymastered automatically const wallet = onboard.wallet; // Execute transactions - no approval prompts, no gas fees await wallet.execute([call]); ``` ### Accessing Controller Features Get access to Cartridge-specific features: ```typescript theme={null} const wallet = await sdk.connectCartridge({ policies }); // Access the controller const controller = wallet.getController(); // Open user profile controller.openProfile(); // Check if user is authenticated const isAuthenticated = controller.isAuthenticated(); ``` ## Complete Example ```typescript theme={null} import { StarkZap, OnboardStrategy, Amount, fromAddress, mainnetTokens } from "starkzap"; const sdk = new StarkZap({ network: "mainnet" }); // Define policies for what the user can do // All transactions matching these policies will be automatically paymastered const policies = [ { target: mainnetTokens.STRK.address, method: "transfer", }, { target: "0xGAME_CONTRACT", method: "play_card", }, ]; // Connect with Cartridge // User approves policies once, session is registered automatically const onboard = await sdk.onboard({ strategy: OnboardStrategy.Cartridge, cartridge: { policies }, deploy: "if_needed", }); const wallet = onboard.wallet; // Use the wallet like any other const balance = await wallet.balanceOf(mainnetTokens.STRK); console.log(`Balance: ${balance.toFormatted()}`); // Transfer tokens - automatically paymastered (no approval, no gas fees) // Because it matches the approved policy const tx = await wallet.transfer(mainnetTokens.STRK, [ { to: fromAddress("0xRECIPIENT"), amount: Amount.parse("10", mainnetTokens.STRK), }, ]); await tx.wait(); console.log("Transfer complete! (Gas paid by Cartridge)"); ``` ## User Flow (web) 1. **User clicks "Connect with Cartridge"** 2. **Cartridge popup appears** with social login options 3. **User signs in** with Google, Twitter, or passkey 4. **Wallet is created** and connected automatically 5. **User approves policies** - Defines what contracts/methods can be called 6. **Session is registered** - Automatically registered for paymastered transactions 7. **Transactions execute automatically** - All transactions matching policies are paymastered (gasless) without additional approval ## Policy Management ### How Policies Work with Paymaster Policies serve two purposes: 1. **Security**: Define what contracts/methods can be called 2. **Paymaster eligibility**: Only transactions matching policies are automatically paymastered When a transaction matches an approved policy, it's automatically sponsored by Cartridge's paymaster. Transactions outside the policies require user approval and may not be paymastered. ### Dynamic Policies You can update policies based on user actions. Note that updating policies requires reconnection and user approval: ```typescript theme={null} // Initial connection with basic policies const wallet = await sdk.connectCartridge({ policies: [ { target: TOKEN_ADDRESS, method: "transfer" }, ], }); // Later, add more policies (requires reconnection and user approval) const updatedWallet = await sdk.connectCartridge({ policies: [ { target: TOKEN_ADDRESS, method: "transfer" }, { targ
프로젝트로 돌아가기