Ethers.js – How to Create an Empty bytes or bytes32 in Ethers.js

ethers.js

I have a function that takes a bytes in solidity, and I want to pass it an empty bytes string without doing "0x000…", can I do this in ethersjs?

Best Answer

ethers.js has a Constants object that contains common values. One of those is ethers.constants.HashZero, which represents an empty bytes32 string.

There are more constants that you could read about here: https://docs.ethers.io/v5/api/utils/constants

For bytes, you would place an empty array ([]) as input in ethers.js. This is due to bytes being an array-based value.