简体   繁体   中英

web3.eth.abi.encodeFunctionSignature is not working as expected

I am using ERC165 in order to find out whether my contracts support an interface or not but I get really confusing behaviour form functionEncoding method of web3. Here is my interface

pragma solidity ^0.5.8;


interface ArrayExtraData {
    function submitOfferArrayExtra(uint offerID, uint[] calldata extra) external returns (int status, uint offID);

    function submitRequestArrayExtra(uint requestID, uint[] calldata extra) external returns (int status, uint reqID);
}

I expect to get 0x1ddeb71f as the interface selector which is essentially xor of function selectors but I get 0xe3bfed76.

And here is my js code:

let interfaceFunctions = [
                 'submitOfferArrayExtra(uint,uint[])',
                'submitRequestArrayExtra(uint,uint[])'
             ]

let interfaceId =  interfaceFunctions.
                     map(web3.eth.abi.encodeFunctionSignature).
                     map((x) => parseInt(x, 16)).
                     reduce((x, y) => x ^ y);
interfaceId = interfaceId > 0 ? interfaceId :  0xFFFFFFFF + interfaceId + 1;
interfaceId = '0x' + interfaceId.toString(16);

OK! I found out how it works :)

You have to be more specific about data types. for example, in this case, you must use uint256 instead of uint .

Have Fun.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM