Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-web3.js

Solana JavaScript SDK

View on GitHub

23 documents · Updated Nov 16, 2026

docs / kit-adapters

Solana Kit compatibility adapters

The Solana Kit compatibility adapters form the boundary between the class-based web3.js API and the typed Solana Kit API. They let web3.js callers use Kit instructions, signers, RPC values, and WebSocket events without exposing Kit wire shapes through the public API. This page extends Connection and RPC and relates to RPC connection operations, WebSocket subscriptions, and Programs and instructions.

Adapter boundary

The adapters keep two API models joined while each model keeps its own purpose. Web3.js provides familiar PublicKey, TransactionInstruction, Connection, and callback shapes. Solana Kit provides typed addresses, request configs, signers, and RPC transport values. Connection creates the Kit-backed RPC client and subscription runtime, then uses the adapters at the edges of each public operation.

The boundary has two directions:

  • Into Kit: web3.js inputs become typed request configs, Kit instructions, Kit signer transactions, or normalized subscription specifications.
  • Out of Kit: RPC results and WebSocket notifications become web3.js account, block, transaction, and callback values.

This diagram shows how the adapters sit between public web3.js operations and Kit transport or signing services.

flowchart LR
    Web3[web3.js public API] --> In[Input adapters]
    In --> Kit[Solana Kit RPC and signer APIs]
    Kit --> Out[Output adapters]
    Out --> Web3
    Web3 --> SubIn[Subscription spec adapters]
    SubIn --> Socket[Kit WebSocket runtime]
    Socket --> SubOut[Notification adapters]
    SubOut --> Web3

Instruction compatibility

The instruction adapters allow message and transaction APIs to accept either web3.js instructions or Kit instructions. They preserve the program address, account order, signer and writable roles, and instruction bytes while changing only the surrounding shape.

Instruction shapes

The Kit instruction shape names the program as programAddress and stores account metadata as address-and-role pairs. The web3.js shape uses a PublicKey program ID and account entries with isSigner and isWritable flags. toKitInstruction maps between these fields, and fromKitInstruction materializes missing account and data arrays as empty values.

The shape check is also a safety boundary. A value that carries Kit fields and legacy fields at the same time is rejected instead of allowing the two views to disagree. A valid Kit address, account role, and byte array are required before the value enters a transaction or message.

References: packages/…/instruction.ts• L13-43 packages/…/instruction-fields.ts• L10-22 packages/…/instruction-guard.ts• L7-80 packages/…/message.ts• L41-57

Instruction plans

An instruction plan is a Kit description of instruction groups that can be expanded before a single web3.js message or transaction is built. The adapter flattens plans into ordered instruction leaves, so a single-transaction API can consume the same input as a Kit builder.

Plans that are designed to span several transactions are not silently reduced to one transaction. The adapter rejects those leaves because doing so would change the plan's meaning and could produce an incomplete or invalid transaction.

References: packages/…/instruction-plan.ts• L11-45 packages/…/legacy.ts• L385-417 packages/…/message.ts• L22-57

RPC request and response compatibility

The request and response adapters keep Connection as the web3.js-facing RPC boundary while Kit supplies typed RPC method shapes. Connection sends requests through its Kit RPC client, and the adapters make the conversion in one place so HTTP methods and WebSocket code use the same rules for addresses, encodings, numbers, filters, and transaction versions.

RPC request shapes

Request adapters turn web3.js options into the explicit configs expected by Kit RPC methods. They carry commitment and transaction-version settings, select block and transaction detail modes, convert numeric values such as slots and offsets to bigint, and mark encoded byte strings as base58 or base64 values.

They also validate choices that the wire format cannot represent as an ambiguous value. A token-account filter must select exactly one of mint or programId. A program-account filter must select exactly one of memcmp or dataSize. These checks keep a caller error from becoming a misleading RPC request.

References: packages/…/request.ts• L39-145 packages/…/request.ts• L157-252 packages/…/request.ts• L255-381

RPC response shapes

Response adapters turn Kit RPC results back into web3.js values. They normalize addresses to PublicKey, decode account and instruction data where the public API expects bytes, preserve parsed data where requested, and convert numeric ledger values to bigint.

The same boundary handles simulation results, blocks, transaction metadata, parsed instructions, address lookup data, and legacy or supported versioned messages. It keeps absent fields absent and keeps explicit null values distinct from omitted values. Unsupported transaction versions fail instead of being treated as legacy transactions.

References: packages/…/response.ts• L261-359 packages/…/response.ts• L514-588 packages/…/response.ts• L690-717 packages/…/response.ts• L943-985 packages/…/response.ts• L1107-1166

Signing compatibility

The signing adapter lets web3.js transactions use Solana Kit transaction partial signers without giving a signer permission to change the message being signed. It connects the serialized bytes and existing signature state held by web3.js to Kit's transaction signing contract.

Transaction signing inputs

The adapter builds a Kit transaction view from the already compiled web3.js message. It derives the lifetime from the message, carries an available block-height limit when one exists, seeds signatures that are already present, and asks each distinct Kit partial signer to sign the same message bytes.

