refactor: replace web3 with viem across all packages#765
refactor: replace web3 with viem across all packages#765
Conversation
Remove web3 (1.x) as a dependency from @celo/connect, @celo/contractkit, @celo/celocli, and all SDK packages. Replace with viem-native equivalents: - Delete rpc-contract.ts, promi-event.ts — replace with viem getContract() - Remove RpcCaller, callback Provider, @ethereumjs/* dependencies - Replace web3 ABI types with viem-native equivalents - Migrate all ContractKit wrappers from proxySend/proxyCall to contract.write/read - Replace CeloTransactionObject/TransactionResult with direct tx hash + viem receipt polling - Replace displaySendTx with displayViemTx across all CLI commands - Add strongly-typed generic ABIs to BaseWrapper and all wrappers - Remove bn.js/BigNumber dependencies, use native bigint throughout - Patch buffer-equal-constant-time for Node 25 compatibility
🦋 Changeset detectedLatest commit: eb44a4a The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb44a4aaaf
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (url.endsWith('.ipc')) { | ||
| try { | ||
| const net = require('net') | ||
| web3 = new Web3(new Web3.providers.IpcProvider(url, net)) | ||
| } catch (e) { | ||
| console.error('.ipc only works in environments with native net module') | ||
| } | ||
| web3 = new Web3(url) | ||
| } else if (url.toLowerCase().startsWith('http')) { | ||
| web3 = new Web3(new Web3.providers.HttpProvider(url, options)) | ||
| return new SimpleIpcProvider(url, net) | ||
| } else { | ||
| web3 = new Web3(url) | ||
| return new SimpleHttpProvider(url, options) |
There was a problem hiding this comment.
Preserve websocket URLs in provider selection
getProviderForKit now routes every non-IPC URL through SimpleHttpProvider, so ws:///wss:// nodes are treated as HTTP endpoints. This breaks newKit('ws://...') and CLI flows that call getProviderForKit (for example commands run with --node ws://...), because JSON-RPC requests are sent with the wrong transport and fail before any contract calls execute.
Useful? React with 👍 / 👎.
| data += chunk.toString() | ||
| }) | ||
|
|
||
| socket.on('end', () => { |
There was a problem hiding this comment.
Complete IPC requests without waiting for connection close
The IPC provider resolves requests only inside a socket.on('end') handler, but common Ethereum IPC servers keep sockets open after replying. In that environment the promise never resolves, causing all IPC RPC calls to hang indefinitely. Parsing/fulfilling on message boundaries (or explicitly closing after write) is needed to avoid deadlocking .ipc users.
Useful? React with 👍 / 👎.
size-limit report 📦
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (43.24%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #765 +/- ##
==========================================
- Coverage 69.61% 67.40% -2.21%
==========================================
Files 150 152 +2
Lines 7075 7514 +439
Branches 1163 1183 +20
==========================================
+ Hits 4925 5065 +140
- Misses 2046 2360 +314
+ Partials 104 89 -15
🚀 New features to boost your workflow:
|
Summary
Replaces web3 (1.x) with viem as the native transport layer across all SDK packages and the CLI. No compatibility shims — clean break.
This is a scoped version of #761 with all AI tooling artifacts (
.sisyphus/,.opencode/,AGENTS.md) stripped out.What's removed:
web3,web3-core,web3-eth,web3-eth-abi,web3-eth-contractdependencies from all packagesrpc-contract.ts,promi-event.ts— replaced by viem'sgetContract()RpcCaller, callback-basedProvider,@ethereumjs/*dependenciesCeloTransactionObject/TransactionResult— replaced with direct tx hash +waitForTransactionReceiptbn.js/BigNumber— replaced with nativebigintdisplaySendTx— replaced withdisplayViemTxacross all CLI commandsweb3-contract-cache.ts→contract-factory-cache.tsWhat's added:
contract-types.tsin connect — viem-nativeCeloContract<TAbi>typeBaseWrapperand all wrappers (~110anyeliminated)wallet-adapter.ts— viem wallet adapterbuffer-equal-constant-timepatch for Node 25 compatibilityTest plan
yarn buildpasses across all packagesyarn testpasses inpackages/sdk/connectyarn testpasses inpackages/sdk/contractkityarn testpasses inpackages/cligrep -r "from 'web3" packages/