WETH9 low level staticcall to `allowances`

The following code seems to revert and I'm not sure why, does anyone spot anything off?

(bool allowance, bytes memory returnData) = weth.staticcall(abi.encodeWithSignature("allowance(address, address)", msg.sender, 0xFd495eeEd737b002Ea62Cf0534e7707a9656ba19));
        require(allowance, "allowance query did not work");

I'm guessing it's cause WETH9 doesn't actually adhere to the ERC20 standard, in this case allowances is a public mapping(address => mapping (address => uint)). It doesn't implement a public view allowance function. If I'm right about what the problem is, how do I query allowances with a lowlevel staticcall?
Edit: After reading the docs on generated getters I don't think that's the issue either. Maybe the problem is I'm making a staticcall to a contract compiled with solidity v0.4.18? Should I just do a regular call?

Would appreciate your help on this @frangio and/or @martriay, thanks!

Can you try removing the space in the signature

-allowance(address, address)
+allowance(address,address)

Ideally you would be using a normal Solidity call so that this error could not happen.

1 Like

Oh wow, can't believe I missed that. Why would a regular call prevent that from happening though?

Just to be clear, by "normal Solidity call" I meant something like weth.allowances(msg.sender, 0x...), rather than manually putting together the calldata using abi.encodeWithSignature.

If you do need to manually encode the calldata for some reason, prefer using abi.encodeWithSelector instead to prevetn this kind of mistake, in the following way:

abi.encodeWithSelector(IERC20.allowance.selector, msg.sender, 0x...)
3 Likes

Noted, thank you so much!