UNPKG

@avalanche-sdk/client

Version:

A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa

29 lines (27 loc) 888 B
import { Address } from "viem"; import { parseAccount } from "viem/utils"; import { AvalancheAccount } from "../avalancheAccount"; /** * Parse an account or address to an AvalancheAccount * * @param account - The account or address to parse {@link AvalancheAccount} * @returns The parsed account {@link AvalancheAccount} or undefined if not provided * * @example * ```ts * import { parseAvalancheAccount } from "@avalanche-sdk/client/accounts"; * * const account = parseAvalancheAccount("0xab...."); * console.log(account); * * ``` */ export function parseAvalancheAccount< accountOrAddress extends Address | AvalancheAccount | undefined >( account: accountOrAddress ): accountOrAddress extends Address ? AvalancheAccount : accountOrAddress { if (typeof account === "string") return { evmAccount: parseAccount(account) as any } as any; return account as any; }