1

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

1

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

sp.to_address(sp.implicit_account(my_key_hash))

Relevant documentation:

https://smartpy.io/docs/types/contracts_addresses#cast-key_hash-to-a-typed-contract

https://smartpy.io/docs/types/contracts_addresses#convert-contract-to-address

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.

2
  • 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 you have read our privacy policy.

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