How to retrieve staking credential hash using cardano serialization library and what is it? How does it differ from public key hash?
-
Needs some more details. Try searching for "staking credential" here and seeing how others have asked.– gRebelCommented May 9, 2022 at 0:23
-
1Try referring github.com/StricaHQ/typhonjs, it's a pure js library. It has many util functions which might be useful for you.– Prashanth S.Commented May 9, 2022 at 4:01
-
I Can't find much info about it. I think it is address stake credential converted into key hash.– RollinCommented May 9, 2022 at 4:42
-
You should add more details in your question, provide more context.– Prashanth S.Commented May 9, 2022 at 5:24
1 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.