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:
@@ -67,8 +67,7 @@ apps/desktop/
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [Ethers](https://docs.ethers.org) — EVM wallet operations
|
||||
- [Viem](https://viem.sh) — EVM chain RPC calls
|
||||
- [Viem](https://viem.sh) — EVM chain RPC calls + wallet operations
|
||||
- [monero-ts](https://github.com/woodser/monero-ts) — Monero RPC client
|
||||
- [Drizzle ORM](https://orm.drizzle.team) — SQLite schema + queries
|
||||
- [Svelte 5](https://svelte.dev) — UI framework
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user