Overview
Usestarkzap-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:2) Configure Metro
Set up Metro once and wrap your config withwithStarkzap:
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:
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.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 fromstarkzap-native and use the same onboarding APIs as web:
5) Cartridge (native session)
When yourstarkzap-native version supports it, you can onboard with Cartridge using an in-app browser / deep-link session flow (not the web @cartridge/controller popup).
- Register the native Cartridge adapter once at app startup, before
connectCartridge()oronboard({ strategy: OnboardStrategy.Cartridge }). Exact export names depend on your SDK version (for exampleregisterCartridgeTsAdapter/registerCartridgeNativeAdapter). - Pass policies and/or a Cartridge preset that resolves policies for your chain (same concepts as Cartridge Controller).
- Align
rpcUrl/chainId(ornetwork) onnew StarkZap({ ... })with the session and paymaster you target. - Deploy: native Cartridge flows often default to
deploy: "never"or recommend it when deployment semantics differ from the browser Controller. Passdeploy: "if_needed"explicitly if you need core-style deployment checks. - Fees: sponsored execution on native is tied to the session wallet (commonly
feeMode: { type: "paymaster" }only for matching policy paths, withoutgasToken).
examples/tic-tac-toe app in the Starkzap repository when available for a full Expo reference.