Skip to content

refactor: replace web3 with viem across all packages#765

Open
pahor167 wants to merge 1 commit intomasterfrom
pahor/web3-to-viem-clean
Open

refactor: replace web3 with viem across all packages#765
pahor167 wants to merge 1 commit intomasterfrom
pahor/web3-to-viem-clean

Conversation

@pahor167
Copy link
Copy Markdown
Contributor

@pahor167 pahor167 commented Apr 1, 2026

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-contract dependencies from all packages
  • rpc-contract.ts, promi-event.ts — replaced by viem's getContract()
  • RpcCaller, callback-based Provider, @ethereumjs/* dependencies
  • CeloTransactionObject / TransactionResult — replaced with direct tx hash + waitForTransactionReceipt
  • bn.js / BigNumber — replaced with native bigint
  • displaySendTx — replaced with displayViemTx across all CLI commands
  • web3-contract-cache.tscontract-factory-cache.ts

What's added:

  • contract-types.ts in connect — viem-native CeloContract<TAbi> type
  • Strongly-typed generic ABIs on BaseWrapper and all wrappers (~110 any eliminated)
  • wallet-adapter.ts — viem wallet adapter
  • buffer-equal-constant-time patch for Node 25 compatibility

Test plan

  • yarn build passes across all packages
  • yarn test passes in packages/sdk/connect
  • yarn test passes in packages/sdk/contractkit
  • yarn test passes in packages/cli
  • No web3 imports remain: grep -r "from 'web3" packages/

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
@pahor167 pahor167 requested a review from a team as a code owner April 1, 2026 08:58
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: eb44a4a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
@celo/wallet-ledger Patch
@celo/celocli Major
@celo/connect Major
@celo/contractkit Major
@celo/dev-utils Minor
@celo/explorer Patch
@celo/governance Patch
@celo/transactions-uri Patch
@celo/wallet-base Patch
@celo/wallet-hsm-aws Patch
@celo/wallet-hsm-azure Patch
@celo/wallet-hsm-gcp Patch
@celo/wallet-local Patch
@celo/wallet-remote Patch
@celo/wallet-hsm Patch

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 150 to +153
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

size-limit report 📦

Path Size
require('@celo/actions') (cjs) 98.85 KB (0%)
import * from '@celo/actions' (esm) 23.55 KB (0%)
import { resolveAddress } from '@celo/actions' (esm) 23.49 KB (0%)
import { getGasPriceOnCelo } from '@celo/actions' (esm) 73 B (0%)
import { getAccountsContract } from '@celo/actions/contracts/accounts' (esm) 46.11 KB (0%)
import * from '@celo/actions/staking' (esm) 50.66 KB (0%)

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

❌ Patch coverage is 43.24943% with 248 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.40%. Comparing base (2276386) to head (eb44a4a).

❌ 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     
Components Coverage Δ
celocli ∅ <ø> (∅)
sdk 66.09% <43.24%> (-3.04%) ⬇️
wallets 73.02% <ø> (-0.13%) ⬇️
viem-sdks 94.15% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant