Skip to main content

Overview

Use starkzap-native when integrating StarkZap in React Native/Expo apps. It re-exports the SDK API and adds a Metro helper (starkzap-native/metro) that handles ESM/CJS resolver compatibility for starknet and its dependencies, and hoists your polyfills to run before the app entry.

1) Install Packages

Install the React Native package and the one polyfill every StarkZap flow needs:
Install the rest only for the features you actually use — each is reached by a specific code path, not by every flow:

2) Configure Metro

Set up Metro once and wrap your config with withStarkzap:
withStarkzap handles resolver compatibility for StarkZap dependencies and hoists your polyfills to run first. It does not import the polyfills for you — do that at your app entry (next step).

3) Load polyfills at your app entry

withStarkzap can only run polyfills that are in Metro’s module graph — it reorders them so they run first, but it cannot import them for you. Import the ones your app needs once, at your entry point (e.g. index.js or your root layout), before any StarkZap code runs. Each polyfill exists for a specific reason, so import only what your app actually uses: Required for every app:
Add if you use Cartridge, the paymaster, or generate keys:
Add if you use the bridge features:
Add this if you use the STRK20 privacy pool with OHTTP on. Take only subtle. The package’s own install() replaces the whole crypto global, including the getRandomValues installed above for starknet:
Use require inside the guard, not a top-level import. The package loads native modules at import time, so an unconditional import crashes where those modules are absent, such as Expo Go. It needs a dev build (npx expo run:android). In an existing native project, run npx expo prebuild again so the C++ module is linked.
Then import that file as the very first line of your entry:
If you skip fast-text-encoding, starknet crashes on the first contract call (TextEncoder is not defined) — starkzap-native warns in the console when it’s absent. Skipping react-native-get-random-values surfaces a clear crypto.getRandomValues must be defined only when a Cartridge/paymaster/keygen path runs.

4) Initialize the SDK

Import from starkzap-native and use the same onboarding APIs as web:
For Privy-based onboarding, see Privy Integration.

5) Cartridge (native session)

When your starkzap-native version supports it, you can onboard with Cartridge using an in-app browser / deep-link session flow (not the web @cartridge/controller popup).
  1. Register the native Cartridge adapter once at app startup, before connectCartridge() or onboard({ strategy: OnboardStrategy.Cartridge }). Exact export names depend on your SDK version (for example registerCartridgeTsAdapter / registerCartridgeNativeAdapter).
  2. Pass policies and/or a Cartridge preset that resolves policies for your chain (same concepts as Cartridge Controller).
  3. Align rpcUrl / chainId (or network) on new StarkZap({ ... }) with the session and paymaster you target.
  4. Deploy: native Cartridge flows often default to deploy: "never" or recommend it when deployment semantics differ from the browser Controller. Pass deploy: "if_needed" explicitly if you need core-style deployment checks.
  5. Fees: sponsored execution on native is tied to the session wallet (commonly feeMode: { type: "paymaster" } only for matching policy paths, without gasToken).
See Cartridge Controller for policy and paymaster behavior, and the examples/tic-tac-toe app in the Starkzap repository when available for a full Expo reference.

6) External Wallet Providers (Optional)

If your app uses WalletConnect/Reown for external wallets, initialize its RN compatibility layer at app startup:
Then pass the resulting providers into StarkZap external wallet adapters as described in Bridging.
If connectCartridge or Cartridge onboarding throws not implemented, your installed starkzap-native build does not ship the native adapter yet — upgrade to a version that documents native Cartridge, or use Signer / Privy until then.

Next Steps