Skip to content

refactor(explorer,governance,wallets,dev-utils): migrate to viem [3/8]#768

Open
pahor167 wants to merge 1 commit intopahor/viem-B-contractkitfrom
pahor/viem-C-sdk-peripherals
Open

refactor(explorer,governance,wallets,dev-utils): migrate to viem [3/8]#768
pahor167 wants to merge 1 commit intopahor/viem-B-contractkitfrom
pahor/viem-C-sdk-peripherals

Conversation

@pahor167
Copy link
Copy Markdown
Contributor

@pahor167 pahor167 commented Apr 1, 2026

Stack

A β†’ B β†’ C β†’ D1 β†’ D2 β†’ D3 β†’ D4 β†’ D5 (CI)

Changes

  • explorer: replace web3 Contract with viem getContract(), remove deprecated ABI helpers
  • governance: replace createViemTxObject with encodeFunctionData in ProposalBuilder
  • wallets: replace web3 signing utils with viem equivalents across all HSM/ledger/local wallets
  • dev-utils: chain-setup and test utils use viem client
  • transactions-uri: remove web3 dependency

Part of the web3 β†’ viem migration. No CI requirement on this PR.


PR-Codex overview

This PR focuses on updating dependencies, improving code consistency, and enhancing the handling of transactions and contracts within the SDK. It transitions from using Web3 to viem for transaction handling and modifies various files to accommodate this change.

Detailed summary

  • Updated package.json files to include viem and remove or replace Web3.
  • Enhanced transaction handling by switching from Web3 methods to viem methods.
  • Added a bigintReplacer function for JSON serialization of BigInt.
  • Modified contract interaction methods to use kit._contracts instead of kit._web3Contracts.
  • Adjusted tests to utilize newKitFromProvider instead of newKitFromWeb3.
  • Improved error handling and logging throughout various modules.
  • Changed transaction value handling from Web3.utils.toWei to direct numeric values using parseEther.

The following files were skipped due to too many changes: packages/dev-utils/src/anvil-test.ts, packages/sdk/wallets/wallet-local/src/signing.test.ts, packages/sdk/explorer/src/sourcify.ts, packages/dev-utils/src/test-utils.ts, packages/sdk/governance/src/proposals.ts, packages/sdk/explorer/src/block-explorer.ts, packages/sdk/explorer/src/sourcify.test.ts, packages/sdk/governance/src/proposal-builder.ts, packages/sdk/wallets/wallet-base/src/signing-utils.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

- explorer: replace web3 Contract with viem getContract(), remove deprecated ABI helpers
- governance: replace createViemTxObject with encodeFunctionData in ProposalBuilder
- wallets: replace web3 signing utils with viem equivalents across all HSM/ledger/local wallets
- dev-utils: chain-setup and test utils use viem client
- transactions-uri: remove web3 dependency
@pahor167 pahor167 requested a review from a team as a code owner April 1, 2026 09:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

⚠️ No Changeset found

Latest commit: 7a57a73

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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: 7a57a73ca2

ℹ️ 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".

return makeEven(`0x` + num.toString(16)) as StrongAddress
}
return makeEven(Web3.utils.numberToHex(num)) as StrongAddress
return makeEven(ensureLeading0x(Number(num).toString(16))) as StrongAddress
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 integer precision in string-to-hex conversion

stringNumberToHex now converts string inputs via Number(num).toString(16), which loses precision for many on-chain values above 2^53 (for example 1000000000000000001). Since this helper is used for value, gasPrice, maxFeePerGas, etc., transactions can be encoded with silently wrong amounts and then signed/broadcast incorrectly. Convert decimal strings with bigint/string arithmetic instead of Number.

Useful? React with πŸ‘Β / πŸ‘Ž.

Comment on lines 89 to +93
async fetchBlockByHash(blockHash: string): Promise<Block> {
return this.kit.connection.getBlock(blockHash)
return this.kit.connection.viemClient.getBlock({ blockHash: blockHash as `0x${string}` })
}
async fetchBlock(blockNumber: number): Promise<Block> {
return this.kit.connection.getBlock(blockNumber)
return this.kit.connection.viemClient.getBlock({ blockNumber: BigInt(blockNumber) })
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 Fetch blocks with full transactions for parser compatibility

These getBlock calls omit includeTransactions: true, so viem returns transaction hashes by default; parseBlock then skips all string entries (typeof tx !== 'string'), leaving parsedTx empty even when blocks contain known calls. This is a functional regression from the previous Connection.getBlock(..., fullTxObjects=true) behavior and breaks block parsing results.

Useful? React with πŸ‘Β / πŸ‘Ž.

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