The result returns only valid signatures keyed by signer address. It checks signer type, transaction size, and signature length. This makes web3.js legacy and versioned transactions share one signing rule while still allowing Kit key-pair, hardware, remote, and no-op signers.

References: packages/…/signing.ts• L27-98 packages/…/signing.ts• L100-132 packages/…/legacy.ts• L713-774 packages/…/versioned.ts• L179-209

Subscription compatibility

Subscription adapters translate the public Connection listener API into Kit WebSocket subscription inputs and translate Kit notifications back into callback arguments. Connection registers each normalized specification with the subscription controller, while the Kit runtime owns transport and lifecycle work. The adapters own the meaning of request options and payload values.

Subscription request shapes

Subscription spec builders normalize account, program, logs, signature, and block listener inputs into one internal specification. They turn PublicKey values into addresses, map log key filters to mentions, apply default account encoding, and map the public rewards option to Kit's showRewards wire field.

The subscription type surface keeps callback and result types tied to the selected encoding or block detail mode. This lets the connection select the right output shape before the runtime opens a Kit subscription.

References: packages/…/subscription-specs.ts• L54-143 packages/…/subscription-types.ts• L39-167 packages/…/connection.ts• L6204-6308 packages/…/connection.ts• L6417-6478

Subscription notifications

Notification adapters convert raw Kit WebSocket payloads into values that web3.js callbacks can use. Account notifications decode base58 or base64 data, preserve base64-plus-Zstandard data for its dedicated type, map owners to PublicKey, and reject the RPC base58 overflow sentinel with guidance to use base64.

Block notifications map the selected transaction detail and encoding into the matching web3.js block result. The controller applies these adapters after the runtime receives a notification, so transport state and callback data remain separate concerns. Signature notifications also become the web3.js received or terminal status forms, and terminal status marks the server subscription as already disposed.

References: packages/…/account-notifications.ts• L24-75 packages/…/account-notifications.ts• L78-146 packages/…/block-notifications.ts• L441-500 packages/…/controller.ts• L47-159 packages/…/runtime.ts• L59-180 packages/…/connection.ts• L6395-6477

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the accepted instruction shapes aligned with the conversion, guard, plan expansion, and message compilation paths.
  • Keep Kit request config fields aligned with the web3.js options that Connection passes for both HTTP calls and subscriptions.
  • Preserve the difference between omitted fields and explicit null values when mapping RPC results.
  • Keep numeric conversion and supported transaction-version rules aligned across HTTP responses, block notifications, and transaction messages.
  • Keep account and block notification decoding aligned with the encoding-specific callback types and the dispatch config stored by the subscription registry.
  • Preserve the signing lifetime and existing-signature rules when changing transaction serialization or signer inputs.
  • Keep the Connection-created Kit RPC client and subscription runtime aligned with the adapter contracts when changing connection setup or listener registration.

Important failure modes

TriggerConsequenceGuard
An instruction object contains both Kit and legacy fields.The transaction can receive conflicting program or account data.Reject the value as an ambiguous instruction before conversion.
A multi-transaction instruction-plan leaf enters a single-transaction API.The plan cannot be honored as one transaction.Reject unsupported plan leaves during expansion.
A token or program account filter selects both alternatives or neither.The RPC request does not describe one valid filter.Validate the exclusive filter choice at the request boundary.
A response contains an unsupported transaction version.The client could misread a newer message as a legacy message.Reject the version during response normalization.
An account subscription uses base58 for data above the RPC size limit.The callback cannot receive the account bytes.Surface the overflow error and use base64 for the subscription.
A signer returns a signature with the wrong length.The transaction would carry invalid authorization data.Check every returned signature before adding it to the web3.js transaction.
A terminal signature notification is followed by explicit server unsubscribe work.The client sends a redundant removal for an already disposed RPC subscription.Mark the server subscription as auto-disposed during notification dispatch.

Key files

FileWhy to read it
packages/…/instruction.ts and instruction-guard.tsDefine the two instruction shapes and the safety check that separates them.
packages/…/instruction-plan.tsShows how Kit instruction plans enter single-transaction web3.js APIs.
packages/…/request.tsDefines the main web3.js-to-Kit RPC request rules and filter validation.
packages/…/response.tsDefines the shared Kit-to-web3.js mapping for accounts, blocks, simulations, and transactions.
packages/…/signing.tsShows how compiled web3.js message bytes reach Kit partial signers.
packages/…/subscription-specs.ts and subscription-types.tsDefine subscription input normalization and the public callback contract.
packages/…/account-notifications.ts and block-notifications.tsDefine account and block WebSocket payload normalization.
packages/…/controller.ts and runtime.tsShow where notification adapters meet Kit transport and web3.js callbacks.
packages/…/connection.tsShows how Connection creates the Kit RPC and subscription services and passes public operations through the adapters.
packages/web3.js/test/kit-adapter-testsDemonstrates the compatibility contract for instructions, requests, responses, and notifications.