Skip to content

[Bug]: sdk.getTokenBalances() inverted arguments #417

Closed
@rsodre

Description

@rsodre

Dojo.js Version

1.2.4

What happened?

The sdk.getTokenBalances() endpoint does not work when fetching accounts or addresses

What is the expected behavior?

We should be able to fetch token account and contracts

Steps to reproduce

this will not work...

# fetching all balances of a contract
const response: torii.TokenBalance[] = await sdk.getTokenBalances(
  //--- accounts
  [],
  //--- contracts
  ['0x43f800e9f5f6e290a798379029fcb28ba7c34e9669f7b5fc77fce8a4ebdc893'], // duelist_token
  //--- tokens
  [],
)
# fetching all balances of an adddress
const response: torii.TokenBalance[] = await sdk.getTokenBalances(
  //--- accounts
  ['0x550212d3f13a373dfe9e3ef6aa41fba4124bde63fd7955393f879de19f3f47f'], // controller account
  //--- contracts
  [],
  //--- tokens
  [],
)

but this work...

# fetching all balances of a contract
const response: torii.TokenBalance[] = await sdk.getTokenBalances(
  //--- accounts
  ['0x43f800e9f5f6e290a798379029fcb28ba7c34e9669f7b5fc77fce8a4ebdc893'], // duelist_token
  //--- contracts
  [],
  //--- tokens
  [],
)
# fetching all balances of an adddress
const response: torii.TokenBalance[] = await sdk.getTokenBalances(
  //--- accounts
  [],
  //--- contracts
  ['0x550212d3f13a373dfe9e3ef6aa41fba4124bde63fd7955393f879de19f3f47f'], // controller account
  //--- tokens
  [],
)

because the arguments are inverted.

this is dojo.js...
https://github.com/dojoengine/dojo.js/blob/09c2599666244d57b9876691b7b683dc1f199070/packages/sdk/src/index.ts#L277C1-L287C1

getTokenBalances: async (
    account_addresses: string[],
    contract_addresses: string[],
    token_ids: string[]
): Promise<torii.TokenBalances> => {
    return await client.getTokenBalances(
        account_addresses,
        contract_addresses,
        token_ids
    );
},

this is dojo.c...
https://github.com/dojoengine/dojo.c/blob/318250c651940844d9ad0b659033b615f0479d03/src/wasm/mod.rs#L737C1-L742C42

    pub async fn get_token_balances(
        &self,
        contract_addresses: Vec<String>,
        account_addresses: Vec<String>,
        token_ids: Vec<String>,
    ) -> Result<TokenBalances, JsValue> {

Trace

No response

Is there an existing issue for this?

  • I have searched the existing issues and verified no issue exits for this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions