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

CC BY-SA 4.0
2021-12-08T06:42:45.000Z
I cannot find `shelleyPayAddrToPlutusPubKHash`. How exactly do I import it?
Kwaggy
CC BY-SA 4.0
2021-12-08T23:05:27.567Z
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
CC BY-SA 4.0
2021-12-07T17:20:55.777Z
2021-12-07T17:20:55.777Z
Jim
<p>This compiles with a recent version of <code>cardano-node</code> and <code>plutus</code>:</p>
<pre><code>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 -&gt; PubKeyHash
addrToPkh (ShelleyAddress net (ScriptHashObj sh) sr) = transKeyHash sh
addrToPkh (ShelleyAddress net (KeyHashObj kh) sr) = transKeyHash kh
</code></pre>

CC BY-SA 4.0
2021-11-16T21:07:30.293Z
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
CC BY-SA 4.0
2021-11-16T21:26:40.563Z
`cabal build` is giving me: _unknown package: `cardano-ledger-shelley`_. Not sure what to do.
Kwaggy
CC BY-SA 4.0
2021-11-17T11:21:54.297Z
@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).
Sebastian Nagel
CC BY-SA 4.0
2021-11-17T17:50:47.033Z
@Sebastian Nagel: Where do I find `AlonzoAddr`?
Kwaggy
CC BY-SA 4.0
2021-11-18T02:37:39.353Z
@insitu: For _recent version of cardano-node_, I downloaded pre-compiled executable from https://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
CC BY-SA 4.0
2021-11-18T19:33:37.680Z
@Kwaggy: There is no `AlonzoAddr` as far as I know. You might expect one as you read `ShelleyAddr`, but in fact the "alonzo era is a shelley era", so `ShelleyAddr` is just fine.
To get the `cardano-ledger-shelley` you do not need the pre-compiled executable, but need to adapt the `cabal.project` file, e.g. like this https://github.com/input-output-hk/hydra-poc/blob/master/cabal.project#L85-L112 -> `cardano-ledger-shelley` is in the `eras/shelley/impl` directory of the ledger specs repo. You can also ask in the `#ask-hydra` channel on the IOG Discord for more help: https://discord.gg/y5kfwHtm
Sebastian Nagel
CC BY-SA 4.0
2021-11-19T05:52:56.803Z
@SebastianNagel: I am running into `cabal build` error: _Failed to build plutus-chain-index-0.1.0.0._, and `cabal clean` does not help.
Kwaggy
CC BY-SA 4.0
2021-11-19T15:27:14.103Z
@SebastianNagel: Please see https://gist.github.com/paul-outlaw/130764aa1da5cb2c93c5be3c550a19e6
Kwaggy
CC BY-SA 4.0
2021-11-20T08:56:58.150Z
@Kwaggy Sorry, I do not really understand your question: Cabal dependencies require source code, either from a package or from a git repository. BTW, I have commented your gist, seems like your SHA1 are not correctly set which would explain the compilation error you see.
insitu
CC BY-SA 4.0
2021-11-16T20:41:28.737Z
2021-11-16T20:41:28.737Z
insitu
<p>Is there a way to do this programmatically? I have an</p>
<p><code>Address ShelleyAddr</code></p>
<p>obtained from</p>
<p><code>deserialiseFromBech32 AsShelleyAddress</code></p>
<p>and need its</p>
<p><code>Plutus.V1.Ledger.Crypto.PubKeyHash</code></p>

<address><api><public-key><bech32>
How to obtain PubKeyHash from Address ShelleyAddr
# How to obtain PubKeyHash from Address ShelleyAddr

(Asked by: username_0 on 2021-11-16)

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

`Address ShelleyAddr`

obtained from

`deserialiseFromBech32 AsShelleyAddress`

and need its

`Plutus.V1.Ledger.Crypto.PubKeyHash`

**Tags:** address, api, public-key, bech32

---

## 2 answers

### Answer by username_1 on 2021-12-07. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: I cannot find `shelleyPayAddrToPlutusPubKHash`. How exactly do I import it?  
> **username_0**: 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` ?  

---

### Answer by username_2 on 2021-11-16. Score: 1

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

> **Comments:**
> **username_0**: 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.  
> **username_0**: `cabal build` is giving me: _unknown package: `cardano-ledger-shelley`_. Not sure what to do.  
> **username_3**: @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).  
> **username_0**: @Sebastian Nagel: Where do I find `AlonzoAddr`?  
> **username_0**: @insitu: For _recent version of cardano-node_, I downloaded pre-compiled executable from https://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?  
> **username_3**: @Kwaggy: There is no `AlonzoAddr` as far as I know. You might expect one as you read `ShelleyAddr`, but in fact the "alonzo era is a shelley era", so `ShelleyAddr` is just fine. To get the `cardano-ledger-shelley` you do not need the pre-compiled executable, but need to adapt the `cabal.project` file, e.g. like this https://github.com/input-output-hk/hydra-poc/blob/master/cabal.project#L85-L112 -> `cardano-ledger-shelley` is in the `eras/shelley/impl` directory of the ledger specs repo. You can also ask in the `#ask-hydra` channel on the IOG Discord for more help: https://discord.gg/y5kfwHtm  
> **username_0**: @SebastianNagel: I am running into `cabal build` error: _Failed to build plutus-chain-index-0.1.0.0._, and `cabal clean` does not help.  
> **username_0**: @SebastianNagel: Please see https://gist.github.com/paul-outlaw/130764aa1da5cb2c93c5be3c550a19e6  
> **username_2**: @Kwaggy Sorry, I do not really understand your question: Cabal dependencies require source code, either from a package or from a git repository. BTW, I have commented your gist, seems like your SHA1 are not correctly set which would explain the compilation error you see.  

---

