<p>You require an instance of type <code>BaseAddress</code> which you can get using a <strong>bech32</strong> formatted address (<code>addr_...</code> or <code>addr_test...</code>). Here an example:</p>
<pre><code>const bech32Addr = &quot;addr_test1qpgljxnfw696g0zslw0p6y4z5qt3vdlxws3e5d2ghftrvgtt0t2lsj2wyyal9d5s5ga3204hzkzrsah9ndu2d7zvqezsl7shc6&quot;;
const addr = BaseAddress.from_address(Address.from_bech32(bech32Addr));

console.log(addr.stake_cred().to_keyhash()); // Ed25519KeyHash | undefined
console.log(addr.stake_cred().to_scripthash()); // ScriptHash | undefined

</code></pre>
<p>In regards to how they differ from PubKeyHashes:
I recommend taking a look at the possible constructors for staking credentials which can be found here:
<a href="https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Credential.html#t:StakingCredential" rel="nofollow noreferrer">https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Credential.html#t:StakingCredential</a></p>
<p>Generally, if a staking credential was created using the <code>Credential</code> constructor which itself can be constructed using either <code>PubKeyCredentials</code> or <code>ScriptCredentials</code> you already see that staking credentials are not just pub key hashes. They could be validator hashes if a script manages staking actions for that address or even a staking pointer.</p>

CC BY-SA 4.0
2022-05-12T18:23:22.193Z
Thank you very much! That's what I needed. :)
Rollin
CC BY-SA 4.0
2022-05-13T08:46:40.163Z
I'd appreciate if you can mark my response as answer :)
Will
CC BY-SA 4.0
2022-11-22T21:48:00.837Z
Very helpful. Thank you!
caike
CC BY-SA 4.0
2022-05-09T08:49:15.623Z
2022-05-09T08:54:51.500Z
2022-05-09T08:54:51.500Z
Will
<p>How to retrieve staking credential hash using cardano serialization library and what is it? How does it differ from public key hash?</p>

CC BY-SA 4.0
2022-05-09T00:23:28.867Z
Needs some more details.  Try searching for "staking credential" here and seeing how others have asked.
gRebel
CC BY-SA 4.0
2022-05-09T04:01:38.533Z
Try referring https://github.com/StricaHQ/typhonjs, it's a pure js library. It has many util functions which might be useful for you.
Prashanth S.
CC BY-SA 4.0
2022-05-09T04:42:22.833Z
I Can't find much info about it. I think it is address stake credential converted into key hash.
Rollin
CC BY-SA 4.0
2022-05-09T05:24:04.247Z
You should add more details in your question, provide more context.
Prashanth S.
<wallet><cardano-serialization-lib><hash>
How to retrieve staking credential hash
# How to retrieve staking credential hash

(Asked by: username_0 on 2022-05-08)

How to retrieve staking credential hash using cardano serialization library and what is it? How does it differ from public key hash?

**Tags:** wallet, cardano-serialization-lib, hash

> **Comments:**
> **username_1**: Needs some more details.  Try searching for "staking credential" here and seeing how others have asked.  
> **username_2**: Try referring https://github.com/StricaHQ/typhonjs, it's a pure js library. It has many util functions which might be useful for you.  
> **username_0**: I Can't find much info about it. I think it is address stake credential converted into key hash.  
> **username_2**: You should add more details in your question, provide more context.  

---

## 1 answers

### Answer by username_3 on 2022-05-09. Score: 1 | Accepted answer

You require an instance of type `BaseAddress` which you can get using a **bech32** formatted address (`addr_...` or `addr_test...`). Here an example:

```
const bech32Addr = "addr_test1qpgljxnfw696g0zslw0p6y4z5qt3vdlxws3e5d2ghftrvgtt0t2lsj2wyyal9d5s5ga3204hzkzrsah9ndu2d7zvqezsl7shc6";
const addr = BaseAddress.from_address(Address.from_bech32(bech32Addr));

console.log(addr.stake_cred().to_keyhash()); // Ed25519KeyHash | undefined
console.log(addr.stake_cred().to_scripthash()); // ScriptHash | undefined

```

In regards to how they differ from PubKeyHashes:
I recommend taking a look at the possible constructors for staking credentials which can be found here:
<https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V1-Ledger-Credential.html#t:StakingCredential>

Generally, if a staking credential was created using the `Credential` constructor which itself can be constructed using either `PubKeyCredentials` or `ScriptCredentials` you already see that staking credentials are not just pub key hashes. They could be validator hashes if a script manages staking actions for that address or even a staking pointer.

> **Comments:**
> **username_0**: Thank you very much! That's what I needed. :)  
> **username_3**: I'd appreciate if you can mark my response as answer :)  
> **username_4**: Very helpful. Thank you!  

---

