I'm trying to recreate the following solidity statement in python:


I have the correct hash function, but I don't know how to recreate the input "this"

Anyone know how to do this?


1 Answer 1


this should be the contract address, which is conventionally represented encoded in hex, prepended by 0x.

You probably have to strip the 0x and turn that into a byte array to feed to your hashing function, so if the contract address is in a variable called addr, do something like:

from sha3 import keccak_256
from rlp.utils import encode_hex, decode_hex

myhash = keccak_256(decode_hex(addr[2:])).hexdigest()

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.