arrayify

Learn about the arrayify utils method

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:

javascript
1const { Utils } = require("alchemy-sdk");
2
3let hexString = "0x68656c6c6f20776f726c64";
4let byteArray = Utils.arrayify(hexString);
5console.log(byteArray); // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]