API ReferenceAdvanced utilities and typesFunction
toAddress()
function toAddress(s): `0x${string}`;Normalizes an address-like string to viem’s EIP-55 checksummed form and casts it to Address.
Throws InvalidArgumentError if s is not valid hex of the
right length — this is not a user-input validation seam (see validateAddress
for that, which returns structured issues instead of throwing); it is for normalizing addresses the
caller already trusts came from the chain, a wallet, or protocol data, so that keys and equality
checks compare consistently regardless of the casing the source used.
Parameters
| Parameter | Type | Description |
|---|---|---|
s | string | The address-like string to normalize. |
Returns
`0x${string}`
The EIP-55 checksummed string typed as Address.
Throws
InvalidArgumentError If s is not valid hex of address
length.