bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 33쪽
s`:
```typescript theme={null}
const sdk = new StarkZap({
rpcUrl: RPC_URL,
chainId: SDK_CHAIN_ID,
bridging: {
ethereumRpcUrl: `https://eth-mainnet.g.alchemy.com/v2/${VITE_ALCHEMY_API_KEY}`,
solanaRpcUrl: `https://solana-mainnet.g.alchemy.com/v2/${VITE_ALCHEMY_API_KEY}`,
layerZeroApiKey: VITE_OFT_PUBLIC_KEY,
layerswapApiKey: VITE_LAYERSWAP_API_KEY,
},
});
```
### Key Code Snippets
**Connecting with Cartridge:**
```typescript theme={null}
const onboard = await sdk.onboard({
strategy: OnboardStrategy.Cartridge,
deploy: "never",
cartridge: { policies: [DUMMY_POLICY] },
});
wallet = onboard.wallet;
```
**Connecting with Privy:**
```typescript theme={null}
const accessToken = await privy.getAccessToken();
const walletRes = await fetch(`${PRIVY_SERVER_URL}/api/privy-wallet/starknet`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
});
const { wallet: walletData } = await walletRes.json();
const onboard = await sdk.onboard({
strategy: OnboardStrategy.Privy,
deploy: "never",
accountPreset: preset,
privy: {
resolve: async () => ({
walletId: walletData.id,
publicKey: walletData.publicKey,
serverUrl: `${PRIVY_SERVER_URL}/api/privy-wallet/sign`,
}),
},
});
wallet = onboard.wallet;
```
**Executing a Transaction:**
```typescript theme={null}
const tx = await wallet.execute([
{
contractAddress: STRK_CONTRACT,
entrypoint: "transfer",
calldata: [wallet.address, "0", "0"],
},
]);
await tx.wait();
```
</Tab>
<Tab title="Mobile App">
The mobile example is a React Native + Expo app covering the same ground as the web example, organised as eight feature tabs. Connect with **Privy** (social login) or a **private key**. It consumes the native package via `"starkzap-native": "file:../../packages/native"`.
### What the example does
* **Onboarding** — Sign in with Privy (email, Google, etc.) or paste a Starknet private key; choose Mainnet or Sepolia.
* **Balances** — View STRK, USDC, WBTC (and network-specific tokens) with optional USD conversion.
* **Transfers** — Single and batch ERC20 transfers with amount input and explorer links.
* **Staking** — Enter delegation pools, add to stake, claim rewards, exit (intent + complete).
* **Yield** — LST staking positions.
* **Swap** — Token swaps and DCA orders.
* **Lending** — Supply, borrow, and repay with Vesu.
* **Bridge** — Deposits from Ethereum and Solana, and withdrawals out of Starknet.
* **Privacy** — Both the [STRK20 pool](/build/starkzap/privacy/strk20) and [Tongo](/build/starkzap/privacy/tongo), selected with a toggle.
* **UX** — Themed light/dark UI, transaction toasts with explorer links, copyable errors, logs FAB.
### Configure environment (required for Privy)
**`You must set up .env before running`**, or the app will show a **"Configuration required"** screen with instructions.
1. Copy the example env file: `cp .env.example .env`
2. Edit `examples/mobile/.env` and set at least:
| Variable | Required | Description |
| - | - | - |
| `EXPO_PUBLIC_PRIVY_APP_ID` | Yes (for Privy) | From [Privy Dashboard](https://dashboard.privy.io) → your app → App ID |
| `EXPO_PUBLIC_PRIVY_CLIENT_ID` | Optional | From Privy Dashboard → Clients |
| `EXPO_PUBLIC_PRIVY_SERVER_URL` | Optional | Your backend URL for server-side signing (e.g. `http://localhost:3001`) |
| `EXPO_PUBLIC_PAYMASTER_PROXY_URL_MAINNET` / `_SEPOLIA` | Optional | Paymaster proxy per network, e.g. `http://localhost:3001/api/paymaster/mainnet`. Per network because each AVNU deployment whitelists only its own pool, and one build switches chains at runtime |
Without `EXPO_PUBLIC_PRIVY_APP_ID`, the app still runs but **Privy login is disabled**; you can use the **private key** flow only.
**Privy Dashboard (Expo Go):** If you use Expo Go and see "Native app ID `host.exp.Exponent` has not been set as an allowed app identifier", add `host.exp.Exponent` in [Privy Dashboard](https://dashboard.privy.io) → **Configuration → App settings → Clients** → **Allowed app identifiers**. **OAuth (Google, Apple, etc.):** Enable login methods and set [allowed URL schemes](https://docs.privy.io/basics/get-started/dashboard/app-clients#allowed-url-schemes) for redirects.
### Getting Started
Install at the **repository root** first, then in the example:
```bash theme={null}
npm install
cd examples/mobile
npm install
npx expo start
```
Then open the app in the iOS simulator, Android emulator, or Expo Go (scan QR code). If `.env` is not configured, you'll see the "Configuration required" screen.
**Optional: Privy server** — For server-side signing, run `examples/server`, then set `EXPO_PUBLIC_PRIVY_SERVER_URL` in `examples/mobile/.env` to that server URL (e.g. `http://localhost:3001`).
### Project Structure
```
examples/mobile/src/
+-- app/ # Expo Router pages
| +-- index.tsx # Onboarding (Privy / private key)
| `-- (tabs)/ # Tab navigation
| +-- balances.tsx
| +-- transfers.tsx
| +-- staking.tsx
| +-- yield.tsx
| +-- swap.tsx
| +-- lending.tsx
| +-- bridge.tsx
| `-- privacy.tsx # STRK20 and Tongo panels
+-- features/ # One directory per feature, with its store and panels
+-- core/ # Config, network, wallet store
+-- ui/ # Reusable components
+-- theme/ # Light/dark theming
`-- polyfills.ts # React Native polyfills, imported at the entry
```
### Key Code Snippets
**Checking Balances:**
```typescript theme={null}
const balance = await wallet.balanceOf(STRK);
console.log(balance.toFormatted()); // "STRK 150.25"
```
**Transferring Tokens:**
```typescript theme={null}
const tx = await wallet.transfer(STRK, [
{ to: fromAddress("0xRECIPIENT"), amount: Amount.parse("10", STRK) },
]);
await tx.wait();
```
**Staking Operations:**
```typescript theme={null}
await wallet.enterPool(poolAddress, Amount.parse("100", STRK));
await wallet.claimPoolRewards(poolAddress);
```
**React Native:** The example includes the usual polyfills (`react-native-get-random-values`, `fast-text-encoding`) and uses the SDK's optional peer deps for React Native. See the [examples/mobile README](https://github.com/keep-starknet-strange/starkzap/tree/main/examples/mobile) in the repo for full run instructions and env details.
</Tab>
<Tab title="Server">
Express.js backend for Privy wallet operations: wallet creation, signing, and paymaster integration.
### Features
* ✅ Privy wallet creation and management
* ✅ Transaction signing endpoint
* ✅ AVNU Paymaster proxy for sponsored transactions
* ✅ Account registration and deployment tracking
* ✅ Simple file-based storage (use a database in production)
### Getting Started
[Login to Privy](https://dashboard.privy.io/) ([Privy Docs.](https://docs.privy.io/basics/get-started/dashboard/overview))
On the Privy Dashboard, create an App, and retrieve the API Keys. Configure your `env.` file.
```bash theme={null}
cd examples/server
cp .env.example .env # then fill in your Privy keys
npm install
npm start
```
The server runs on `http://localhost:3001`.
### Environment Variables
* `ENABLE_PRIVY` - Enable the Privy wallet routes
* `PRIVY_APP_ID` - Your Privy application ID (required for Privy routes)
* `PRIVY_APP_SECRET` - Your Privy application secret (required for Privy routes)
* `ENABLE_PAYMASTER` - Enable the paymaster proxy route
* `AVNU_API_KEY` - AVNU Paymaster API key (optional; set it for sponsored mode)
* `AVNU_PAYMASTER_URL_MAINNET` / `AVNU_PAYMASTER_URL_SEPOLIA` - Upstream paymaster per network (both default to AVNU's public endpoints)
Wallet data is persisted to `wallets.json`, which is created on demand. It is a file store for development — use a real database in production.
### API Endpoints
| Endpoint | Method | Auth | Description |
| - | - | - | - |
| `/api/health` | GET | No | Returns `{ status: "ok" }`. Used to check the server is reachable before attempting Privy operations. |
| `/api/health/privy` | GET | No | Present only when the Privy routes are enabled. |
| `/api/health/paymaster` | GET | No | Present only when the paymaster proxy is enabled. |
| `/api/privy-wallet/starknet` | POST | Bearer token | Creates a Starknet wallet via Privy, or returns the existing one. Returns `{ wallet: { id, address, publicKey }, accounts, isNew }`. |
| `/api/privy-wallet/register-account` | POST | Bearer token | Associates a computed account address with a preset. Body: `{ preset, address, deployed? }`. |
| `/api/privy-wallet/set-deployed` | POST | Bearer token | Updates the deployment status of a registered account. Body: `{ preset, deployed }`. |
| `/api/privy-wallet/sign` | POST | No | Signs a transaction hash. Body: `{ walletId, hash }`. Returns `{ signature }`. |
| `/api/paymaster/:network` | POST | No | Proxies the body to that network's AVNU paymaster, attaching the API key header. Returns the response as-is. The bare `/api/paymaster` returns 400 naming the two valid paths, rather than silently picking a network. |
#### Sign Transaction Hash
```bash theme={null}
POST /api/privy-wallet/sign
Content-Type: application/json
{
"walletId": "wallet-id",
"hash": "0x..."
}
```
Returns `{ signature: [...] }`
#### Paymaster Proxy
```bash theme={null}
POST /api/paymaster/mainnet # or /api/paymaster/sepolia
Content-Type: application/json
{
"method": "estimate_fee",
"params": { ... }
}
```
Forwards requests to AVNU Paymaster with API key authentication. The network is part of the path because each AVNU deployment whitelists only its own privacy pool: send a mainnet pool to the Sepolia paymaster and it answers `156 :: privacy pool address is not whitelisted` from two layers away. One API key covers both.
<Warning>
This route raises the JSON body limit to 4 MB. A [STRK20](/build/starkzap/privacy/strk20) proof runs to roughly 300–320 KB for a simple transfer and more for transactions carrying more actions, which is past Express's 100 KB default — and that default rejects them with an HTML 413 before any route runs, surfacing as "non-JSON response" rather than a size problem. Any proxy you put in front of a paymaster needs the same allowance.
</Warning>
<Warning>
The route is **unauthenticated**, which is only safe on localhost. The reason to run a proxy at all is that it holds the API key so the key never ships in a browser bundle — which makes the route a way to *spend* that key without ever seeing it. Reachable from the internet, it is an open relay for your sponsorship budget. Gate it before deploying anything shaped like this, and gate the paymaster route specifically. `privacy.paymaster.fetch` is where a client-side credential goes.
</Warning>
### Key Code Snippets
**Signing Endpoint:**
```typescript theme={null}
app.post("/api/privy-wallet/sign", async (req, res) => {
const { walletId, hash } = req.body;
const result = await privy
.wallets()
.rawSign(walletId, { params: { hash } });
res.json({ signature: result.signature });
});
```
**Paymaster Proxy:**
```typescript theme={null}
app.post("/api/paymaster/:network", async (req, res) => {
const upstream = UPSTREAMS[req.params.network];
if (!upstream) return res.status(400).json({ error: "Unknown network" });
const response = await fetch(upstream, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(AVNU_API_KEY && { "x-paymaster-api-key": AVNU_API_KEY }),
},
body: JSON.stringify(req.body),
});
const data = await response.json();
res.status(response.status).json(data);
});
```
</Tab>
</Tabs>
## Common Patterns
### Error Handling
All examples include proper error handling:
```typescript theme={null}
try {
const tx = await wallet.execute(calls);
await tx.wait();
console.log("Success!");
} catch (error) {
console.error("Transaction failed:", error);
// Show user-friendly error message
}
```
### Loading States
Examples demonstrate loading state management:
```typescript theme={null}
function setButtonLoading(btn: HTMLButtonElement, loading: boolean) {
if (loading) {
btn.disabled = true;
btn.innerHTML = '<span class="spinner"></span>';
} else {
btn.disabled = false;
btn.textContent = "Submit";
}
}
```
### Transaction Tracking
All examples show how to track transaction status:
```typescript theme={null}
const tx = await wallet.execute(calls);
console.log(`Tx hash: ${tx.hash}`);
console.log(`Explorer: ${tx.explorerUrl}`);
await tx.wait();
console.log("Transaction confirmed!");
```
## Next Steps
* Explore the example code in the `examples/` directory
* Adapt the patterns to your own application
* Check the [API Reference](/build/starkzap/api-reference) for detailed method documentation
* Review the [Troubleshooting](/build/starkzap/troubleshooting) guide if you encounter issues
# Glossary
Source: https://docs.starknet.io/build/starkzap/glossary
Web3 terminology explained in web2-friendly terms
## Key Concepts for Web2 Developers
If you're new to blockchain development, here are the key terms you'll encounter, explained using familiar web2 concepts:
### Wallet
**Web2 Equivalent:** Bank account or user account
A wallet is like a bank account on the blockchain. It has:
* An **address** (like an account number) - where you receive funds
* A **private key** (like a password) - used to authorize transactions
* A **public key** (like a username) - derived from the private key, can be shared
Unlike a bank account, users control their wallet directly—there's no bank in the middle.
### Signer
**Web2 Equivalent:** Authentication/Authorization system
A signer is what proves you own a wallet and authorizes transactions. Think of it like:
* **OAuth tokens** - prove you're logged in
* **API keys** - authorize API calls
* **Digital signatures** - prove you authorized a transaction
The SDK supports different signer types:
* **Private Key Signer** - Like storing a password locally (for servers only)
* **Privy Signer** - Like OAuth, keys managed by a service
* **Cartridge Signer** - Like social login, keys managed by Cartridge
### RPC (Remote Procedure Call)
**Web2 Equivalent:** API endpoint
An RPC endpoint is like a REST API endpoint, but for blockchain operations. It's how your app communicates with the blockchain network to:
* Read data (like checking balances)
* Submit transactions (like sending tokens)
* Query the network state
Think of it like calling `fetch()` to a blockchain API instead of your own backend.
### Network / Chain
**Web2 Equivalent:** Environment (production, staging, development)
* **Mainnet** = Production - Real money, real transactions
* **Testnet (Sepolia)** = Staging - Fake money for testing
* **Devnet** = Local development - Your own test blockchain
Just like you have `production`, `staging`, and `localhost` environments.
### Gas / Transaction Fees
**Web2 Equivalent:** Credit card processing fees or API usage costs
Gas is the fee paid to process transactions on the blockchain. Think of it like:
* Credit card processing fees (2-3% per transaction)
* AWS API Gateway costs (pay per request)
* Stripe transaction fees
With the SDK, you can:
* **User pays** - User covers the gas fee (like normal)
* **Sponsored** - You pay the gas fee for users (like offering free shipping)
### Address
**Web2 Equivalent:** Account number, email address, or user ID
An address is a unique identifier for a wallet on the blockchain. It's like:
* A bank account number (where you send money)
* An email address (where you send messages)
* A user ID in your database
Example: `0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d`
### Private Key
**Web2 Equivalent:** Password or secret key
A private key is a secret that proves you own a wallet. It's like:
* A password for your bank account
* An API secret key
* A JWT signing key
**⚠️ Never share your private key!** It's like sharing your password—anyone with it can control your wallet.
### Public Key
**Web2 Equivalent:** Username or public identifier
A public key is derived from a private key and can be shared. It's like:
* A username (public, can be shared)
* An email address (public identifier)
* A user ID (public reference)
Unlike a private key, sharing your public key is safe.
### Transaction
**Web2 Equivalent:** API request or database operation
A transaction is an operation on the blockchain, like:
* Sending tokens (like a bank transfer)
* Calling a smart contract function (like an API call)
* Deploying a contract (like deploying a service)
Transactions are:
* **Immutable** - Once confirmed, can't be changed (like a database commit)
* **Public** - Anyone can see them (like public API logs)
* **Atomic** - Either fully succeed or fully fail (like database transactions)
### Deploy
**Web2 Equivalent:** Creating an account or provisioning a service
On Starknet, wallets are smart contracts that need to be "deployed" (created on the blockchain) before they can be used. It's like:
* Creating a new user account in your database
* Provisioning a new AWS service
* Setting up a new bank account
The SDK handles this automatically with `deploy: "if_needed"`.
### Token / ERC20
**Web2 Equivalent:** Currency or digital asset
A token is like a currency or digital asset on the blockchain. Think of it like:
* **Bitcoin** - A cryptocurrency
* **USDC** - A stablecoin (like digital dollars)
* **STRK** - Starknet's native token
* **Custom tokens** - Like loyalty points or in-game currency
The SDK makes it easy to send and receive any token, just like sending money via Venmo or PayPal.
### Staking
**Web2 Equivalent:** Savings account or investment
Staking is like putting money in a savings account that earns interest. You:
* Lock up tokens (like depositing money)
* Earn rewards over time (like interest)
* Can withdraw later (like closing the account)
The SDK handles all the complexity—you just call `wallet.enterPool()`.
### Smart Contract
**Web2 Equivalent:** Backend service or API
A smart contract is code that runs on the blockchain. Think of it like:
* A backend API endpoint
* A microservice
* A database stored procedure
Unlike traditional code, smart contracts:
* Run on the blockchain (decentralized)
* Can't be changed once deployed (immutable)
* Execute automatically when called
### Account Preset
**Web2 Equivalent:** Account type or user role
An account preset defines what type of wallet account to create. It's like:
* Choosing between "Personal" vs "Business" account types
* Selecting a user role (admin, user, guest)
* Picking a subscription tier
Different presets have different features and security models (like OpenZeppelin, Argent, Braavos).
## Privacy terms
Starkzap supports two independent privacy protocols. See [Choosing a privacy protocol](/build/starkzap/privacy/overview) for which to use.
### STRK20 privacy pool
**Web2 Equivalent:** A pooled clearing account
One contract holding balances for every token. Instead of a public balance on your own account, your funds sit in the pool as private **notes** that only you can find. Because the pool moves the funds on your behalf, your account does not appear on the transaction. Hides amounts, sender, and recipient. See [STRK20](/build/starkzap/privacy/strk20).
### Tongo
**Web2 Equivalent:** An account with the balance column encrypted
A separate protocol, one contract per token, where your balance stays on your own account but is stored encrypted. Hides amounts only — you still send the transaction yourself, so your address is visible. See [Tongo](/build/starkzap/privacy/tongo).
### Note
**Web2 Equivalent:** An individual banknote, rather than a balance
The unit of private value in the STRK20 pool. A private balance is a *set* of notes, not a single number, and spending means proving you own specific notes. Spending part of a note produces change, called **surplus**, which returns to you as a new private note.
### Viewing key
**Web2 Equivalent:** A read-only API key for your ow프로젝트로 돌아가기