0

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

sha256(this)

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

Anyone know how to do this?

Thanks!

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, privacy policy and cookie policy

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