The function to call is called xyz().

My code:



AttributeError: module 'web3' has no attribute 'sha3'

In newer versions of web3, the above error occurs. What else can be used to get the hexadecimal equivalent of the function name?

Source of code: How to know the hex code to use in data to call a specific contract function? (the solution doesn't work on newer versions of web3)

2 Answers 2


The hexadecimal equivalent of the method is called the function selector.

The function selector is the first 4 bytes of Keccak hash of the function signature, arguments packed as string types.

You can get this by:

>>> from web3 import Web3
>>> Web3.keccak(text="xyz()")
>>> hex_bytes = Web3.keccak(text="xyz()")
>>> print(hex_bytes[0:4].hex())
  • 2
    it is also called signature , within the sources it is called signature, but in solidity it is called selector
    – Nulik
    Commented Jul 31, 2021 at 18:46
  • Thank you @Nulik. I believed the selector refers to Solidity 4-byte identifier whereas the function signature is a general programming language concept. Commented Aug 1, 2021 at 11:34

you are looking for this:



Encodes the function name to its ABI signature, which are the first 4 bytes of the sha3 hash of the function name including types.


In pythhon there should exist an equivalent call

  • I have been searching the equivalent for ages but still didn't manage to find it, do you by any chance know it?
    – CodeNoob
    Commented Sep 4, 2021 at 14:41

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.