I was wondering how to create the policy Id/script for the cardano assets. I am new to cardano blockchain but I have worked on Ethereum. I read the docs provided by the cardano officials but couldn't find any possible way on how to work with this lib. Moreover, there is no information provided by cardano on how to use this lib or possibly I could find it. Please provide the information about how to use this lib. Thank you..
1 Answer
You can find a full example here in the the /doc/getting-started folder of the serialization lib:
https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/minting-nfts.md
You basically compose your script depending on your requirements, e.g. by creating a scripts object via NativeScripts.new()
, adding the individual script components (timelock / pub key hash) to that and wrapping them in a new_script_all()
script.
The "policy id" is a hex representation of the final script hash, received like this (from the example above):
const policyId = Buffer.from(mintScript.hash().to_bytes()).toString("hex");
console.log(`POLICY_ID: ${policyId}`);