2

I have the following contract:

pragma solidity ^0.4.17;

contract test{

mapping(bytes4 => bool) internal supportedInterfaces;
uint public a;

function test() public{
          supportedInterfaces[this.transferFrom.selector] = true;
  }

  function supportsInterface(bytes4 interfaceID) external view returns (bool) {
        return supportedInterfaces[interfaceID];
  }


  function transferFrom(address _from, address _to, uint256 _tokenId) public{
     a = 1;
  }

  function transferFrom(address _from, address _to, uint256 _tokenId, bytes data) public{
    a = 2;
  }

}

But I get the error:

Member 'transferFrom' is not unique after argument dependent lookup.

So how do I refer to the selector (or two different ones) in the test function?

Edit: https://github.com/ethereum/solidity/issues/1256 --does this issue mean that it's not resolved?

1 Answer 1

3

I don't know if there's a better way, but you can compute the function selectors directly:

bytes4(keccak256(bytes("transferFrom(address,address,uint256)")))

and

bytes4(keccak256(bytes("transferFrom(address,address,uint256,bytes)")))
1
  • 1
    You forgot to also convert the function signature into bytes : Should be: bytes4(keccak256(bytes("transferFrom(address,address,uint256))")) - bytes4(keccak256(bytes("transferFrom(address,address,uint256,bytes"))) Mar 21, 2020 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.