How to retrieve staking credential hash using cardano serialization library and what is it? How does it differ from public key hash?
You require an instance of type
BaseAddress which you can get using a bech32 formatted address (
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
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.