starkzap-rs
A Rust SDK for seamless Starknet wallet integration — the faithful Rust mirror of starkzap.
Built for the Starknet community.
Installation
[]
= "0.1.1"
# Optional signers / helpers
= { = "0.1.1", = ["privy"] }
= { = "0.1.1", = ["cartridge"] }
= { = "0.1.1", = ["full"] }
Git install is still available if you want the latest repository version:
= { = "https://github.com/OkoliEvans/starkzap-rs" }
Quick Start
use ;
async
Dependencies
The SDK depends on:
starknet(0.17) for Starknet accounts, providers, and signingtokiofor async runtime
These are installed automatically when you add starkzap-rs.
Cargo features
Like StarkZap TS uses optional integrations and peer dependencies, starkzap-rs
uses optional Cargo features:
| Feature | What it enables |
|---|---|
privy |
Privy server-side signer |
cartridge |
Cartridge session signer |
full |
All optional signers |
wasm |
WASM-target crate builds |
The crate uses default = [], so the base SDK works without enabling any feature.
Targets
- Server / CLI (tokio) — first-class target
- Browser helper tooling — see
examples/cartridge_session_web/for the Cartridge session exporter - WASM crate build — verified with
cargo check --features wasm --target wasm32-unknown-unknown
Networks
// Preset networks
let sdk = new;
let sdk = new;
let sdk = new;
// Custom RPC (Alchemy, Infura, etc.)
let sdk = new;
Default fallback endpoints (used when no rpc_url is provided):
- Mainnet:
https://starknet.drpc.org - Sepolia:
https://starknet-sepolia.drpc.org - Devnet:
http://127.0.0.1:5050/rpc
For production, always use your own RPC key — public endpoints are rate-limited.
Signers
StarkSigner (raw private key)
Suitable for server-side scripts, CI/CD, and developer demos.
let signer = new?;
let wallet = sdk.onboard.await?;
PrivySigner (privy feature)
Server-side embedded wallets. Your backend never holds the private key.
# env vars required
PRIVY_APP_ID=clxxxxxxxxxxxxxxxx
PRIVY_APP_SECRET=privy_secret_...
use PrivySigner;
let mut privy = from_env?;
// Create a new wallet for a user and persist the returned metadata
let wallet = privy.create_wallet_info.await?;
// Or load an existing wallet
let privy = from_env?.with_wallet_and_public_key;
Setup:
- Create a Privy app at https://privy.io
- Dashboard → Settings → API Keys → copy App ID and App Secret
- Persist
wallet_id,address, andpublic_keyfrom the first wallet creation - Set
PRIVY_APP_IDandPRIVY_APP_SECRET
CartridgeSigner (cartridge feature)
Uses a full session bundle exported from the Cartridge Controller flow.
Use the helper app in examples/cartridge_session_web/ to:
- authenticate with Cartridge
- approve session policies
- export
CARTRIDGE_SESSION_BUNDLE_B64
Rust backend:
use CartridgeSigner;
let signer = from_env?;
let wallet = sdk.onboard.await?;
Cartridge's primary auth flow (passkeys, biometrics, username/password, social) is browser-native. Rust consumes the exported session bundle and executes through the registered session account model.
Helper app setup:
Then open the local Vite URL, create a session, and copy CARTRIDGE_SESSION_BUNDLE_B64
into your .env.
Token Presets
use ;
// Mainnet
let usdc = usdc; // 6 decimals
let usdc_e = usdc_e; // 6 decimals (bridged)
let strk = strk; // 18 decimals
let eth = eth; // 18 decimals
let wbtc = wbtc; // 8 decimals
let tbtc = tbtc; // 18 decimals
let lbtc = lbtc; // 8 decimals
let xwbtc = xwbtc; // 8 decimals
let solvbtc = solvbtc; // 18 decimals
let wsteth = wsteth; // 18 decimals
// Sepolia
let usdc = usdc;
let strk = strk;
let eth = eth;
let wbtc = wbtc;
let tbtc = tbtc;
let lbtc = lbtc;
// By symbol
let tok = by_symbol.unwrap;
Token and validator preset data is generated at build time from:
codegen/presets/tokens.jsoncodegen/presets/validators.json
That keeps the Rust API stable while making preset updates data-driven. BTC-family Starknet assets from StarkZap TS V1 are included in these generated presets.
Amount
let usdc = usdc;
let amount = parse?;
amount.raw; // 10_500_000 (raw u128, 6 decimals)
amount.to_formatted; // "10.5 USDC"
amount.to_decimal_string; // "10.5"
amount.to_u256_felts; // [Felt(10_500_000), Felt::ZERO]
amount.is_zero; // false
Transfers
use ;
use ;
let usdc = usdc;
let amount = parse?;
// Simple transfer. Defaults to user-pays execution.
let tx = wallet
.transfer
.await?;
// TS-style transfer with explicit execution options.
let tx = wallet
.transfer_with_options
.await?;
transfer_with_options mirrors StarkZap TS wallet.transfer(token, transfers, options).
Rust keeps transfer(...) as the backward-compatible convenience method and exposes
the options-aware version explicitly.
Paymaster (AVNU Gasless)
use ;
// Sepolia — no API key needed
let config = new;
// Mainnet — API key required
let config = with_api_key;
// or from env: AVNU_API_KEY=...
let config = from_env;
// Execute any calls gaslessly
let tx = wallet.execute.await?;
tx.wait.await?;
Obtain a mainnet API key at https://app.avnu.fi.
Sponsored execution mirrors the StarkZap TS wallet flow:
- if the account is deployed, the SDK sends an invoke-only paymaster transaction
- if the account is undeployed, the SDK sends deploy-and-invoke through paymaster
- the undeployed sponsored branch is guarded by a per-wallet deploy lock
- if another request deploys first, the SDK retries as invoke-only on already-deployed errors
If an account class is not compatible with sponsored execution, the SDK now
falls back to normal user_pays execution instead of failing the entire flow.
Live Test Harnesses
For deliberate real-network verification, the repo includes ignored live tests:
# Sepolia / generic live checks
# Mainnet STRK systems
# Mainnet WBTC systems
Notes:
- these tests can submit real transactions
tests/mainnet_live.rsincludes optional staking writes gated behindRUN_MAINNET_STAKING_WRITES=1tests/mainnet_wbtc_live.rsusesMAINNET_WBTC_TRANSFER_AMOUNTfor live WBTC checks- paymaster tests run only when
AVNU_API_KEYis set
Staking
use ;
let strk = strk;
let validators = mainnet_validators;
let pool = wallet.get_staker_pools.await?.address;
// Enter pool (stake)
let tx = wallet.enter_pool.await?;
tx.wait.await?;
// Check position
let pos = wallet.get_pool_position.await?;
println!;
// Add more
let tx = wallet.add_to_pool.await?;
// Claim rewards
let tx = wallet.claim_rewards.await?;
// Exit (two-step: intent → wait cooldown → finalise)
let tx = wallet.exit_pool_intent.await?;
// ... wait ~21 days on mainnet ...
let tx = wallet.exit_pool.await?;
// Discover pools
let staker_addrs: = mainnet_validators.into_iter.map.collect;
let pools = wallet.discover_my_pools.await?;
Transactions
let tx = wallet.transfer.await?;
// Wait for confirmation (polls with exponential backoff)
let receipt = tx.wait.await?;
// Custom timeout
let receipt = tx.wait_with_options.await?;
// Poll current status
let status = tx.status.await?; // TxStatus::Pending | Accepted | Reverted | Rejected
// Stream updates
use StreamExt;
let mut stream = tx.watch;
while let Some = stream.next.await
// Hash
println!; // "0x..."
Documentation
The main usage guide today is this README plus the runnable examples in examples/.
For the closest reference model and API design, see the official StarkZap TypeScript SDK:
Examples
The repo includes runnable examples for the main SDK flows:
basic_transferpaymaster_transferstaking_flowprivy_signercartridge_signer
For Cartridge session export, use the helper app in examples/cartridge_session_web/.
Setup & Development
# Clone
# Copy env
# Fill in PRIVATE_KEY, ACCOUNT_ADDRESS, etc.
# Build
# Type check
# Run all unit tests (no network required)
# Run live integration tests (requires RPC or devnet)
# Start devnet first: starknet-devnet --seed 0
# Run examples
# Run the Cartridge session exporter helper
# Lint
# Format
Installing starknet-devnet (for local testing)
# Python (easier)
# or Rust binary
# Start with a fixed seed (reproducible preloaded accounts)
# Devnet gives you preloaded accounts at http://127.0.0.1:5050
# Check account list at: http://127.0.0.1:5050/predeployed_accounts
Roadmap
- Core: StarkSigner, tokens, transfer, execute
- AVNU paymaster
- Staking: enter/exit/rewards/discovery
- Privy signer flow
- Cartridge session flow
- Auto account deploy
- Token/validator preset codegen
- WASM build verification
- Published to crates.io
License
MIT