starkzap-sdk
Original:🇺🇸 English
Translated
3 scriptsChecked / no sensitive code detected
Use when integrating or maintaining applications built with keep-starknet-strange/starkzap. Covers StarkSDK setup, onboarding (Signer/Privy/Cartridge), wallet lifecycle, sponsored transactions, ERC20 transfers, staking flows, tx builder batching, examples, tests, and generated presets.
1installs
Added on
NPX Install
npx skill4agent add keep-starknet-strange/starknet-agentic starkzap-sdkTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Starkzap SDK
Project-focused guide for .
https://github.com/keep-starknet-strange/starkzapUse this skill when requests involve Starkzap SDK code, examples, or docs.
When To Use
Trigger for tasks like:
- "Add a new onboarding flow in Starkzap"
- "Fix sponsored transaction behavior in wallet.execute"
- "Update staking pool logic or validator presets"
- "Patch Privy signer/server integration"
- "Review Starkzap tests/docs/examples"
Repository Map
Primary implementation:
- - top-level orchestration (
src/sdk.ts)StarkSDK - - wallet implementations and lifecycle
src/wallet/* - -
src/signer/*,StarkSigner, signer adapterPrivySigner - -
src/tx/*andTxTxBuilder - - token helpers, balance/transfer logic
src/erc20/* - - staking operations and pool discovery
src/staking/* - - shared domain types (
src/types/*,Address, config)Amount
Operational and docs:
- and
tests/*tests/integration/* - ,
examples/web,examples/server,examples/mobileexamples/flappy-bird - for generated artifacts in the Starkzap repo
scripts/* - and
docs/*mintlify-docs/*
Skill resources:
- - signer trust boundaries and auth assumptions
skills/starkzap-sdk/references/signer-integration.md - - paymaster flow and fee mode behavior
skills/starkzap-sdk/references/sponsored-transactions.md - -
skills/starkzap-sdk/references/erc20-helpers.mdsemantics and transfer patternsAmount - - pool discovery and timeout/abort safety
skills/starkzap-sdk/references/staking-reliability.md - - wallet readiness and execute flow
skills/starkzap-sdk/scripts/wallet-execute-example.ts - - staking pool discovery and diagnostics
skills/starkzap-sdk/scripts/staking-pool-discovery.ts
Quick Reference
Common starknet.js patterns (provider/account/call/execute/listen):
typescript
import { Account, Contract, RpcProvider } from "starknet";
const provider = await RpcProvider.create({
nodeUrl: process.env.RPC_URL!,
});
const account = new Account({
provider,
address: process.env.ACCOUNT_ADDRESS!,
signer: process.env.PRIVATE_KEY!,
cairoVersion: "1",
});
const contract = new Contract({
abi,
address: process.env.CONTRACT_ADDRESS!,
providerOrAccount: account,
});
await contract.call("balance_of", [account.address]); // read
const tx = await account.execute([
{
contractAddress: process.env.CONTRACT_ADDRESS!,
entrypoint: "do_work",
calldata: [],
},
]);
await provider.waitForTransaction(tx.transaction_hash);typescript
// With Starkzap Tx wrapper
const submitted = await wallet.execute(calls, { feeMode: "user_pays" });
const stop = submitted.watch(
({ finality, execution }) => console.log(finality, execution),
{ pollIntervalMs: 5000, timeoutMs: 120000 }
);
// stop(); // call to unsubscribe earlyCommon error classes and immediate recovery:
| Error Class | Typical Signal | Immediate Recovery |
|---|---|---|
| | Re-check token decimals/symbol, parse from known token preset, avoid mixing token types. |
| | Run |
| timeout, 429, provider mismatch | Retry with backoff, confirm |
| | Run |
| Privy 401/403, invalid signature response | Verify signer server auth, headers/body resolver, and trusted |
See also:
- for implementation-specific troubleshooting
skills/starkzap-sdk/references/* - for runnable diagnostic examples
skills/starkzap-sdk/scripts/*
Core Workflows
1) Configure StarkSDK
and Connect Wallets
StarkSDKCommon API path:
- Instantiate with
StarkSDKornetwork.rpcUrl + chainId - Use or
sdk.onboard(...).sdk.connectWallet(...) - Call before user-pays writes.
wallet.ensureReady({ deploy: "if_needed" })
Supported onboarding strategies:
OnboardStrategy.SignerOnboardStrategy.PrivyOnboardStrategy.Cartridge
For Cartridge:
- Treat as web-only runtime.
- Expect popup/session behavior and policy scoping requirements.
typescript
import {
ChainId,
OnboardStrategy,
StarkSDK,
StarkSigner,
} from "starkzap";
const sdk = new StarkSDK({ network: "sepolia" });
const customSdk = new StarkSDK({
rpcUrl: process.env.RPC_URL!,
chainId: ChainId.SEPOLIA,
});
const signerResult = await sdk.onboard({
strategy: OnboardStrategy.Signer,
account: { signer: new StarkSigner(process.env.PRIVATE_KEY!) },
feeMode: "user_pays",
deploy: "if_needed",
});
const privyResult = await sdk.onboard({
strategy: OnboardStrategy.Privy,
privy: {
resolve: async () => ({
walletId: process.env.PRIVY_WALLET_ID!,
publicKey: process.env.PRIVY_PUBLIC_KEY!,
serverUrl: process.env.PRIVY_SIGNER_URL!,
}),
},
feeMode: "sponsored",
});
const cartridgeResult = await sdk.onboard({
strategy: OnboardStrategy.Cartridge,
cartridge: {
preset: "controller",
policies: [{ target: "0xPOOL", method: "stake" }],
},
});
const wallet = await sdk.connectWallet({
account: { signer: new StarkSigner(process.env.PRIVATE_KEY!) },
feeMode: "sponsored",
});
await wallet.ensureReady({ deploy: "if_needed" });2) Execute Transactions (wallet.execute
, wallet.preflight
, wallet.tx
)
wallet.executewallet.preflightwallet.txUse:
- for direct execution.
wallet.execute(calls, options) - for simulation checks.
wallet.preflight({ calls, feeMode }) - (
wallet.tx()) for batched operations with deterministic ordering.TxBuilder
typescript
const calls = [
{
contractAddress: process.env.CONTRACT_ADDRESS!,
entrypoint: "do_work",
calldata: [],
},
];
const preflight = await wallet.preflight({
calls,
feeMode: "user_pays",
});
if (!preflight.ok) {
throw new Error(`Preflight failed: ${preflight.reason}`);
}
const userPaysTx = await wallet.execute(calls, { feeMode: "user_pays" });
await userPaysTx.wait();
const sponsoredTx = await wallet.execute(calls, { feeMode: "sponsored" });
await sponsoredTx.wait();
const batchedTx = await wallet
.tx()
.add(...calls)
.send({ feeMode: "sponsored" });
await batchedTx.wait();typescript
function getSdkErrorClass(error: unknown): string {
const message = error instanceof Error ? error.message : String(error);
if (message.includes("not deployed")) return "UNDEPLOYED_ACCOUNT";
if (message.includes("timed out") || message.includes("429")) {
return "RPC_OR_NETWORK";
}
if (message.includes("signature") || message.includes("Privy")) {
return "AUTH_OR_PERMISSION";
}
if (message.includes("Invalid") || message.includes("Amount")) {
return "VALIDATION_ERROR";
}
return "UNKNOWN";
}
try {
await wallet.execute(calls, { feeMode: "user_pays" });
} catch (error) {
const kind = getSdkErrorClass(error);
if (kind === "UNDEPLOYED_ACCOUNT") {
await wallet.ensureReady({ deploy: "if_needed" });
}
throw error;
}When changing execution behavior:
- Audit deploy vs execute path for undeployed accounts.
- Verify runtime constraints (is web-only).
OnboardStrategy.Cartridge - Cover both and
user_paysbranches in tests.sponsored
3) ERC20 and Staking Scope
ERC20 notes (starkzap-sdk internal token operations, no avnu required):
- Validate with the token preset used for the call.
Amount - Keep multicall ordering explicit for batched transfers.
typescript
import { Amount } from "starkzap";
const usdcAmount = Amount.parse("25", USDC);
try {
const tx = await wallet
.tx()
.transfer(USDC, [
{ to: recipientA, amount: usdcAmount },
{ to: recipientB, amount: Amount.parse("5", USDC) },
])
.send({ feeMode: "user_pays" });
await tx.wait();
} catch (error) {
// Re-parse Amount from the expected token preset before retrying.
throw error;
}Staking notes (starkzap-specific staking flows):
- Membership-sensitive operations: ,
enter,add,exit intent.exit - Validate staking config and chain presets before execution.
- Verify timeout/abort behavior where pool resolution is involved.
For general DeFi operations (swaps, DCA, lending) and STRK staking via the avnu aggregator, use the skill.
starknet-defi4) Examples + Integration Surfaces
Check for drift between:
examples/web/main.tsexamples/server/server.ts- and docs links
README
Specifically verify endpoint and auth consistency for Privy + paymaster proxy flows.
Guardrails
Do not hand-edit generated files:
src/erc20/token/presets.tssrc/erc20/token/presets.sepolia.tssrc/staking/validator/presets.tssrc/staking/validator/presets.sepolia.tsdocs/api/**docs/export/**
Regenerate with scripts:
bash
npm run generate:tokens
npm run generate:tokens:sepolia
npm run generate:validators
npm run generate:validators:sepolia
npm run docs:api
npm run docs:exportKeep API export changes explicit:
- If new public API is added/removed, update .
src/index.ts
Validation Checklist
Run minimal set first:
bash
npm run typecheck
npm testRun broader checks when behavior is cross-cutting:
bash
npm run build
npm run test:allIntegration tests may require local devnet/fork setup:
bash
npm run test:integrationIf not run, clearly report why.
Error Codes & Recovery
Map observed errors to actionable recovery:
| Error Class | Typical Trigger | Recovery Steps |
|---|---|---|
| | Confirm token decimals/symbol, re-create |
| RPC timeout, | Retry with exponential backoff, check |
| | Run |
| | Increase timeout where appropriate, add abort handling, retry on fresh provider session, avoid parallel heavy queries. |
| Privy signing errors, 401/403, invalid signature payloads | Verify signer server auth headers/body, validate trusted |
| | Run |
| Preset/docs changes diverge from source of truth | Regenerate via |
If a fix is uncertain:
- Reproduce with the closest example in .
examples/* - Capture command, environment, and failing test IDs.
- Report exact file/path + remediation attempted.
Useful Task Patterns
-
Bug fix in wallet lifecycle:
- inspect ,
src/wallet/index.tssrc/wallet/utils.ts - patch
- update
tests/wallet*.test.ts
- inspect
-
Privy auth/signature issue:
- inspect
src/signer/privy.ts - align with
examples/server/server.ts - update
tests/privy-signer.test.ts
- inspect
-
Staking regression:
- inspect ,
src/staking/staking.tssrc/staking/presets.ts - add/adjust integration assertions in
tests/integration/staking.test.ts
- inspect
Example Prompt
"Use this skill to fix Starkzap sponsored execution for undeployed accounts, add tests, and list behavior changes."