Web3JS Online
Viem Online
Webhooks, Alerts, and a simple API.
The leftPad function is a utility method provided by the web3.utils module that adds a padding to the left of a string. The function takes three parameters: value, characterAmount, and sign.
The value parameter is the string or number that you want to pad. If value is an integer or bigint, it will be converted to a hex string.
The characterAmount parameter is the number of characters that you want to add to the left of the value.
The sign parameter is an optional string that specifies the character to use for the padding. If sign is not provided, the padding character will be '0' by default.
The function returns a string that is the result of adding the padding to the left of the value.
Here's an example usage of the leftPad function:
In this example, the leftPad function is called with the value 123, the character amount 4, and the sign 0. The function returns the string 0000123, which has a padding of four zeros on the left. In the second call, the leftPad function is called with the value 'hello', the character amount 4, and the sign ' '. The function returns the string ' hello', which has a padding of four spaces on the left.
The leftPad function is useful for formatting data in a way that is consistent with the expected format of a particular application or system. It can be used to add leading zeros to a number, leading spaces to a string, or any other type of padding that is needed.