dAppBooster
    Preparing search index...

    Function getTruncatedHash

    • Truncates a hash string (like an Ethereum address or transaction hash) by preserving the beginning and end.

      This function is specifically designed for blockchain-related hash values with the "0x" prefix, automatically preserving the prefix in addition to the specified number of characters.

      Parameters

      • hash: string

        The hash string to truncate (typically starts with "0x")

      • Optionallength: number = 6

        The number of characters to preserve at both start and end (min: 1, max: 16, excluding the "0x" prefix)

      Returns string

      The truncated hash with ellipsis in the middle

      // Truncate an Ethereum address with default length
      getTruncatedHash("0x1234567890abcdef1234567890abcdef12345678");
      // Returns: "0x123456...345678"
      // Truncate with custom length
      getTruncatedHash("0x1234567890abcdef1234567890abcdef12345678", 4);
      // Returns: "0x1234...5678"
      // Truncate with maximum length
      getTruncatedHash("0x1234567890abcdef1234567890abcdef12345678", 16);
      // Uses maximum of 16: "0x1234567890abcdef...1234567890abcdef"