48: Function Signature Hash
A function signature hash
is a four-byte representation of a function's signature. It is used to uniquely identify functions
within a contract.
The following code snippet creates a signature hash using the keccak256 hashing algorithm.
Test
The following code snippet creates a signature hash from a transaction.
Example 1: Consider a contract with a function foo(). The signature of the function is foo(). The corresponding signature hash is 0x7f12a5a6.
Example 2: Consider a contract with a function bar(uint a, string memory b). The signature of the function is bar(uint,string). The corresponding signature hash is 0xacb08c82.
Example 3: Consider a contract with a function baz(address payable c, uint256 d). The signature of the function is baz(address,uint256). The corresponding signature hash is 0x8b7d828d.
Function Signature Hash A function signature hash is a unique identifier for a function in a smart contract. It is the result of taking the function parameters and hashing them together with a unique algorithm. This hash can then be used to call the function in the future.
For example, consider the following function:
The function signature hash of this function is 0x2d2b2ece
. This can be calculated by hashing together the function name (addNumbers) and the parameters (uint a, uint b) using a hashing algorithm such as Keccak-256.
Another example is the following function:
The function signature hash of this function is 0xfe710e6f
. This can be calculated by hashing together the function name (multiplyNumbers) and the parameters (uint a, uint b) using a hashing algorithm such as Keccak-256.
That's it for the lesson 48!
Last updated