<p>I figured out that the Lucid command that does the trick is <code>Data.from</code>.  First, in the original code, I need to add <code>Data</code> in the list of imports:</p>
<pre class="lang-typescript prettyprint-override"><code>import { Blockfrost, Lucid, Data, } from &quot;https://deno.land/x/lucid@0.10.7/mod.ts&quot;;
</code></pre>
<p>Then simply add:</p>
<pre class="lang-typescript prettyprint-override"><code>const solution = Data.from(datum);
console.log(solution);
</code></pre>
<p>at the end of the original code.</p>

CC BY-SA 4.0
2023-09-16T17:57:04.573Z
Still it would be nice to know if it is indeed CBOR the encoding from which `Data.from` deserializes.
a_juggler
CC BY-SA 4.0
2023-09-16T17:55:33.840Z
2023-09-16T17:55:33.840Z
a_juggler
<p>The following code allows me to query a Datum from the blockchain using Lucid and Blockfrost:</p>
<pre class="lang-typescript prettyprint-override"><code>import { Blockfrost, Lucid } from &quot;https://deno.land/x/lucid@0.10.7/mod.ts&quot;;

const lucid = await Lucid.new(
  new Blockfrost(
    &quot;https://cardano-preview.blockfrost.io/api/v0&quot;,
    &lt;your BLOCKFROST_API_KEY&gt;
  ),
  &quot;Preview&quot;
);

const nft = &quot;b7e0e70f653f23abc39d16f6f6be16fd72e3fe3030db9b16cecccf68524549545f5354415445&quot;;  // example

const utxo = await lucid.utxoByUnit(nft);
const datum = utxo.datum
console.log(datum);
</code></pre>
<p>The output to the console, for this example, is:</p>
<pre><code>d8799f1903e819f80c1903e81903e8ff
</code></pre>
<p>My question now is, what command in Lucid allows me to deserialize this output?  I don't even know what kind of encoding I am dealing with (I suspect it is CBOR).</p>
<p>By the way, I know that the desired deserialization, for this example, should be:</p>
<pre><code>{
   constructor: 0,
   fields: [
      {
         int: 1000
      },
      {
         int: 63500
      },
      {
         int: 1000
      },
      {
         int: 1000
      }
   ]
}
</code></pre>

<lucid><inline-datum>
How to deserialize Datum using Lucid
# How to deserialize Datum using Lucid

(Asked by: username_0 on 2023-09-16)

The following code allows me to query a Datum from the blockchain using Lucid and Blockfrost:
import { Blockfrost, Lucid } from "https://deno.land/x/lucid@0.10.7/mod.ts";

const lucid = await Lucid.new(
  new Blockfrost(
    "https://cardano-preview.blockfrost.io/api/v0",
    
  ),
  "Preview"
);

const nft = "b7e0e70f653f23abc39d16f6f6be16fd72e3fe3030db9b16cecccf68524549545f5354415445";  // example

const utxo = await lucid.utxoByUnit(nft);
const datum = utxo.datum
console.log(datum);

The output to the console, for this example, is:
d8799f1903e819f80c1903e81903e8ff

My question now is, what command in Lucid allows me to deserialize this output?  I don't even know what kind of encoding I am dealing with (I suspect it is CBOR).
By the way, I know that the desired deserialization, for this example, should be:
{
   constructor: 0,
   fields: [
      {
         int: 1000
      },
      {
         int: 63500
      },
      {
         int: 1000
      },
      {
         int: 1000
      }
   ]
}

**Tags:** lucid, inline-datum

---

## 1 answers

### Answer by username_0 on 2023-09-16. Score: 1 | Accepted answer

I figured out that the Lucid command that does the trick is Data.from.  First, in the original code, I need to add Data in the list of imports:
import { Blockfrost, Lucid, Data, } from "https://deno.land/x/lucid@0.10.7/mod.ts";

Then simply add:
const solution = Data.from(datum);
console.log(solution);

at the end of the original code.

> **Comments:**
> **username_0**: Still it would be nice to know if it is indeed CBOR the encoding from which `Data.from` deserializes.  

---

