I am writing a smart contract which allows the delegate to be changed. I also want incoming payments to be permissioned. Ideally, I want to update the incoming payment whitelist with the baker's address at the same time the delegate is changed. But changing the delegate requires a TKeyHash while sp.sender is of type TAddress.

How can I compare, or convert, a TKeyHash to TAddress and the reverse?

I have tried casting with sp.address(baker_key_hash) or sp.key_hash(baker_address) but that gives an error.

1 Answer 1


You can convert a key_hash to a contract and then a contract to an address.


Relevant documentation:



Converting from an address to a key_hash is not possible. For an example why, a KT1... address does not have a corresponding key_hash.

  • Thank you. But that only answers half the question. What about the reverse? Is there a way to convert from TAddress to TKeyHash? Dec 8, 2021 at 6:58
  • 1
    @BakeꜩforMe, no. Remark that it wouldn’t be sound, KT1… addresses don’t correspond to key hashes.
    – FFF
    Dec 8, 2021 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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