Skip to content

Commit

Permalink
adding eth balance to wallet details action
Browse files Browse the repository at this point in the history
  • Loading branch information
stat committed Jan 31, 2025
1 parent 2a753d4 commit 2a0a280
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Decimal } from "decimal.js";
import { z } from "zod";
import { ActionProvider } from "../action_provider";
import { WalletProvider } from "../../wallet_providers/wallet_provider";
Expand Down Expand Up @@ -34,6 +35,7 @@ export class WalletActionProvider extends ActionProvider {
This tool will return the details of the connected wallet including:
- Wallet address
- Network information (protocol family, network ID, chain ID)
- ETH token balance
- Native token balance
- Wallet provider name
`,
Expand All @@ -49,13 +51,17 @@ export class WalletActionProvider extends ActionProvider {
const balance = await walletProvider.getBalance();
const name = walletProvider.getName();

// Convert balance from Wei to ETH using Decimal for precision
const ethBalance = new Decimal(balance.toString()).div(new Decimal(10).pow(18));

return `Wallet Details:
- Provider: ${name}
- Address: ${address}
- Network:
* Protocol Family: ${network.protocolFamily}
* Network ID: ${network.networkId || "N/A"}
* Chain ID: ${network.chainId || "N/A"}
- ETH Balance: ${ethBalance.toFixed(6)} ETH
- Native Balance: ${balance.toString()}`;
} catch (error) {
return `Error getting wallet details: ${error}`;
Expand Down

0 comments on commit 2a0a280

Please sign in to comment.