Skip to content

Conversation

@GuiBibeau
Copy link
Collaborator

@GuiBibeau GuiBibeau commented Jan 5, 2026

Summary

Complete drop-in replacement for @solana/web3.js Connection class, powered by @solana/client and @solana/kit.

Key Features

  • Full API Compatibility: 73 methods (59 async RPC + 8 subscription + 6 remove listener)
  • Migration Path: connection.client getter provides access to SolanaClient for gradual adoption of @solana/client features
  • Automatic Type Conversion: bigint-to-number conversion for seamless web3.js compatibility
  • WebSocket Subscriptions: Full support for all subscription types (onAccountChange, onProgramAccountChange, onSignature, onSlotChange, etc.)

API Coverage

  • Core queries: getBalance, getAccountInfo, getMultipleAccountsInfo, getSlot, getBlockHeight
  • Transactions: sendTransaction, sendRawTransaction, confirmTransaction, simulateTransaction
  • Token operations: getTokenAccountsByOwner, getTokenAccountBalance, getTokenSupply
  • Block & history: getBlock, getBlockTime, getTransaction, getSignaturesForAddress
  • Parsed methods: getParsedAccountInfo, getParsedTransaction, getParsedBlock
  • Cluster info: getVersion, getClusterNodes, getEpochInfo, getGenesisHash

Migration to @solana/client

import { Connection } from "@solana/web3-compat";

const connection = new Connection("https://api.devnet.solana.com");

// Get the SolanaClient instance for modern features
const client = connection.client;
await client.actions.connectWallet("phantom");

Testing

  • 277 unit tests passing
  • 24 devnet integration tests with pre-funded account
  • CI workflow for devnet tests (TEST_PRIVATE_KEY secret required)

Changes in This PR

  • Implement full Connection class with all 73 methods
  • Refactor to use SolanaClient instead of SolanaRpcClient
  • Add connection.client getter for migration path
  • Fix confirmTransaction to accept object strategy and poll for confirmation
  • Fix getSignatureStatuses parameter issue
  • Add devnet integration tests with CI workflow
  • Revamp README with example-focused documentation

GuiBibeau and others added 5 commits January 5, 2026 23:20
Transform @solana/web3-compat into a complete drop-in replacement for
@solana/web3.js Connection class, powered by @solana/client and @solana/kit.

Implementation includes:
- 73 total methods (59 async RPC + 8 subscription + 6 remove listener)
- Phase 1: Core high-frequency methods (getMultipleAccountsInfo,
  getTokenAccountsByOwner, sendTransaction, getTransaction, etc.)
- Phase 2: Block and transaction history (getBlock, getBlockTime,
  getBlockHeight, isBlockhashValid, getFeeForMessage, etc.)
- Phase 3: Parsed methods with jsonParsed encoding (getParsedAccountInfo,
  getParsedTransaction, getParsedBlock, etc.)
- Phase 4-7: Slot, epoch, cluster, stake, inflation, and misc methods
- WebSocket subscriptions (onAccountChange, onProgramAccountChange,
  onSignature, onSlotChange, onRootChange, onLogs, etc.)

All methods follow strict web3.js API compatibility with automatic
bigint-to-number conversion for seamless migration.

Tests: 253 passing (12 new tests for Phase 3 and WebSocket subscriptions)
- Refactor Connection to use SolanaClient instead of SolanaRpcClient
- Add `connection.client` getter for gradual migration to @solana/client
- Fix confirmTransaction to accept object strategy and poll for confirmation
- Fix getSignatureStatuses (commitment param not supported by RPC)
- Revamp README with example-focused documentation
- Add devnet integration tests with CI workflow
- Remove experimental language from READMEs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Base58 encoded blockhashes and signatures have variable length
(43-44 chars for hashes, 86-88 for signatures). Updated tests
to use range checks instead of exact length assertions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Devnet integration tests are run in a dedicated CI job with TEST_PRIVATE_KEY.
E2E tests require Playwright which is not installed in the base test environment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@catmcgee
Copy link
Contributor

catmcgee commented Jan 8, 2026

tested on a few examples and works well! worth having more eyes for testing complex projects

@amilz amilz assigned amilz and unassigned amilz Jan 13, 2026
@amilz amilz self-requested a review January 13, 2026 15:45
@zeyxx
Copy link

zeyxx commented Jan 13, 2026

🧪 Real-World Testing on Production Project (GASdf)

I tested @solana/web3-compat as a drop-in replacement for @solana/[email protected] in GASdf - a production gasless transaction layer for Solana with advanced features:

  • VersionedTransactions (V0)
  • Address Lookup Tables
  • Transaction simulation
  • SPL Token operations (burns, transfers)
  • Custom RPC with rate limiting

Test Results

Metric Before After Changes
Test Suites Failed 14 7
Tests Failed 208 47
Tests Passed 790/1011 (78%) 1185/1245 (95%)

Issues Found

1. 🔴 Missing CJS Build

The package.json declares "main": "./dist/index.node.cjs" but the tsup config only generates ESM files. CommonJS projects (like most Node.js backends) can't use the package.

Fix: Added CJS output to tsup.config.package.ts:

// Node.js - CJS, unminified (for CommonJS consumers)
{
  ...nodeConfig,
  entry: nodeEntry,
  format: ['cjs'],
  outDir: 'dist',
  outExtension() {
    return { js: '.node.cjs' };
  },
  platform: 'node',
},

2. 🔴 Dependencies Not Bundled

For a true "drop-in replacement", the package needs to be self-contained. With skipNodeModulesBundle: true, consumers get errors like:

Cannot find module '@solana/transaction-confirmation'
Cannot find module '@solana-program/address-lookup-table'

Fix: Bundle @solana/* deps for web3-compat specifically:

skipNodeModulesBundle: packageDirName !== 'web3-compat',
noExternal: packageDirName === 'web3-compat' ? [/^@solana\//, /^@solana-program\//] : [],

This increases bundle size (163KB → 1.46MB) but makes it truly drop-in.

3. 🟡 SPL-Token Compatibility Issue

47 remaining failures are related to @solana/spl-token integration:

Transaction instruction index 0 has undefined program id

Instructions created by @solana/spl-token (e.g., createBurnInstruction) seem to produce TransactionInstruction objects that aren't fully compatible with web3-compat's Transaction.add().

Recommendation

  1. Add CJS builds to the default config
  2. Consider bundling dependencies for the "compat" package specifically
  3. Investigate the programId issue with spl-token instructions

Happy to test further iterations! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants