Guidance for AI coding agents (Claude Code, Cursor, Copilot, etc.) working in this repository. Humans: see CONTRIBUTING.md β this file is a condensed, agent-oriented companion to it, not a replacement.
starknet.js is the JavaScript/TypeScript SDK for Starknet. It is a published npm
library (starknet), so the public API surface is a contract β treat breaking
changes deliberately (see Conventions).
- Node
>=22is required. Install withnpm install. npm run buildβ full build viatsup(CJS + ESM + IIFE +.d.ts). Required before publishing-related tasks; not needed just to run unit tests.npm run lintβ ESLint (airbnb + prettier), autofix on.npm run ts:checkβ type-check only (tsc --noEmit).npm run formatβ Prettier write.
There are two kinds of tests, and the default command needs live infrastructure:
-
Unit tests β no infra needed. Use this loop.
npm run test:unit # all pure unit tests (~1400 tests, ~20s) npm run test:unit -- __tests__/utils/uint256.test.ts # a single file
This uses
jest.unit.config.ts, which runs the pure suites under__tests__/utils/and skips the devnet-connecting global setup. Use it to verify changes tosrc/utils/**and other logic with unit coverage. -
Integration tests β require a running Starknet devnet or RPC node.
npm test,npm run test:coverage, andnpm run test:watchrun the full suite viajest.config.ts, whoseglobalSetupthrows if it cannot reach a devnet (http://127.0.0.1:5050) and noTEST_ACCOUNT_*env vars are set. The root-level__tests__/*.test.tssuites (account, contract, provider, paymaster, walletβ¦) exercise real RPC calls. To run them, start a devnet (Docker:shardlabs/starknet-devnet-rs) or point at a node viaTEST_RPC_URL+TEST_ACCOUNT_ADDRESS+TEST_ACCOUNT_PRIVATE_KEY(see CONTRIBUTING.md). Two suites under__tests__/utils/(ethSigner,batch) also need a node and are excluded fromtest:unit.
If you cannot start a devnet, run npm run test:unit + npm run lint +
npm run ts:check and say so explicitly β do not claim the full suite passed.
High-level classes are re-exported from src/index.ts; utils are exported as
namespaces (hash, num, cairo, shortString, β¦).
| Module | What lives there |
|---|---|
account/ |
Account (+ AccountInterface) β signs and sends transactions, declares/deploys, fees. |
contract/ |
Contract (+ ContractInterface) β typed wrapper to call/invoke a deployed contract via its ABI. |
provider/ |
RpcProvider (+ ProviderInterface) β read chain state; RPCResponseParser shapes responses. |
channel/ |
Transport layer: RpcChannel (JSON-RPC) and WebSocketChannel / Subscription (WS). |
signer/ |
Signer, EthSigner, LedgerSigner* (+ SignerInterface) β message/transaction signing. |
wallet/ |
WalletAccount / WalletAccountV5 β browser wallet (get-starknet / wallet-standard) integration. |
paymaster/ |
PaymasterRpc (+ PaymasterInterface) β gasless / sponsored transaction flows. |
deployer/ |
Deployer (+ DeployerInterface) β UDC-based contract deployment helpers. |
plugins/ |
Plugin framework + implementations (starknet-id, fast-execute, brother-id). |
service/ |
Shared service-layer types. |
utils/ |
Pure helpers: calldata (encode/decode), hash, cairoDataTypes, num, shortString, merkle, typedData, transaction, address, ec, etc. Most have unit tests β test:unit. |
types/ |
Public TypeScript types, including RPC API types (types/api) and Starknet spec bindings. |
global/ |
Global config, constants, and logger. |
Multiple RPC spec versions are supported simultaneously (e.g. v0_8, v0_9); the
pinned starknet_specs dev-dependencies define them. Be version-aware when touching
channel/, provider/, or types/api.
- Conventional Commits, enforced by commitlint (
feat(scope): subject). Onlyfeatandfixdrive the changelog β usechore/test/docs/refactorfor non-shipping changes. Subjects describe the change relative to the target branch, not your feature branch. - PR target branches (see CONTRIBUTING.md for the full table):
developβ default target for fixes, features, docs (npm tagnext).betaβ API-breaking / behavior-changing work; mark the breaking change in the commit (npm tagbeta).main/maintenance/*β maintainers only.
- Do not edit the version number or
CHANGELOG.mdβ semantic-release owns both. - Do not commit generated files (
dist/, coverage). Updatepackage-lock.jsonwhen you change dependencies. - Update docs in
www/and add tests for any behavior change (see CONTRIBUTING.md).
npm testreformats files afterwards (posttestruns Prettier) β running it can leave unexpected diffs in your working tree.pretestrunslint+ts:checkbefore tests, sonpm testcan fail on a lint or type error before a single test executes.- A
pre-commithusky hook runs lint-staged andcommit-msgruns commitlint. A badly formatted commit message is rejected at commit time β get the format right up front. - The default test suite hard-fails without a reachable devnet (see above). A bare
jest <path>will also hit this β go throughnpm run test:unitfor infra-free runs. .claude/is git-ignored, so per-user agent config there is local-only. ThisAGENTS.mdis the shared, committed source of truth. Tools that only read aCLAUDE.md(e.g. Claude Code) can use a local, git-ignoredCLAUDE.mdthat points here.