refactor(explorer,governance,wallets,dev-utils): migrate to viem [3/8]#768
refactor(explorer,governance,wallets,dev-utils): migrate to viem [3/8]#768pahor167 wants to merge 1 commit intopahor/viem-B-contractkitfrom
Conversation
- 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
|
There was a problem hiding this comment.
π‘ 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 |
There was a problem hiding this comment.
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 πΒ / π.
| 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) }) |
There was a problem hiding this comment.
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 πΒ / π.
Stack
Changes
getContract(), remove deprecated ABI helperscreateViemTxObjectwithencodeFunctionDatainProposalBuilderchain-setupand test utils use viem clientPart 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
Web3toviemfor transaction handling and modifies various files to accommodate this change.Detailed summary
package.jsonfiles to includeviemand remove or replaceWeb3.Web3methods toviemmethods.bigintReplacerfunction for JSON serialization ofBigInt.kit._contractsinstead ofkit._web3Contracts.newKitFromProviderinstead ofnewKitFromWeb3.Web3.utils.toWeito direct numeric values usingparseEther.