Learn getTokenAccountBalance use cases, code examples, request parameters, response structure, and tips.
getTokenAccountBalance
RPC method returns the token balance of a specific SPL Token account. This is essential for applications that need to display or verify the amount of a particular token held by a token account.
commitment
(string, optional): Specifies the commitment level for the query. If omitted, the default commitment of the RPC node is used (usually finalized
).result
field in the JSON-RPC response contains an object with a context
and a value
field. The value
object holds the balance information:
amount
(string): The raw balance of the token account as a string. This is an integer representing the smallest unit of the token (e.g., if a token has 6 decimals, an amount of “1000000” means 1 token).decimals
(u8): The number of decimal places defined for this token type (by its mint).uiAmount
(number | null): The balance formatted as a floating-point number, taking into account the decimals
. This field might be null
or deprecated in some contexts in favor of uiAmountString
.uiAmountString
(string): The balance formatted as a string, taking into account the decimals
. This is often preferred for display to avoid potential floating-point inaccuracies.getTokenAccountsByOwner
.decimals
field to correctly interpret the amount
. The uiAmountString
is generally safer for display than uiAmount
to avoid floating-point precision issues.value
in the response will be null
or an error will be thrown. The JavaScript example includes a basic check for balance.value
.finalized
is the safest but has the most latency.getTokenAccountBalance
method.