Solidity – How to Get Interface ID of Solidity Interface Using Ethers.js?

eip-165ethers.jsinterfacessolidity

Is there a way to get an interface ID of a Solidity interface using ethersjs? I'm using ethersjs in my test file and I want to test if the supportsInterface is returning a correct interface ID.

I could get the interface ID in Solidity with type(IMyContract).interfaceId but it doesn't seem like there is a straightforward way of achieving the same thing outside of Solidity.

How can I get the interface ID of a contract or interface in ethersjs?

Best Answer

Currently there is not. You have to xor all function selectors of IMyContract.

To make your life easier, you can use ethers.js interface and use its getSighash functions to not have to hash it and slice it ourself. But still you have to xor these selectors to get an interfaceId.

Related Topic