zeroPad

Learn about the zeroPad utils method

Introduction

The zeroPad method is used to pad a hex string into a byte array with leading zeros so that its length is 64 characters.

Usage

This method should be used when you want to pad a hex string into a byte array with leading zeros so that its length is 64 characters. For example, you can use this method to pad the hex string '0x1234' into:

Uint8Array(64) [
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 18, 52
]

Here's a simple code example to demonstrate how to use this method:

const { Utils } = require("alchemy-sdk");

let hexString = '0x1234';

let zeroPaddedHexByteArray = Utils.zeroPad(hexString, 64); 
console.log(zeroPaddedHexByteArray); 

/*
Output:

Uint8Array(64) [
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 18, 52
]
*/
ReadMe