Node.js SDK
The Node.js SDK lets JavaScript and TypeScript tools run or use a Surfpool Solana runtime. It combines a native runtime with a typed TypeScript API, so tests can use standard Solana RPC and local state controls through one package. The package also provides an optional Kit integration; the Rust SDK, MCP server, and shared contracts describe related integration paths.
Product role
The package gives Node.js users a local Solana environment for tests and development. The root API manages a runtime and provides direct state controls, while the Kit entry composes those controls with the normal Kit client model.
Local runtime lifecycle
The Surfnet API starts an isolated Surfpool instance with RPC and WebSocket endpoints plus a funded payer. Callers can inspect the instance, change local state, move simulated time, read buffered events, and stop the instance. This lifecycle supports test setup and teardown without requiring a separate service process.
References: crates/…/index.ts• L36-103 crates/…/lib.rs• L48-167
Test state control
The direct API controls the state that a test needs to prepare or inspect. It supports account and token funding, account replacement and reset, account streaming, program deployment, time travel, local events, and startup settings such as offline mode or a remote RPC source. The Kit API extends this model with confidential Token-2022 balance access and typed results.
References: crates/…/index.ts• L105-211 crates/…/lib.rs• L169-517 crates/…/api.ts• L111-138
Kit integration
The @solana/surfpool/kit entry connects Surfpool to the composable client model from @solana/kit. It provides standard local-cluster RPC features and a typed client.cheatcodes surface. The same entry supports starting a local instance or connecting to one that already runs.
Embedded mode
Embedded mode starts Surfnet inside the Node.js process. The plugin installs the Surfnet payer, points RPC and WebSocket services at the new instance, and exposes the native handle as client.surfnet. It also adds typed cheatcodes to the Kit client. Disposing the client stops the embedded instance, which ties the runtime lifetime to the client lifetime.
References: crates/…/surfpool.ts• L140-213 crates/…/surfpool.ts• L251-300 crates/…/README.md• L35-60
Attach mode
Attach mode connects a Kit client to an existing Surfpool HTTP endpoint. It does not create a runtime or install a payer, so the caller must provide signing support. The plugin supplies RPC, subscriptions, and typed cheatcodes for the remote instance. A separate subscription URL can be set when the WebSocket route does not match the usual endpoint.
References: crates/…/surfpool.ts• L54-76 crates/…/surfpool.ts• L215-249 crates/…/README.md• L71-108
The Kit flow joins client composition, the local RPC stack, and typed cheatcodes in either runtime mode.
flowchart LR
A[Kit client] --> B{Surfpool mode}
B -->|embedded| C[Start Surfnet]
B -->|attach| D[Use running Surfpool]
C --> E[RPC and WebSocket services]
D --> E
E --> F[Standard Solana RPC]
E --> G[Typed Surfnet cheatcodes]
C --> H[Surfnet handle and payer]
D --> I[Caller-provided payer]
TypeScript API surface
The package separates the public JavaScript-facing wrapper from the wire-level Kit types. This lets the root API present convenient native values while the Kit API uses the address, integer, request, and response shapes required by its RPC contract.
Native wrapper API
The root package exports Surfnet and its related data types. The API covers runtime lifecycle, account and token setup, program deployment, clock changes, event draining, and keypair creation. The TypeScript boundary converts native byte arrays to Uint8Array values for callers.
References: crates/…/index.ts• L1-34 crates/…/index.ts• L48-228
Cheatcode RPC API
The Kit entry provides createSurfnetCheatcodesRpc for a standalone typed RPC client and surfnetCheatcodes for composing that client into an existing Kit client. Public method names omit the surfnet_ wire prefix. The transport restores that prefix, unwraps normal response envelopes, preserves bare clock results, and keeps large integers as bigint.
References: crates/…/cheatcodes.ts• L22-120 crates/…/json.ts• L1-106
Cheatcode capability groups
The typed API groups local controls by the state or diagnostic data they affect. These groups provide the main map of the Kit surface:
- Clock: pause, resume, and move simulated time.
- Accounts: set, reset, stream, and inspect account and token state.
- Programs: clone, write, and change program authority.
- Profiles: create and query transaction profile data.
- IDL and scenarios: register program interface data and repeatable scenarios.
- Network: change supply, reset the network, inspect Surfnet state, and export snapshots.
- Local history: read local transaction signatures.
- Cheatcode access: enable or disable selected cheatcodes.
References: crates/…/api.ts• L92-191 crates/…/index.ts• L1-12
Confidential transfer access
The Kit account API supports confidential Token-2022 balance workflows. A caller can derive the keys needed for a token account and request the balance parts that those keys can read. Results use bigint values and return null for an unavailable balance part.
References: crates/…/api.ts• L111-123 crates/…/ConfidentialBalanceKeys.ts• L5-22 crates/…/GetConfidentialBalanceResponse.ts• L5-24
Generated Kit bindings
Generated bindings keep TypeScript request and response types aligned with the Rust wire contract for Surfpool cheatcodes. The handwritten Kit API combines those generated shapes into the public client surface, while a generated method manifest defines the expected method set.
Rust type source
The binding generator runs the surfpool-types Rust test suite with the ts-bindings feature. It emits TypeScript shapes for shared requests and responses, then adds the package import style and barrel exports. The generated manifest records the complete surfnet_* method set.
References: crates/…/generate-kit-types.js• L1-60 crates/…/index.ts• L1-37 crates/…/methods.ts• L1-34
API coverage contract
The handwritten SurfnetCheatcodesApi must match the generated method manifest exactly. A compile-time assertion enforces this contract, so a Rust method add or rename requires regenerated bindings and a matching TypeScript API update.
References: crates/…/api.ts• L194-240
Build and package pipeline
The build produces one npm package with a native module and TypeScript output. The native part supplies the embedded runtime. The TypeScript part supplies the root wrapper and the Kit entry in both CommonJS and ESM forms.
Native and TypeScript outputs
The package first builds the Rust crate as a platform-aware native module through napi tooling. It then compiles the root and Kit TypeScript APIs and synchronizes the final distribution files. The package exposes the root entry for CommonJS-style use and a separate ESM boundary for the Kit entry.
References: crates/…/package.json• L57-71 crates/…/build.rs• L1-5 crates/…/tsconfig.json• L1-15 crates/…/tsconfig.kit.esm.json• L1-8 crates/…/sync-dist.js• L1-28
Platform package assembly
The root package declares optional native packages for macOS Intel, macOS Arm, and Linux x64 GNU. Build support creates those package directories and places the matching native artifact in each one. npm then installs the platform package that matches the consumer's host.
References: crates/…/package.json• L24-39 crates/…/package.json• L95-99 .github/…/sdk_node.yml• L127-151
Release support
Release support keeps the root package, platform packages, lock file, and published artifacts on one version. It also checks the package as an installed product rather than checking only the source tree.
Version preparation
The prepare-release script validates the requested semantic version and the npm version used by CI. It updates the root version and platform dependency versions, refreshes the lock file, and restores optional dependency stubs while platform packages are not yet published.
References: crates/…/prepare-release.js• L7-19 crates/…/prepare-release.js• L60-137
Continuous validation
The SDK workflow regenerates Kit bindings and fails when the committed result changes. It then builds the Rust and npm layers, runs direct and Kit checks, packs root and platform tarballs, and installs those tarballs in temporary projects. The release workflow repeats these package checks before npm publication and provides a dry-run path for review.
References: .github/…/sdk_node.yml• L33-217 .github/…/release_sdk_node_npm.yml• L16-191 .github/…/release_sdk_node_npm.yml• L193-304
Product checks
The test scripts check the package at three levels. Direct SDK checks cover runtime setup and state helpers. Kit unit checks cover RPC translation and attach behavior without starting a runtime. Kit smoke checks cover a real embedded client and its RPC, payer, cheatcode, funding, and disposal flow.
References: crates/…/package.json• L69-71 crates/…/smoke.js• L13-202 crates/…/kit-unit.js• L36-440 crates/…/kit-smoke.js• L8-99
Change checklist
When these files or sections are changed, remember to consider these:
- When a Rust cheatcode method or wire type changes, regenerate
surfpool-sdk/kit/generated/, update the matching handwritten API type, and preserve the manifest coverage check. - When the package version changes, update platform package versions and the lock file through the release preparation path. The root optional dependencies must still use the same release version.
- When exports or compiler settings change, check both
@solana/surfpool/kitimport styles and the packed tarball. The root package and Kit ESM output have different module boundaries. - When platform targets change, update napi target data, platform package assembly, workflow matrices, and publish conditions together.
- When attach endpoint behavior changes, check the separate HTTP and WebSocket endpoint contract. A proxy or custom WebSocket port may need an explicit subscription URL.
- When confidential balance methods or types change, keep key derivation, token-account setup, decryption inputs, and nullable outputs aligned across generated bindings and the handwritten Kit API.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Generated bindings differ from the Rust wire types | TypeScript methods or payloads can drift from the surfnet_* RPC contract | Run npm run generate:kit-types; CI compares the generated directory and the API has a manifest coverage assertion |
Embedded client or Surfnet is not stopped | RPC sockets and ports can remain open and later tests can fail | Call stop() or dispose the embedded Kit client during teardown |
| Attach mode has no existing payer | The client cannot sign transactions because attach mode does not install one | Install a payer before connecting with surfpool({ rpcUrl }) |
| Attach mode uses the wrong WebSocket endpoint | Standard subscriptions fail even when HTTP RPC works | Set rpcSubscriptionsUrl when the server uses a custom port or proxy route |
| Root and platform package versions differ | npm can select a missing or incompatible native binary | Run release preparation and install packed root and platform tarballs before publish |
| Kit peer packages are not installed | The Kit entry cannot provide its client plugins | Install @solana/kit, @solana/kit-plugin-rpc, and @solana/kit-plugin-signer when using the Kit entry |
Key files
| File | Why to read it |
|---|---|
| crates/…/README.md | User-facing package model, embedded and attach examples, and development commands |
| crates/…/index.ts | Public Surfnet API and native value boundary |
| crates/…/lib.rs | Native runtime capabilities exposed to Node.js |
| crates/…/surfpool.ts | Embedded and attach Kit composition model |
| crates/…/cheatcodes.ts | Typed cheatcode RPC behavior and JSON transport contract |
| crates/…/api.ts | Handwritten Kit API groups and generated-manifest coverage |
| crates/…/index.ts | Public barrel for generated wire types |
| crates/…/methods.ts | Generated method manifest for the cheatcode contract |
| crates/…/generate-kit-types.js | Rust-to-TypeScript binding generation contract |
| crates/…/package.json | Package exports, peer and platform dependencies, and build commands |
| crates/…/package-lock.json | Locked Node and Kit dependency versions used by the package build |
| crates/…/prepare-release.js | Version and lock-file preparation for npm releases |
| .github/…/sdk_node.yml | Binding freshness, build, packaging, and installed-package validation |
| .github/…/release_sdk_node_npm.yml | Artifact build, package assembly, dry run, and npm publication flow |