Skip to content

hexZeroPad

hexZeroPad(value, length): string

Defined in: utils/bytes.ts:622

Returns a hex string padded to a specified length of bytes.

Similar to “hexZeroPad” in ethers.js

Differs from “padLeft” in web3.js because web3 counts by characters, not bytes.

Parameters

value

BytesLikeWithNumber

A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded

length

number

The final length in bytes

Returns

string

A hex string padded to the specified length

Throws

If the value is not a hex string or number

Throws

If the value is longer than the length

Examples

hexZeroPad('0x60', 2);
// '0x0060'
hexZeroPad(0x60, 3);
// '0x000060'
hexZeroPad('12345', 1);
// Throws