Skip to main content

In Solidity function signatures are 4 bytes long and the formula to generate it is to hash it with the keccak256 function, like so:

bytes4(keccak256(“setA(uint256)”))

bytes4(keccak256("setA(uint256)"))

The first 4 bytes of msg.datamsg.data are the method signature. How can I extract those 4 bytes from msg`msg.data (using Solidity of course)?

In Solidity function signatures are 4 bytes long and the formula to generate it is to hash it with the keccak256 function, like so:

bytes4(keccak256(“setA(uint256)”))

The first 4 bytes of msg.data are the method signature. How can I extract those 4 bytes from msg.data (using Solidity of course)?

In Solidity function signatures are 4 bytes long and the formula to generate it is to hash it with the keccak256 function, like so:

bytes4(keccak256("setA(uint256)"))

The first 4 bytes of msg.data are the method signature. How can I extract those 4 bytes from `msg.data (using Solidity of course)?

Source Link
forhas
  • 825
  • 1
  • 10
  • 30

How to extract function signature from msg.data

In Solidity function signatures are 4 bytes long and the formula to generate it is to hash it with the keccak256 function, like so:

bytes4(keccak256(“setA(uint256)”))

The first 4 bytes of msg.data are the method signature. How can I extract those 4 bytes from msg.data (using Solidity of course)?