Can I get balance coin of account (address)?

Hello guys
Can I get the token’s account (sender) balance in contract programming?

Hi @cryptojame,

No, it’s not possible to access information about a sender other than through the objects they authorize you to access in the transaction. This is because of Sui’s Object-centric programming model, you can read more about it in this blog post. Sui is set-up this way so that:

  • Users get greater control over what they authorize a transaction to do (for example, if they only want to authorize a transaction to use up to X SUI, they can do that by passing in a Coin<SUI> with a balance of X, and they will know that the transaction cannot access other coins that they own but they didn’t pass in as inputs).
  • The system can take advantage of this information to run transactions in parallel.

Hi @amnn
Hum so we can’t know how many tokens a user is holding right? I mean just want to see how many tokens the user is holding.

This is not something you can access on-chain, but off-chain, you can make an RPC call for this information:

In JSON-RPC, suix_getBalance.

{
    "jsonrpc": "2.0",
    "method": "suix_getBalance",
    "id": 1,
    "params": [$OWNER]
}

In GraphQL, Address.balance:

{
    address(address: $owner) {
        balance { 
            totalBalance
        }
    }
}

Thank @amnn
It’s easy if use sui client or sui sdk guy. I mean want to get the coin’s balance in sui contract (move) on-chain.

As you’ve described it, what you want to do (get the entire balance for an address, in Move, on-chain) is not possible, but maybe there is another way to get you unblocked. Can you share some more details about what you’re trying to achieve and how this request fits into it?