This is going to be short question and may be silly, but I'm literally stuck with a problem, where I need to pass address(0)
to function in Truffle Test in JS and don't really know how to do it. In solidity it's simply address(0)
, but in Truffle JS?
3 Answers
You can simply use 0
, or 0x0000000000000000000000000000000000000000
.
address(0)
in Solidity is equivalent to 0x0000000000000000000000000000000000000000
.
-
3
-
4To be clear, you have to use it as a String:
zero_address = "0x0000000000000000000000000000000000000000";
this works for me.– almelJun 10, 2020 at 1:09
You must put single quotes around it. '0x0000000000000000000000000000000000000000' worked for me Been hunting down that bug for some time ...
Don't know about web3.js, but in ethers.js ethers.constants.AddressZero
will do the work.
Example: Suppose you have a transfer function in your contract like this:
function transfer(address to, uint256 amount) public {
require(to != address(0), "Transfer to the zero address");
////
////
}
you can test this by:
await expect(
contract.transfer(ethers.constants.AddressZero, amount)
).to.be.revertedWith("Transfer to the zero address");
You can check out this link for reference: https://docs.ethers.io/v5/api/utils/constants/#constants-AddressZero
-
Hello. Providing a little sample and a link to the function documentation would make this answer way better ;) Jun 18, 2022 at 4:07
-