Learn about the arrayify
utils method
Introduction
The arrayify
method is used to convert a hex string into a byte array. This method is often used to ensure that input values are formatted correctly for various EVM operations.
Usage
This method should be used when a hex string is expected to be an array of bytes. For example, if an EVM contract function is expecting a byte array for a parameter, this method can be used to convert the hex string into the correct format.
Here's a simple code example to demonstrate how to use this method:
const { Utils } = require("alchemy-sdk");
let hexString = "0x68656c6c6f20776f726c64";
let byteArray = Utils.arrayify(hexString);
console.log(byteArray); // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]