# How to get metadata of a native asset from an account balance?

**URL:** <https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483>\
**Category:** Sway\
**Created:** [November 2, 2023, 12:16am UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483 "2023-11-02T00:16:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [November 2, 2023, 12:16am UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/1 "2023-11-02T00:16:49Z")

</div>

I’m aware of the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_20) standard, but I’m wondering how to use it.

The problem I’ve encountered: in order to call functions such as `name` or `total_supply` from the SRC-20 standard, you need to have two values:

- contract id
- asset id

When getting account balances from the fuel node api, you obtain only one of those values - asset id (as per [graphql schema](https://github.com/FuelLabs/fuel-core/blob/203beaa182100abffec68a70323215da70f2de1f/crates/client/assets/schema.sdl#L5-L9)).

The question is - what contract id should I use to start calling the SRC-20 functions on an asset?

As an example - is it possible and what contract id should I use if I want to get a name of the base asset id (`0x0000000000000000000000000000000000000000000000000000000000000000`)?

---

<div class="post-metadata">

**Author:** ![sandusky](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sandusky/32/1313_2.png) [@sandusky](https://forum.fuel.network/u/sandusky)\
**Post date:** [November 2, 2023, 3:24pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/2 "2023-11-02T15:24:07Z")

</div>

Hi there!

1. As seen in [source](https://github.com/FuelLabs/sway/blob/ae31213b8832110e74b55ce72f99b32beb519d75/sway-lib-std/src/contract_id.sw#L80), the asset\_id is calculated by hashing te contract\_id and the sub\_id.
2. The only case where asset\_id == “0x000…” is the base asset, which is ZERO\_B256.
3. The base asset lacks of a wrapper contract so it’s not SRC-20 compliant.
4. The metadata lives in the contract that minted the asset.

> - what contract id should I use to start calling the SRC-20 functions on an asset

You need the contract\_id beforehand since you can’t deconstruct the asset\_id hash.

> - is it possible and what contract id should I use if I want to get a name of the base asset id

Is not possible, there’s no contract wrapping the base asset.

Let me know if this solves your question 🌴

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [November 2, 2023, 4:54pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/3 "2023-11-02T16:54:11Z")

</div>

Thanks for the detailed explanation!

But it doesn’t actually solve the problem I have.

I’d like to give some information about assets that the users posses, but from what you’re saying, it’s impossible unless I know the contract ids in advance. So, every time a new asset comes out on Fuel, I need to contact the issuer and ask for a contract id, is that correct?

This gets even more painful with NFTs (which are also native assets). Every time someone creates an NFT, we need to get its contract id in order to be able to understand that this is an NFT and show some info about it.

Is there a workaround you can think of? If not, I believe that it’s an important feature for a blockchain to have

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [November 11, 2023, 12:23pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/4 "2023-11-11T12:23:00Z")

</div>

@sandusky hey, do you have any ideas on how to achieve this?

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [November 22, 2023, 3:29pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/5 "2023-11-22T15:29:23Z")

</div>

@sandusky sorry for pinging you again, but do you have any idea on how to implement this?

---

<div class="post-metadata">

**Author:** ![sandusky](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sandusky/32/1313_2.png) [@sandusky](https://forum.fuel.network/u/sandusky)\
**Post date:** [November 23, 2023, 2:06pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/6 "2023-11-23T14:06:01Z")

</div>

Hi there!  
Sorry for the delay @mpoplavkov  
I was out for devconnect.

This issue was the source of an interesting conversation among the Fuel Labs engineers.  
The quick answer is that there’s no simple way to solve this.

Internally, the following approaches were discussed.

1. A global indexer solution.
2. A “ERC-1820” inspired central registry
3. An onchain assetId → contractId map attached to the TX.

Since #2 and #3 seem quite out of reach for your current situation, the #1 might be a choice.

Basically is an indexer module tracking all mints.  
Right now is not that expensive but can result in a lot of infra in the context of mainnet.

Such a tool might require some kind of query fee service, such as The Graph. Maybe a middleware trying to spend predicates before serving queries. Feels like a product by itself.

I think the source of this question is some kind of portfolio metadata display.

My take is to build this kind of indexer but initially just track the most active contracts and slowly evolve into a wider approach.

I’m bullish on the “indexer marketplace - query fee service” dapp. It might be a fit for some kind of grants program 😉

What do you think about this?

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [November 23, 2023, 4:55pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/7 "2023-11-23T16:55:29Z")

</div>

Yes, I thought about the indexer but wanted to avoid implementing it if Fuel was to suggest a better approach 🙂 We’ll estimate the complexity of running an indexer and think about it, thank you!

---

<div class="post-metadata">

**Author:** ![sandusky](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sandusky/32/1313_2.png) [@sandusky](https://forum.fuel.network/u/sandusky)\
**Post date:** [November 26, 2023, 3:49pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/8 "2023-11-26T15:49:21Z")

</div>

Thanks for sharing your thoughts.

Implementing an indexer solution like this can result in a product by itself.

A better approach requires some tweaking at the client level, so it might take a while, right now the quickest way to unblock is by implementing the indexer.

Let me know if you need further support on this endeavor!

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [February 20, 2024, 1:32pm UTC](https://forum.fuel.network/t/how-to-get-metadata-of-a-native-asset-from-an-account-balance/3483/9 "2024-02-20T13:32:49Z")

</div>

Hello @sandusky. Do you have any updates on this topic by any chance? Maybe Fuel has decided to solve this problem somehow?
