1

I am trying to derive the MethodID from the function, based on this post.

However, when I look at this transaction on Etherscan, I cannot see how swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline) can hash to 0x791ac947.

Getting the first 4 bytes of keccak256("swapExactTokensForETHSupportingFeeOnTransferTokens(uint256, uint256, address[], address, uint256)") gives 0x2e701daa.

What am I missing?

gioro
  • 15
  • 4

2 Answers2

3

Almost there!

You need to remove the spaces. So swapExactTokensForETHSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256) -> 0x791ac947. Can be easily tested online at https://emn178.github.io/online-tools/keccak_256.html

Lauri Peltonen
  • 29,391
  • 3
  • 20
  • 57
2

you must remove spaces in between them and wrap that into bytes4 so that you can get the first 4 bytes.

function getHash() external pure returns(bytes4 example){
    example = bytes4(keccak256("swapExactTokensForETHSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256)"));
}

well this returns the value you wanted.

DereK
  • 294
  • 1
  • 10