<p>You could try this out. Basically assets are under value.multiassets() and is a double map from policy ID =&gt; assetName =&gt; quantity. You can iterate over this map with 2 for loops:</p>
<pre><code>const value = CSL.Value.from_bytes(...) // your value
const lovelace = value.coin().to_str();
if (value.multiasset()) {
const multiAssets = value.multiasset().keys();
for (let j = 0; j &lt; multiAssets.len(); j++) {
  const policy = multiAssets.get(j);
  const policyAssets = value.multiasset().get(policy);
  const assetNames = policyAssets.keys();
  for (let k = 0; k &lt; assetNames.len(); k++) {
    const assetPolicy = Buffer.from(policy.to_bytes()).toString(&quot;hex&quot;); // hex encoded policy
    const assetName = Buffer.from(
      assetNames.get(k).name(),
      &quot;hex&quot;
    ).toString(); // utf8 encoded asset name
    const quantity = policyAssets.get(assetNames.get(k)).to_str(); // asset's quantity

    // your code here

  }
}
</code></pre>

CC BY-SA 4.0
2021-12-24T15:18:42.197Z
Can I use `Buffer` in the browser or is this code only running on a Server (NodeJS)?
eddex
CC BY-SA 4.0
2021-11-14T20:54:26.780Z
2021-12-06T06:47:45.540Z
2021-12-06T06:47:45.540Z
Alessandro Konrad
<p>Hello I am building a daap and i wanted to save blockFrost requests so I wonder if it is posible to fetch all assets using the nami wallet? I was trying with the window.cardano.get balance() , after using cardano serialization lib  with Value.from_bytes() I get the ada total using Value.from_bytes().coin().to_str()  but for all the other methods defined on Value.from_bytes() i can not find any that allows me to get .to_str() ... so even if i think that the total assets is in the original Value, I can not read it. Any help?</p>

<wallet><nami-wallet><cardano-serialization-lib>
How to fetch assets siting on an adress using cardano serialization library and Nami wallet?
# How to fetch assets siting on an adress using cardano serialization library and Nami wallet?

(Asked by: username_0 on 2021-11-13)

Hello I am building a daap and i wanted to save blockFrost requests so I wonder if it is posible to fetch all assets using the nami wallet? I was trying with the window.cardano.get balance() , after using cardano serialization lib with Value.from\_bytes() I get the ada total using Value.from\_bytes().coin().to\_str() but for all the other methods defined on Value.from\_bytes() i can not find any that allows me to get .to\_str() ... so even if i think that the total assets is in the original Value, I can not read it. Any help?

**Tags:** wallet, nami-wallet, cardano-serialization-lib

---

## 1 answers

### Answer by username_1 on 2021-11-14. Score: 5 | Accepted answer

You could try this out. Basically assets are under value.multiassets() and is a double map from policy ID => assetName => quantity. You can iterate over this map with 2 for loops:
const value = CSL.Value.from_bytes(...) // your value
const lovelace = value.coin().to_str();
if (value.multiasset()) {
const multiAssets = value.multiasset().keys();
for (let j = 0; j < multiAssets.len(); j++) {
  const policy = multiAssets.get(j);
  const policyAssets = value.multiasset().get(policy);
  const assetNames = policyAssets.keys();
  for (let k = 0; k < assetNames.len(); k++) {
    const assetPolicy = Buffer.from(policy.to_bytes()).toString("hex"); // hex encoded policy
    const assetName = Buffer.from(
      assetNames.get(k).name(),
      "hex"
    ).toString(); // utf8 encoded asset name
    const quantity = policyAssets.get(assetNames.get(k)).to_str(); // asset's quantity

    // your code here

  }
}

> **Comments:**
> **username_2**: Can I use `Buffer` in the browser or is this code only running on a Server (NodeJS)?  

---

