# Docs import React from "react"; ## Getting Started ### Core ```ts twoslash import { Beaut } from "@0xhq/beaut"; // Base. Beaut.address("0x1234567890abcdef1234567890abcdef12345678"); // → "0x1234...5678" Beaut.hash("0xabcde4e7f9ee58b4574bad27d9c1c72a9c656f7cf3b7469c3ea027b456a3d0e"); // → "0xabcd...3d0e" // Currency. Beaut.money(12345.67, { currency: "EUR" }); // → "€12,345.67" // Explorer. Beaut.explorerAddress("https://etherscan.io", "0x1234...5678"); // → "https://etherscan.io/address/0x1234...5678" Beaut.explorerBlock("https://etherscan.io", 17500000); // → "https://etherscan.io/block/17500000" Beaut.explorerTxHash("https://etherscan.io", "0xabcde4e7f9ee58b4574bad27d9c1c72a9c656f7cf3b7469c3ea027b456a3d0e"); // → "https://etherscan.io/tx/0xabcde4e7f9ee58b4574bad27d9c1c72a9c656f7cf3b7469c3ea027b456a3d0e" // Number. Beaut.bigint(1_000_000n, 18); // → "0.000001" Beaut.kmb(1_250_000); // → "1.25M" Beaut.percent(0.1234); // → "12.34%" ``` ### React #### Components #### Hooks ```tsx twoslash import React from 'react'; // ---cut--- import { useBigIntInput } from "@0xhq/beaut/react"; // useBigIntInput. const { value, valueAsBigInt, handleInputChange, isError } = useBigIntInput(); ``` ## Installation Relay is published as `@0xhq/beaut` and ships as ESM. Make sure your project declares `"type": "module"` or uses a bundler that understands `.ts/.mjs` outputs. ### Add the package :::code-group ```bash [pnpm] pnpm add @0xhq/beaut ``` ```bash [npm] npm install @0xhq/beaut ``` ```bash [yarn] yarn add @0xhq/beaut ``` ::: ## Why `@0xhq/beaut` ? ### The problems Building crypto products often starts with a long, familiar checklist: * trim `addresses` for UI, * collapse transaction `hashes`, * format `balances` with the right `locale` and precision, * turn raw block/tx data into `explorer links`, * validating `bigint` forms, ... and the list goes on. Every time, teams end up `reinventing the wheel`, writing their own validation, deciding which locales to support, and patching edge cases behind the scenes. That repetition leaves you less time for the actual product and more for arguing about whether the hash should show 6 or 8 characters. ### The Beaut way `Beaut` is a response to that `fatigue`. Instead of shipping every repo with a bespoke suite of small utilities, Beaut gathers those indispensable helpers into a single, dependable `toolbox` that already validates inputs, applies sane defaults, and exposes a predictable surface across base utilities, currency formatters, explorer link builders, number helpers and more. import { ExampleUseBigIntInput } from "../../../examples/react/hooks/useBigIntInput"; ## useBigIntInput Keeps a controlled input value synchronized with a `bigint` representation while enforcing decimal precision rules, input validation, and an explicit error flag so conversions never throw. ### Usage ```tsx twoslash import React from 'react'; // ---cut--- import { useBigIntInput } from "@0xhq/beaut/react"; const { value, valueAsBigInt, handleInputChange, isError } = useBigIntInput(); // [!code hl] ``` ### Example ### Types #### Parameters ```ts twoslash import { UseBigIntInputParameters } from "@0xhq/beaut/react"; ``` #### Return Type ```ts twoslash import { UseBigIntInputReturnType } from "@0xhq/beaut/react"; ``` import { Beaut } from "@0xhq/beaut"; ## bigint Formats raw `bigint` inputs into human-readable decimal strings. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.bigint(1000000000000000000n, 18, { fallback: "0" }); // [!code hl] Output: "1.0" ``` ### Types #### Parameters ```ts twoslash import { BigintParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { BigintReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## kmb Formats `numbers` into compact K/M/B notation. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.kmb(1500000); // [!code hl] Output: "1.50M" ``` ### Types #### Parameters ```ts twoslash import { KmbParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { KmbReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## percent Formats `percents` into a human-friendly string. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.percent(0.1234); // [!code hl] Output: "12.34%" ``` ### Types #### Parameters ```ts twoslash import { PercentParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { PercentReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## explorerAddress Formats a safe `explorer URL` that points to an `address`. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.explorerAddress("https://etherscan.io", "0x1234567890abcdef1234567890abcdef12345678"); // [!code hl] Output: "https://etherscan.io/address/0x1234567890abcdef1234567890abcdef12345678" ``` ### Types #### Parameters ```ts twoslash import { ExplorerAddressParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { ExplorerAddressReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## explorerBlock Formats a safe `explorer URL` that points to a `block`. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.explorerBlock("https://etherscan.io", 12345678); // [!code hl] Output: "https://etherscan.io/block/12345678" ``` ### Types #### Parameters ```ts twoslash import { ExplorerBlockParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { ExplorerBlockReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## explorerTxHash Formats a safe `explorer URL` that points to a `transaction hash`. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.explorerTxHash( "https://etherscan.io", "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", ); // [!code hl] Output: "https://etherscan.io/tx/0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" ``` ### Types #### Parameters ```ts twoslash import { ExplorerTxHashParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { ExplorerTxHashReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## money Formats `numbers` into localized currency strings. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.money(1234.56, { currency: "EUR" }); // [!code hl] Output: "€1,234.56" ``` ### Types #### Parameters ```ts twoslash import { MoneyParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { MoneyReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## address Formats an `address` into a human-friendly string. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.address("0x1234567890abcdef1234567890abcdef12345678"); // [!code hl] Output: "0x1234...5678" ``` ### Types #### Parameters ```ts twoslash import { AddressParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { AddressReturnType } from "@0xhq/beaut"; ``` import { Beaut } from "@0xhq/beaut"; ## hash Formats a `hash` into a human-friendly string. ### Usage ```ts twoslash import { Beaut } from "@0xhq/beaut"; const formatted = Beaut.hash("0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"); // [!code hl] Output: "0xabcd...7890" ``` ### Types #### Parameters ```ts twoslash import { HashParameters } from "@0xhq/beaut"; ``` #### Return Type ```ts twoslash import { HashReturnType } from "@0xhq/beaut"; ```