7

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?

Patrick Collins
  • 11,186
  • 5
  • 44
  • 97

2 Answers2

7

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.

Ahmed Ihsan Tawfeeq
  • 4,524
  • 2
  • 19
  • 47
5
let value = ethers.utils.formatBytes32String("")

This will give you 0x00....00

Patrick Collins
  • 11,186
  • 5
  • 44
  • 97