2

I try to convert a "key_hash" to "address" data type.

In OCaml syntax like: let key_h = (addr : key_hash) in

and ReasonML syntax like: let key_h = (addr : key_hash);

have the same error:

Type error:  Unexpected type in annotated expression.
Expected type:
    address
Actual type:
    key_hash

I found this advice, but it doesn't solve my problem...

Can I solve this directly? Or only work around?

Thanks in advance!

3

To convert a key_hash to an address, you can use:

# Liquidity
Contract.address (Account.default k)

# Michelson
IMPLICIT_ACCOUNT; ADDRESS

To convert an address to a key_hash is more difficult. Michelson does not expose any nice way to do this.

Hopefully, a future protocol change will add an operation for this.

For now, it might be best to work around it. Have someone pass a key or key_hash in the parameter instead. If you need to, you can convert to address as above and compare for equality, e.g. to check that a given key_hash matches a SENDER.

If you really want it today, it should be possible to hack it, using Bytes.pack to convert the address to bytes, modifying the bytes a bit, and then using Bytes.unpack to get a key_hash. However, I don't recommend this, so I won't share code for it...

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.