# Failed to deserialize idl blob: Invalid data

**URL:** <https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720>\
**Category:** Rust\
**Created:** [November 24, 2024, 9:59pm UTC](https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720 "2024-11-24T21:59:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joah](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@joah](https://forum.dfinity.org/u/joah)\
**Post date:** [November 24, 2024, 9:59pm UTC](https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720/1 "2024-11-24T21:59:08Z")

</div>

Hii there!

I have been stuck at this bug for a long time now, please I’ll love to get help. Here is my code:

```auto
pub async fn check_balance(account: String) -> Result<BalanceResponse> {
    let account_identifier = AccountIdentifier::from_hex(&account).map_err(|e| e.to_string())?;

    let balance_args = AccountBalanceArgs {
        account: account_identifier,
    };

    match ic_cdk::api::call::call::<(AccountBalanceArgs,), (Tokens,)>(
        Principal::from_text(ICP_LEDGER_CANISTER_ID).unwrap(),
        "account_balance_dfx",
        (balance_args,),
    )
    .await
    .map_err(|e| e.1)
    {
        Ok((icpts,)) => {
            // Log the balance in e8s (the smallest unit of ICP)
            ic_cdk::println!("Received balance: {} e8s", icpts.e8s());

            Ok(BalanceResponse {
                balance: icpts.e8s(),
                error: None,
            })
        }
        Err(e) => {
            // Log the error
            ic_cdk::println!("Error fetching balance: {:?}", e);

            Ok(BalanceResponse {
                balance: 0,
                error: Some(e),
            })
        }
    }
}

```

My error: [Canister bd3sg-teaaa-aaaaa-qaaba-cai] Error fetching balance: “Fail to decode argument 0 from table0 to record { account : text }”  
Error deserializing blob 0x4449444c036b02bc8a0101c5fed201716c029cbab69c0278c897a79907026e71010000000000000000000001424661696c20746f206465636f646520617267756d656e7420302066726f6d207461626c653020746f207265636f7264207b206163636f756e74203a2074657874207d  
Error: Failed to deserialize idl blob: Invalid data.  
Caused by: input: 4449444c036b02bc8a0101c5fed201716c029cbab69c0278c897a79907026e710100\_00000000000000000001424661696c20746f206465636f646520617267756d656e7420302066726f6d207461626c653020746f207265636f7264207b206163636f756e74203a2074657874207d  
table: type BalanceRequest = record { account : text }  
type BalanceResponse = record { balance : nat64; error : opt text }  
type Transaction = record {  
to : text;  
from : text;  
created\_at : nat64;  
narration : text;  
amount : nat64;  
}  
type TransferRequest = record { to : text; amount : nat64 }  
type TransferResponse = record { block\_index : opt nat64; error : opt text }  
type Wallet = record {  
updated\_at : nat64;  
balance : nat64;  
transaction : vec Transaction;  
created\_at : nat64;  
user\_id : text;  
address : text;  
}  
type table0 = variant { 17\_724 : table1; 3\_456\_837 : text }  
type table1 = record { 596\_483\_356 : nat64; 1\_932\_118\_984 : table2 }  
type table2 = opt text  
wire\_type: variant { 17\_724 : table1; 3\_456\_837 : text }, expect\_type: record { balance : nat64; error : opt text }  
Caused by: Fail to decode argument 0 from table0 to record { balance : nat64; error : opt text }  
Caused by: Subtyping error: Type mismatch at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/candid-0.10.8/src/de.rs:994

Also, I have tried logging the `account_identifier` and it logs the exact account identifier I inputed. Thank you.

---

<div class="post-metadata">

**Author:** ![joah](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@joah](https://forum.dfinity.org/u/joah)\
**Post date:** [November 24, 2024, 10:00pm UTC](https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720/2 "2024-11-24T22:00:42Z")

</div>

This is my candid service

```auto
 check_icp_balance: (text) -> (BalanceResponse) query;

```

```auto
type BalanceRequest = record {
  account: text; // Account identifier
};

```

---

<div class="post-metadata">

**Author:** ![rem.codes](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rem.codes/32/40260_2.png) [@rem.codes](https://forum.dfinity.org/u/rem.codes)\
**Post date:** [November 25, 2024, 9:25am UTC](https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720/3 "2024-11-25T09:25:03Z")

</div>

I think the main issue here is that you are expecting the wrong result type, it should be something like `ic_cdk::api::call::call::<Result<(Tokens,), (RejectionCode, String)>>`

(or `CallResult<(Tokens,)>` from the `ic-cdk` crate.

But maybe easier is using the `ic_ledger_types` crate which has a [`account_balance`](https://docs.rs/ic-ledger-types/latest/ic_ledger_types/fn.account_balance.html) method.

also not sure if the `AccountIdentifier` is going to work like that, this is what i use to convert a principal to `AccountIdentifier`

```rs
use ic_ledger_types::{AccountIdentifier, DEFAULT_SUBACCOUNT};

pub fn principal_to_account_identifier(principal: Principal) -> AccountIdentifier {
    AccountIdentifier::new(&principal, &DEFAULT_SUBACCOUNT)
}

```

---

<div class="post-metadata">

**Author:** ![joah](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@joah](https://forum.dfinity.org/u/joah)\
**Post date:** [November 25, 2024, 8:01pm UTC](https://forum.dfinity.org/t/failed-to-deserialize-idl-blob-invalid-data/37720/4 "2024-11-25T20:01:49Z")

</div>

Thank you very much @rem.codes . Let me update my code based on your solution.
