1

I'm trying to write a function in vyper that takes two addresses and returns a 256-bit hash (either keccak256 or sha256).

Afaik the builtin hash functions only take Bytes, bytes32 and Strings as inputs, and there are no type conversions from address to any of those types.

How can I make a hash of two addresses like this?

1 Answer 1

1

There are two ways to do this, with slightly different results.

# @version 0.3.2

# address1 and address2 are left-padded with zeros before the hash
keccak256(_abi_encode(address1, address2))

# bytes20 is available as of v0.3.2
# hash the 40 bytes of the two addresses concatenated together
keccak256(concat(convert(address1, bytes20), convert(address2, bytes20))

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.