Is there a way to do this programmatically? I have an

Address ShelleyAddr

obtained from

deserialiseFromBech32 AsShelleyAddress

and need its


2 Answers 2


There is now the function shelleyPayAddrToPlutusPubKHash in cardano-api which returns Maybe PubKeyHash because in the case of a script credential there is no corresponding public key hash.

  • I cannot find shelleyPayAddrToPlutusPubKHash. How exactly do I import it?
    – Kwaggy
    Dec 8, 2021 at 6:42
  • In cabal.project, what tag hash do I use for source-repository-package type: git location: https://github.com/input-output-hk/cardano-node.git ?
    – Kwaggy
    Dec 8, 2021 at 23:05

This compiles with a recent version of cardano-node and plutus:

import Plutus.V1.Ledger.Api (PubKeyHash)
import Cardano.Ledger.Alonzo.TxInfo (transKeyHash)
import Cardano.Api (ShelleyAddr)
import Cardano.Api.Shelley (Address (ShelleyAddress))   
import Cardano.Ledger.Shelley.API (Credential (KeyHashObj, ScriptHashObj))

addrToPkh :: Address ShelleyAddr -> PubKeyHash
addrToPkh (ShelleyAddress net (ScriptHashObj sh) sr) = transKeyHash sh
addrToPkh (ShelleyAddress net (KeyHashObj kh) sr) = transKeyHash kh
  • Is there such a thing as an AlonzoAddr (via deserialiseFromBech32 AsAlonzoAddress)? I am only using ShellyAddr because that's what I found in the API.
    – Kwaggy
    Nov 16, 2021 at 21:07
  • cabal build is giving me: unknown package: cardano-ledger-shelley. Not sure what to do.
    – Kwaggy
    Nov 16, 2021 at 21:26
  • @Kwaggy: AlonzoAddr is fine and to make it compile you need to add cardano-ledger-shelley to your code's .cabal file in the build-depends section and maybe ensure you are having the https://github.com/input-output-hk/cardano-ledger-specs as a source-repository-package in cabal.project (depends a bit on your workflow). Nov 17, 2021 at 11:21
  • @Sebastian Nagel: Where do I find AlonzoAddr?
    – Kwaggy
    Nov 17, 2021 at 17:50
  • @insitu: For recent version of cardano-node, I downloaded pre-compiled executable from docs.cardano.org/getting-started/installing-the-cardano-node and parked the unzipped in my root dir. How do I teach cabal about it, such that .cabal file is happy with having cardano-ledger-shelley in its build-depends section?
    – Kwaggy
    Nov 18, 2021 at 2:37

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.