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?
Asked
Active
Viewed 8,575 times
7
Patrick Collins
- 11,186
- 5
- 44
- 97
2 Answers
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
-
1In Ethers.js V6,
formatBytes32Stringwas replaced byencodeBytes32String. – Peter Feb 11 '23 at 04:24
bytes. – Ahmed Ihsan Tawfeeq Feb 23 '22 at 15:460xhex value would also work. – Ahmed Ihsan Tawfeeq Feb 23 '22 at 17:17