migrate from ethers to viem

- Replace HDNodeWallet.fromPhrase with mnemonicToAccount from viem/accounts
- Replace JsonRpcProvider.getBalance with viem createPublicClient + getBalance
- Replace formatEther with viem's formatEther (same API)
- Remove ethers dependency from package.json
- Update README
This commit is contained in:
2026-05-20 14:31:10 +08:00
parent 79f8a26eb3
commit 49f064f8b1
3 changed files with 9 additions and 10 deletions
+1 -2
View File
@@ -67,8 +67,7 @@ apps/desktop/
## Dependencies ## Dependencies
- [Ethers](https://docs.ethers.org) — EVM wallet operations - [Viem](https://viem.sh) — EVM chain RPC calls + wallet operations
- [Viem](https://viem.sh) — EVM chain RPC calls
- [monero-ts](https://github.com/woodser/monero-ts) — Monero RPC client - [monero-ts](https://github.com/woodser/monero-ts) — Monero RPC client
- [Drizzle ORM](https://orm.drizzle.team) — SQLite schema + queries - [Drizzle ORM](https://orm.drizzle.team) — SQLite schema + queries
- [Svelte 5](https://svelte.dev) — UI framework - [Svelte 5](https://svelte.dev) — UI framework
-1
View File
@@ -19,7 +19,6 @@
"@koins/utils": "workspace:*", "@koins/utils": "workspace:*",
"drizzle-orm": "^1.0.0-beta.22", "drizzle-orm": "^1.0.0-beta.22",
"electrobun": "^1.18.1", "electrobun": "^1.18.1",
"ethers": "^6.16.0",
"mode-watcher": "^1.1.0", "mode-watcher": "^1.1.0",
"monero-ts": "^0.11.8", "monero-ts": "^0.11.8",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",
+8 -7
View File
@@ -1,4 +1,5 @@
import { JsonRpcProvider, HDNodeWallet, formatEther } from 'ethers' import { mnemonicToAccount } from 'viem/accounts'
import { createPublicClient, http, formatEther } from 'viem'
import { electrobun, type TxEntry, type MoneroTxEntry, type MoneroAccountEntry } from '$lib/electrobun' import { electrobun, type TxEntry, type MoneroTxEntry, type MoneroAccountEntry } from '$lib/electrobun'
import { tryCatch } from '@koins/utils' import { tryCatch } from '@koins/utils'
@@ -180,7 +181,7 @@ export const Wallet = () => {
loading = true loading = true
error = '' error = ''
try { try {
HDNodeWallet.fromPhrase(phrase.trim()) mnemonicToAccount(phrase.trim())
await electrobun.rpc?.request.setSecret({ await electrobun.rpc?.request.setSecret({
service: 'koins', service: 'koins',
name: 'vault', name: 'vault',
@@ -293,11 +294,11 @@ export const Wallet = () => {
loading = true loading = true
error = '' error = ''
tokenBalances = [] tokenBalances = []
const wallet = HDNodeWallet.fromPhrase(seed) const account = mnemonicToAccount(seed)
address = wallet.address address = account.address
const provider = new JsonRpcProvider(net().rpc) const client = createPublicClient({ transport: http(net().rpc) })
const [nativeBal, nativeBalError] = await tryCatch( const [nativeBal, nativeBalError] = await tryCatch(
provider.getBalance(wallet.address), client.getBalance({ address: account.address }),
) )
if (nativeBalError) { if (nativeBalError) {
@@ -309,7 +310,7 @@ export const Wallet = () => {
const [bals, balsError] = await tryCatch( const [bals, balsError] = await tryCatch(
electrobun.rpc.request.fetchTokenBalances({ electrobun.rpc.request.fetchTokenBalances({
address: wallet.address, address: address,
chainid: net().chainid, chainid: net().chainid,
}), }),
) )