Hash Input
Fixed-length hex hash input for H160, H256, and H512 types with auto-detection
import { HashInput } from "@/components/params/inputs/hash";
// Auto-detects hash type from typeName
<HashInput
name="codeHash"
label="Code Hash"
typeName="H256"
client={client}
typeId={11}
isRequired
onChange={(hash) => console.log("Hash:", hash)}
/>
// Explicit hash type override
<HashInput
name="ethAddress"
label="Ethereum Address"
hashType="H160"
client={client}
typeId={8}
onChange={(hash) => console.log("Hash:", hash)}
/>Hash Input
The Hash input provides a hex string field for fixed-length hash types. The primary component HashInput auto-detects the hash type from the typeName prop, or accepts an explicit hashType override. Three thin wrappers -- Hash160, Hash256, and Hash512 -- are also exported for use in the input-map registry at different priorities.
Supported Type Names
The three Hash variants are registered at different priorities to ensure correct matching:
Hash160 -- priority 82:
H160- Any type name matching
/^H160$/
Hash256 -- priority 80:
H256Hash- Any type name matching
/H256/or/Hash/
Hash512 -- priority 78:
H512- Any type name matching
/^H512$/
Auto-Detection
When using HashInput directly, the hash type is auto-detected from the typeName prop:
- If
typeNamecontains"H160"-> H160 (20 bytes, 40 hex chars) - If
typeNamecontains"H512"-> H512 (64 bytes, 128 hex chars) - Otherwise -> H256 (32 bytes, 64 hex chars) as the default
An explicit hashType prop overrides auto-detection.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Field identifier used for the HTML id and form state |
label | string | No | Display label shown above the input |
description | string | No | Help text shown below the input |
typeName | string | No | The SCALE type name, used for auto-detection (e.g. "H256") |
hashType | "H160" | "H256" | "H512" | No | Explicit hash type override |
isDisabled | boolean | No | Disables the input when true |
isRequired | boolean | No | Shows a red asterisk next to the label |
error | string | No | Validation error message to display |
client | DedotClient<PolkadotApi> | Yes | Connected Dedot client |
typeId | number | No | Metadata type ID for this parameter |
value | any | No | Externally controlled hex value (e.g. from hex decode) |
onChange | (value: unknown) => void | No | Callback fired with the hex hash string |
Features
- Fixed-length validation: Each variant enforces the correct hex character count -- 40 for H160 (20 bytes), 64 for H256 (32 bytes), 128 for H512 (64 bytes).
- Live validation icon: A green checkmark or red X icon appears in the input suffix to indicate whether the current value is a valid hash of the expected length.
- Auto
0xprefix on paste: When pasting a hex string without the0xprefix, the component automatically prepends it using theautoPrefix0xutility. - Lowercase normalization: Input is automatically lowercased for consistent hex formatting.
- Contextual placeholder: Each variant shows a placeholder of the correct length so the user can see the expected format at a glance.
Type Resolution
import { findComponent } from "@/lib/input-map";
// Each hash type resolves to its specific variant
findComponent("H160", typeId, client); // -> Hash160
findComponent("H256", typeId, client); // -> Hash256
findComponent("Hash", typeId, client); // -> Hash256
findComponent("H512", typeId, client); // -> Hash512Usage
import { HashInput, Hash256 } from "@/components/params/inputs/hash";
// Auto-detecting (recommended for generic use)
<HashInput name="hash" label="Hash" typeName="H256" client={client} />
// Explicit variant (used by input-map registry)
<Hash256 name="codeHash" label="Code Hash" client={client} />Validation
Each variant uses a Zod schema that validates the hex string length:
// H160: 40 hex characters (20 bytes)
hash160Schema: /^0x[0-9a-fA-F]{40}$/
// H256: 64 hex characters (32 bytes)
hash256Schema: /^0x[0-9a-fA-F]{64}$/
// H512: 128 hex characters (64 bytes)
hash512Schema: /^0x[0-9a-fA-F]{128}$/Value Format
The onChange callback receives a string -- a 0x-prefixed lowercase hex string of the appropriate length. If the input is cleared, undefined is emitted.