<p>The serialization lib is written in Rust and compiled to web assembly. Rust manually manages its memory, and I'm assuming that you need to do the same here. If you look at the typescript types you can see that every object has a <code>free()</code> method.</p>
<p>The ptr is a pointer to memory. If you need to access information of the UTXO you need to use the provided functions. So for example, this will construct the TransactionOutput from the CBOR hex string</p>
<pre><code>const fromHexString = hexString =&gt;
  new Uint8Array(hexString.match(/.{1,2}/g).map(byte =&gt; parseInt(byte, 16)));

const utxos = await cardano
        .getUtxos()
        .then(cborUTXOS =&gt; 
                cborUTXOS.map(cborUTXO =&gt; 
                        CardanoWasm.TransactionUnspentOutput.from_bytes(fromHexString(cborUTXO))
                    )
             )
</code></pre>
<p>And you can see how many lovelaces an output has like this:</p>
<pre><code>utxos[0].output().amount().coin().to_str()
</code></pre>

CC BY-SA 4.0
2021-11-06T03:22:58.683Z
As far as i underestand you are telling me to do the same i did using a map function and a hex decoder explicit ... in fact i got the same ptr than before.
Alicia Basilio
CC BY-SA 4.0
2021-11-06T13:50:25.883Z
when i do .coin() i get coin is not a function...  where can i read about ehis objets? .output() for example?
Alicia Basilio
CC BY-SA 4.0
2021-11-10T02:27:05.963Z
The cardano serialization lib exposes some typescript definitions, so you can see what methods are available for each object. If you install the library with npm you can see the `.d.ts` type definition in node_modules
Hernan Rajchert
CC BY-SA 4.0
2022-03-31T20:43:34.327Z
@AliciaBasilio hello were you able to find an easy way to look at the content inside these pointer objects? I noticed not all types have these methods to look at
B Snow
CC BY-SA 4.0
2021-11-03T20:26:46.087Z
2021-11-03T20:26:46.087Z
Hernan Rajchert
<p>I am working on an app, I am using Nami wallet and <a href="https://github.com/Emurgo/cardano-serialization-lib" rel="nofollow noreferrer">cardano-serialization-lib</a>.</p>
<p>When I query UTxO and decode it using <code>cardano-serialization-lib</code>, I get an object with only attribute is something called &quot;ptr&quot;, ptr is a number I was expecting an actual UTxO... I want to know how can I get the UTXO because I want it for using it inside a policy script.</p>
<p><strong>Edit</strong>:</p>
<p>Extended explanation: I run the following comands in my browser:</p>
<pre><code>window.cardano.enable();
window.cardano.getUtxos();
</code></pre>
<p>I get this :</p>
<pre><code>Promise {&lt;pending&gt;}[[Prototype]]: Promise[[PromiseState]]: &quot;fulfilled&quot;[[PromiseResult]]: Array(1)0: &quot;82825820eef507b798abbb8a1360efbd113f51eda22e2fbaae3cc32c78724c8644c164a40082583900756e62ff9667b187209b6fe1b577061491cf6f93a81e1f91741e2e3accb864ae67087f69bbd9ab74f71781d13ae40aab86e1de30ca7e21171a1dcd6500&quot;length: 1[[Prototype]]: Array(0)
</code></pre>
<p>when i decode it using the library in NodeJS with the following script:</p>
<pre><code>const S = require(&quot;./node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js&quot;);
const _Buffer = require(&quot;buffer/&quot;).Buffer;
const rawUtxo =
  &quot;82825820eef507b798abbb8a1360efbd113f51eda22e2fbaae3cc32c78724c8644c164a40082583900756e62ff9667b187209b6fe1b577061491cf6f93a81e1f91741e2e3accb864ae67087f69bbd9ab74f71781d13ae40aab86e1de30ca7e21171a1dcd6500&quot;;

const utxos = S.TransactionUnspentOutput.from_bytes(
  _Buffer.from(rawUtxo, &quot;hex&quot;)
);

console.log(utxos); 
</code></pre>
<p>I get this:</p>
<p>TransactionUnspentOutput { ptr: 1179656 },</p>

