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
View File
@@ -19,7 +19,6 @@
"@koins/utils": "workspace:*",
"drizzle-orm": "^1.0.0-beta.22",
"electrobun": "^1.18.1",
"ethers": "^6.16.0",
"mode-watcher": "^1.1.0",
"monero-ts": "^0.11.8",
"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 { tryCatch } from '@koins/utils'
@@ -180,7 +181,7 @@ export const Wallet = () => {
loading = true
error = ''
try {
HDNodeWallet.fromPhrase(phrase.trim())
mnemonicToAccount(phrase.trim())
await electrobun.rpc?.request.setSecret({
service: 'koins',
name: 'vault',
@@ -293,11 +294,11 @@ export const Wallet = () => {
loading = true
error = ''
tokenBalances = []
const wallet = HDNodeWallet.fromPhrase(seed)
address = wallet.address
const provider = new JsonRpcProvider(net().rpc)
const account = mnemonicToAccount(seed)
address = account.address
const client = createPublicClient({ transport: http(net().rpc) })
const [nativeBal, nativeBalError] = await tryCatch(
provider.getBalance(wallet.address),
client.getBalance({ address: account.address }),
)
if (nativeBalError) {
@@ -309,7 +310,7 @@ export const Wallet = () => {
const [bals, balsError] = await tryCatch(
electrobun.rpc.request.fetchTokenBalances({
address: wallet.address,
address: address,
chainid: net().chainid,
}),
)