# Query balance issue

**URL:** <https://forum.fuel.network/t/query-balance-issue/6494>\
**Category:** TypeScript SDK\
**Tags:** testnet, feedback\
**Created:** [August 20, 2024, 5:41pm UTC](https://forum.fuel.network/t/query-balance-issue/6494 "2024-08-20T17:41:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aravindhk](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@aravindhk](https://forum.fuel.network/u/aravindhk)\
**Post date:** [August 20, 2024, 5:41pm UTC](https://forum.fuel.network/t/query-balance-issue/6494/1 "2024-08-20T17:41:57Z")

</div>

```
const contract_wallet = Wallet.fromAddress(toBech32(market_contract_id), provider);
const contract_token_all_balance = await contract_wallet.getBalances()
console.log("contract_token_all_balance", contract_token_all_balance);

```

I’m getting this result while using this code.  
contract\_token\_all\_balance {  
balances: [  
{  
assetId: ‘0xd331425f990cafd224fec452061b26257fed4fe0d56f91b3fd0db1623ae61146’,  
amount: \<BN: 0x1e8480\>  
},  
{  
assetId: ‘0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07’,  
amount: \<BN: 0x30d40\>  
}  
]  
}

I’m getting zero when I try to get the balance from contract. this is the contract code.  
#[storage(read)]  
fn get\_asset\_balance(asset\_id: AssetId) → u64 {  
this\_balance(asset\_id)  
}

can anyone help me to resolve this issue? I try to get the native coin and src20 token balance from contract.

> **[Fuel Explorer](https://app.fuel.network/account/0x1a1d5aa54af52b7350d0e2d725ccbd41c94987d42df56c7d39b29dc225c0c340/assets)**
>
> Explorer of The Rollup OS for Ethereum

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [August 21, 2024, 6:12am UTC](https://forum.fuel.network/t/query-balance-issue/6494/2 "2024-08-21T06:12:50Z")

</div>

> [@aravindhk](#):
>
> #[storage(read)]  
> fn get\_asset\_balance(asset\_id: AssetId) → u64 {  
> this\_balance(asset\_id)  
> }

`this_balance()` function is used to get the balance of the current contract. If that’s what you are trying to do then the correct syntax is `this_balance(AssetId::base())`. You can have a look at the example [here](https://docs.fuel.network/guides/intro-to-sway/contract-functions/#5-withdraw-funds)

---

<div class="post-metadata">

**Author:** ![aravindhk](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@aravindhk](https://forum.fuel.network/u/aravindhk)\
**Post date:** [August 22, 2024, 1:27am UTC](https://forum.fuel.network/t/query-balance-issue/6494/3 "2024-08-22T01:27:40Z")

</div>

> **[Fuel Explorer](https://app.fuel.network/account/0x6d2cceef819029abb15731a874dd6c9ac1a402b108478801191dde2685c8586c/assets)**
>
> Explorer of The Rollup OS for Ethereum

> **[Fuel Explorer](https://app.fuel.network/contract/0x6d2cceef819029abb15731a874dd6c9ac1a402b108478801191dde2685c8586c/assets)**
>
> Explorer of The Rollup OS for Ethereum

source code -  
js script - [fuel\_mint/marketplace.js at main · aravindhkm/fuel\_mint · GitHub](https://github.com/aravindhkm/fuel_mint/blob/main/marketplace.js)  
contract code - [fuel\_mint/native-asset/native-asset-contract/src/main.sw at main · aravindhkm/fuel\_mint · GitHub](https://github.com/aravindhkm/fuel_mint/blob/main/native-asset/native-asset-contract/src/main.sw)

i’m doing the same which you mentioned in the reply. still, I get the zero balance in contract code. when I search the contract address in fuel explorer. i can able to see the balance in the account page but not on the contract page. Do I need to follow any other steps to send the coin to the contract? I’m a little bit confused here. can anyone please me to resolve this issue? i have attached my git repo link please look into it

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [August 22, 2024, 7:42am UTC](https://forum.fuel.network/t/query-balance-issue/6494/4 "2024-08-22T07:42:57Z")

</div>

At the first glance, your code seems correct. though let me try debugging and get back †o you

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [August 22, 2024, 11:49am UTC](https://forum.fuel.network/t/query-balance-issue/6494/5 "2024-08-22T11:49:09Z")

</div>

Hey @aravindhk, the discrepancy between the account balance and the contract balance can be due to the fundamental difference between how balances are managed for accounts and contracts in the Fuel network.

Account balances sum up the UTXOs, contract balances fetch the balance owned by the contract state. If there is a regular balance associated with a contract id that’s likely due to user error, as those utxos will essentially be stuck since no one will be able to sign over those.

---

<div class="post-metadata">

**Author:** ![aravindhk](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@aravindhk](https://forum.fuel.network/u/aravindhk)\
**Post date:** [August 23, 2024, 3:53am UTC](https://forum.fuel.network/t/query-balance-issue/6494/6 "2024-08-23T03:53:52Z")

</div>

@Nazeeh21 Can you please share any reference links for that?

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [August 23, 2024, 9:22am UTC](https://forum.fuel.network/t/query-balance-issue/6494/7 "2024-08-23T09:22:44Z")

</div>

I don’t have specific documentation that directly compares account and contract balances. However, I can provide you with relevant documentation links that cover how to check balances for both accounts and contracts, which should help you understand the differences.

### Relevant Documentation

1. **Checking Account Balances** :

- This documentation explains how to check the balance of a specific asset in your wallet.
- [Checking Balances](https://docs.fuel.network/docs/fuels-ts/wallets/checking-balances/)

1. **Checking Contract Balances** :

- This documentation explains how to check the available balance of a specific asset for a contract.
- [Contract Balance](https://docs.fuel.network/docs/fuels-ts/contracts/contract-balance/)

### Key Points

- **Account Balance** :
  - Managed by the Fuel network.
  - Reflects assets directly held by the account.
  - Example method: `getBalance` on a wallet instance.

- **Contract Balance** :
  - Depends on the contract’s logic to manage and track assets.
  - Reflects assets explicitly transferred to and managed by the contract.
  - Example method: `getBalance` on a contract instance.

### Example: Checking Account Balance

```auto
const myWallet = Wallet.fromPrivateKey(privateKey, provider);

// The returned amount is a BigNumber
const balance: BN = await myWallet.getBalance(provider.getBaseAssetId());
console.log("Account Balance:", balance.toString());

```

### Example: Checking Contract Balance

```auto
const contractBalance = await contract.getBalance(baseAssetId);
console.log("Contract Balance:", contractBalance.toString());

```

LMK if you need more explanation
