I am writing a fallback function this way:

fallback() external {        
     (param1, param2) = abi.decode(msg.data[4:], (uint256, uint256));

I know this is not a good practice but let's suppose i call an "azerty" function on my contract with 2 uint256. And of course, azerty function does not exists. So fallback function will be called.

I have 2 questions inside this fallback function:

  • How can i get the function name (azerty) ?
  • Is there a way to get the arguments types and count ? (in my case, i know i have 2 uint256 but what will happen if i call azerty with a single uint argument ?


1 Answer 1


It is not possible to recover the function name from the transaction alone since only 4 bytes from the function identifier are include. Those 4 bytes are also accessible through msg.sig.

It should be possible to store a mapping in the contract so they can be recovered from the identifier: mapping (bytes4 => string) public signatures. Store them signatures[bytes4(0x70a08231)] = "balanceOf(address)", using it signatures[msg.sig].

Recent solidity version validate a function has enough data and revert if they have less than expected.

Using fallback skips any validation but abi.decode fails when there's not enough data to decode all of its parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.