feat(web3-compat): implement full Connection class replacement#140
feat(web3-compat): implement full Connection class replacement#140
Conversation
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
|
tested on a few examples and works well! worth having more eyes for testing complex projects |
🧪 Real-World Testing on Production Project (GASdf)I tested
Test Results
Issues Found1. 🔴 Missing CJS BuildThe Fix: Added CJS output to // Node.js - CJS, unminified (for CommonJS consumers)
{
...nodeConfig,
entry: nodeEntry,
format: ['cjs'],
outDir: 'dist',
outExtension() {
return { js: '.node.cjs' };
},
platform: 'node',
},2. 🔴 Dependencies Not BundledFor a true "drop-in replacement", the package needs to be self-contained. With Fix: Bundle 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 Issue47 remaining failures are related to Instructions created by Recommendation
Happy to test further iterations! 🚀 |
Summary
Complete drop-in replacement for
@solana/web3.jsConnection class, powered by@solana/clientand@solana/kit.Key Features
connection.clientgetter provides access toSolanaClientfor gradual adoption of@solana/clientfeaturesAPI Coverage
Migration to @solana/client
Testing
TEST_PRIVATE_KEYsecret required)Changes in This PR
SolanaClientinstead ofSolanaRpcClientconnection.clientgetter for migration pathconfirmTransactionto accept object strategy and poll for confirmationgetSignatureStatusesparameter issue