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.


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


getBalance() response

New contributor
Daniel Diaz is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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'));
  • thanks! but this code returns this object "{ptr: 1180552}", what to do with that? Oct 13 at 15:43
  • Yeah I got the same response so I'm not too sure about it. I'd recommend you rather building your transactions using TransactionBuilder, because it offers you nice way to specify change address and etc. 2 days ago

Your Answer

Daniel Diaz is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.