Programmatically generate Policy Id from Policy script


I am trying to generate Policy Id inside my program instead of using “cardano-cli transaction policyid” .

I understand that I need to create a hash of Policy Script to generate the policy id. But I am not able to find the exact logic to do that.

For example, I am trying to programmatically generate policy id from the below policy script.
“keyHash”: “ad7a7b87959173fc9eac9a85891cc93892f800dd45c0544128228884”,
“type”: “sig”

Can anyone point me to any client side implementation of the same or any document ?

Thanks in advance.

Serialize the script to CBOR according to the CDDL specification, prepend a zero byte, and hash all that with blake2b_244. For details, see Policy hash in python.

1 Like

Thanks a lot. I was missing \00 byte.

1 Like