CC BY-SA 4.0
2021-10-22T08:31:00.113Z
It looks like you are looking at a pointer address. But you really need to expand your question as it is not clear.
Marek Mahut - StakeNuts
CC BY-SA 4.0
2021-10-22T14:19:52.833Z
Yes as far as i underestand ptr is some kind of pointer, I edited explaing more details as you suggested. Thank you!
Alicia Basilio
CC BY-SA 4.0
2021-12-11T11:35:56.330Z
I'm use cardano-serialization-lib.
How to get key hash ?
Thank.
qi.chalerm
<wallet><smart-contract><utxo>
What is the relation of "ptr" with UTXO?
# What is the relation of "ptr" with UTXO?

(Asked by: username_0 on 2021-10-22)

I am working on an app, I am using Nami wallet and cardano-serialization-lib.
When I query UTxO and decode it using cardano-serialization-lib, I get an object with only attribute is something called "ptr", ptr is a number I was expecting an actual UTxO... I want to know how can I get the UTXO because I want it for using it inside a policy script.
Edit:
Extended explanation: I run the following comands in my browser:
window.cardano.enable();
window.cardano.getUtxos();

I get this :
Promise {}[[Prototype]]: Promise[[PromiseState]]: "fulfilled"[[PromiseResult]]: Array(1)0: "82825820eef507b798abbb8a1360efbd113f51eda22e2fbaae3cc32c78724c8644c164a40082583900756e62ff9667b187209b6fe1b577061491cf6f93a81e1f91741e2e3accb864ae67087f69bbd9ab74f71781d13ae40aab86e1de30ca7e21171a1dcd6500"length: 1[[Prototype]]: Array(0)

when i decode it using the library in NodeJS with the following script:
const S = require("./node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js");
const _Buffer = require("buffer/").Buffer;
const rawUtxo =
  "82825820eef507b798abbb8a1360efbd113f51eda22e2fbaae3cc32c78724c8644c164a40082583900756e62ff9667b187209b6fe1b577061491cf6f93a81e1f91741e2e3accb864ae67087f69bbd9ab74f71781d13ae40aab86e1de30ca7e21171a1dcd6500";

const utxos = S.TransactionUnspentOutput.from_bytes(
  _Buffer.from(rawUtxo, "hex")
);

console.log(utxos); 

I get this:
TransactionUnspentOutput { ptr: 1179656 },

**Tags:** wallet, smart-contract, utxo
> **Comments:**
> **username_1**: It looks like you are looking at a pointer address. But you really need to expand your question as it is not clear.  
> **username_0**: Yes as far as i underestand ptr is some kind of pointer, I edited explaing more details as you suggested. Thank you!  
> **username_2**: I'm use cardano-serialization-lib. How to get key hash ? Thank.  

---

## 1 answers

### Answer by username_3 on 2021-11-03. Score: 3

The serialization lib is written in Rust and compiled to web assembly. Rust manually manages its memory, and I'm assuming that you need to do the same here. If you look at the typescript types you can see that every object has a free() method.
The ptr is a pointer to memory. If you need to access information of the UTXO you need to use the provided functions. So for example, this will construct the TransactionOutput from the CBOR hex string
const fromHexString = hexString =>
  new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));

const utxos = await cardano
        .getUtxos()
        .then(cborUTXOS => 
                cborUTXOS.map(cborUTXO => 
                        CardanoWasm.TransactionUnspentOutput.from_bytes(fromHexString(cborUTXO))
                    )
             )

And you can see how many lovelaces an output has like this:
utxos[0].output().amount().coin().to_str()

> **Comments:**
> **username_0**: As far as i underestand you are telling me to do the same i did using a map function and a hex decoder explicit ... in fact i got the same ptr than before.  
> **username_0**: when i do .coin() i get coin is not a function...  where can i read about ehis objets? .output() for example?  
> **username_3**: The cardano serialization lib exposes some typescript definitions, so you can see what methods are available for each object. If you install the library with npm you can see the `.d.ts` type definition in node_modules  
> **username_4**: @AliciaBasilio hello were you able to find an easy way to look at the content inside these pointer objects? I noticed not all types have these methods to look at  

---

