user4401: Hi i just recently started working with Nami Wallet to be implementes in a web app, but when im trying to get my wallet balance:
window.cardano.getBalance().then(res => console.log(res))

its returning an string.

"1a3b983883"

would love to know what that is and if i can convert that to an actual number.
Picture:


user1045: getBalance function returns cbor encoded hex string, so you should actually decode it.
Easiest way to do it is by using Cardano Serialization Lib.
After you've downloaded the library you can decoded it by doing this:
import * as wasm from '@emurgo/cardano-serialization-lib-browser';

window.cardano.getBalance().then(res => {
   const balance = wasm.Value.from_bytes(Buffer.from(res, 'hex'));
   const lovelaces = balance.coin().to_str();

   console.log(lovelaces);
})

EDIT:
Thanks to Hernan Rajchert for explaining on how to get lovelaces from Values object.

4401: <p>Hi i just recently started working with Nami Wallet to be implementes in a web app, but when im trying to get my wallet balance:</p>
<pre><code>window.cardano.getBalance().then(res =&gt; console.log(res))
</code></pre>
<p>its returning an string.</p>
<blockquote>
<p>&quot;1a3b983883&quot;</p>
</blockquote>
<p>would love to know what that is and if i can convert that to an actual number.</p>
<p>Picture:</p>
<p><a href="https://i.stack.imgur.com/KQlBe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/KQlBe.png" alt="getBalance() response" /></a></p>
 1045: <p><code>getBalance</code> function returns cbor encoded hex string, so you should actually decode it.</p>
<p>Easiest way to do it is by using <a href="https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser" rel="noreferrer">Cardano Serialization Lib</a>.</p>
<p>After you've downloaded the library you can decoded it by doing this:</p>
<pre><code>import * as wasm from '@emurgo/cardano-serialization-lib-browser';

window.cardano.getBalance().then(res =&gt; {
   const balance = wasm.Value.from_bytes(Buffer.from(res, 'hex'));
   const lovelaces = balance.coin().to_str();

   console.log(lovelaces);
})
</code></pre>
<p><strong>EDIT:</strong></p>
<p>Thanks to <a href="https://cardano.stackexchange.com/users/4593/hernan-rajchert">Hernan Rajchert</a> for explaining on how to get lovelaces from Values object.</p>
