Skip to content

Drop ethers.js, migrate to pure viem #803

@dmytrotkk

Description

@dmytrotkk

The portal currently uses ethers v6 across ~50 files, connected to wagmi/viem through a translation layer (ethers.ts) that converts viem wallet clients back into ethers signers. This is a round-trip through two libraries for the same JSON-RPC provider — adds ~120 KB to the bundle and blocks EIP-5792.

This ticket removes ethers entirely and moves everything to viem.

Scope

~50 files across three areas:

Utilities (~25 instances, low risk). Most have 1:1 viem equivalents: parseUnits, formatUnits, getAddress, keccak256, toHex, isHex, hexToNumber, hexToBigInt, encodePacked. Affected files: units.ts, helper.ts, chain.ts, chain_id.ts, miner.ts, delegations.ts.

@skalenetwork/skale-contracts-ethers-v6@skalenetwork/skale-contracts-viem (5 files, medium risk). The viem adapter exists (2.0.0-develop.7, released March 2026). Same API shape, different underlying types. Used in: contracts/index.ts, contracts/baseChain.ts, contracts/paymaster.ts, metaport.ts, credit-station.ts. Risk: pre-release package — if it has gaps, keep ethers for this one dependency and file upstream issues.

Contract and transaction layer (~20 files, bulk of the work). Refactor BaseChain/SChain/MainnetChain classes: provider: ProviderpublicClient: PublicClient, signer: SignerwalletClient: WalletClient. All new Contract(addr, abi, signer)getContract({ address, abi, client }). All .connect(signer) calls go away. Rewrite transactions.ts from signer.sendTransaction() to walletClient.writeContract() + publicClient.waitForTransactionReceipt(). Update error handling (ethers ACTION_REJECTED → viem UserRejectedRequestError). Update MetaportState.ts and all components using useEthersSigner()/useEthersProvider() to use wagmi hooks directly.

Final cleanup. Delete ethers.ts translation layer. Remove ethers from all package.json files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions