Vana SDK - v2.2.2
    Preparing search index...

    Function formatEth

    • Format wei value to ETH with specified decimal places

      Parameters

      • wei: string | number | bigint

        Value in wei (as bigint, string, or number)

      • decimals: number = 4

        Number of decimal places to display (default: 4)

      Returns string

      Formatted ETH value as string

      Converts wei (smallest ETH unit) to human-readable ETH format. 1 ETH = 10^18 wei. The function truncates rather than rounds to ensure predictable display in financial contexts.

      Edge Cases:

      • Truncates (not rounds) to specified decimal places
      • Negative values are supported
      • Zero values return "0.0000" (based on decimals)
      • Very small values may display as "0.0000" due to truncation
      // Standard conversions
      formatEth(1000000000000000000n) // Returns: "1.0000"
      formatEth(1500000000000000000n, 2) // Returns: "1.50"
      formatEth("2000000000000000000") // Returns: "2.0000"

      // Edge cases
      formatEth(1000000000000000n) // Returns: "0.0010" (0.001 ETH)
      formatEth(100000000000000n) // Returns: "0.0001"
      formatEth(10000000000000n) // Returns: "0.0000" (truncated)
      formatEth(-1000000000000000000n) // Returns: "-1.000"