Search code examples
solidityeverscale

How to get funID?


need help to get the correct funcID. I've Tried many ways. Will be glad to get your help. Thanks!

slugSha256() {
  slug=$(echo -n "$1" | sha256sum | cut -d' ' -f1)
  echo -n $((16#"${slug:0:8}"))
}
functionHash() {
  hash=$(slugSha256 "$(echo -n "$1" | sed 's/ //g')")
  if [[ "$1" == *constructor* ]]; then hash=$((hash ^ (2 ** 31))); fi
  printf '0x%x' "$hash"
}
functionID() { functionHash "$1v2"; }

`

functionID "main()(string)" # 0xb0992770
functionID "redeem(uint256, string, uint256)()" # 0x58160fa0
functionID "constructor()()" # 0x68b55f3f


Solution

  • foo.sol

    pragma ever-solidity >= 0.64.0;
    contract foo {
     constructor() public {}
     function main() public returns (string) {}
     function redeem(uint256 a, string b, uint256 c) public {}
    }
    

    via everdev npx everdev sol update

    ~/.everdev/solidity/solc --function-ids foo.sol

    via sold: sold --function-ids foo.sol

    out:

    {
      "constructor": "0x68b55f3f",
      "main": "0x30992770",
      "redeem": "0x58160fa0"
    }
    
    

    via web tool https://ever.bytie.moe/serializer

    enter image description here