<p>The <code>policyId</code> is the hash of the policy script. It is a blake2b-224 hash resulting in 28 bytes and a hex length of 56 chars. So, your code will always work and is the right way to do it.</p>
<p>Find the spec defining the scriptHash <a href="https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L251" rel="noreferrer">here</a>, note that the <code>scriptHash</code> is of type hash28 denoting the hash length.</p>
<p>Also, the <code>assetName</code> can be of any length between 0-32 bytes. Something to keep a note of in your application, this also means that there can be a token without <code>assetName</code>. Find the <code>assetName</code> length spec <a href="https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L252" rel="noreferrer">here</a></p>

CC BY-SA 4.0
2021-05-24T13:57:17.310Z
2021-05-24T13:57:17.310Z
Ashish Prajapati
<p>Yes, the policy ID is indeed defined as a <code>ScriptHash</code> in the specifications. Its length is 28 bytes.</p>

CC BY-SA 4.0
2021-05-24T12:51:50.653Z
Thanks for the answer. Coud you provide a link to the specification you mentioned?
eddex
CC BY-SA 4.0
2021-08-10T13:57:38.440Z
https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L251
Marek Mahut - StakeNuts
CC BY-SA 4.0
2021-05-24T12:44:11.190Z
2021-05-24T12:44:11.190Z
vaz
<p>Let's say I have the following native token <em>unit</em> <code>d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc537061636542756433323639</code> that consists of the <em>policy id</em> <code>d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc</code> and <em>asset name</em> <code>537061636542756433323639</code>.</p>
<p>The <em>asset name</em> is a HEX representation of the name. Therefore it can vary in length.</p>
<p>But the <em>policy id</em> is some sort of a hash of the policy, so I'd assume the length of the string is always the same. Is this correct?</p>
<p>What I want to achieve is to split the <em>asset name</em> and the <em>policy id</em> e.g. like this:</p>
<pre><code>'d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc537061636542756433323639'.substring(56)
&gt; &quot;537061636542756433323639&quot;
</code></pre>

<native-assets><policy>
Is the length (in characters) of a token policy id always the same?
# Is the length (in characters) of a token policy id always the same?

(Asked by: username_0 on 2021-05-24)

Let's say I have the following native token unit d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc537061636542756433323639 that consists of the policy id d5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc and asset name 537061636542756433323639.
The asset name is a HEX representation of the name. Therefore it can vary in length.
But the policy id is some sort of a hash of the policy, so I'd assume the length of the string is always the same. Is this correct?
What I want to achieve is to split the asset name and the policy id e.g. like this:
'd5e6bf0500378d4f0da4e8dde6becec7621cd8cbf5cbb9b87013d4cc537061636542756433323639'.substring(56)
> "537061636542756433323639"

**Tags:** native-assets, policy

---

## 2 answers

### Answer by username_1 on 2021-05-24. Score: 8 | Accepted answer

The `policyId` is the hash of the policy script. It is a blake2b-224 hash resulting in 28 bytes and a hex length of 56 chars. So, your code will always work and is the right way to do it.

Find the spec defining the scriptHash [here](https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L251), note that the `scriptHash` is of type hash28 denoting the hash length.

Also, the `assetName` can be of any length between 0-32 bytes. Something to keep a note of in your application, this also means that there can be a token without `assetName`. Find the `assetName` length spec [here](https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L252)


---

### Answer by username_2 on 2021-05-24. Score: 2

Yes, the policy ID is indeed defined as a `ScriptHash` in the specifications. Its length is 28 bytes.

> **Comments:**
> **username_0**: Thanks for the answer. Coud you provide a link to the specification you mentioned?  
> **username_3**: https://github.com/input-output-hk/cardano-ledger-specs/blob/683bef2e40cbd10339452c9f2009867c855baf1a/shelley-ma/shelley-ma-test/cddl-files/shelley-ma.cddl#L251  

---

