solana/docs/src/api/methods/_getTokenAccountBalance.mdx

92 lines
1.8 KiB
Plaintext

import {
DocBlock,
DocSideBySide,
CodeParams,
Parameter,
Field,
Values,
CodeSnippets,
} from "../../../components/CodeDocBlock";
<DocBlock>
## getTokenAccountBalance
Returns the token balance of an SPL Token account.
<DocSideBySide>
<CodeParams>
### Parameters:
<Parameter type={"string"} required={true}>
Pubkey of Token account to query, as base-58 encoded string
</Parameter>
<Parameter type={"object"} optional={true}>
Configuration object containing the following fields:
<Field
name="commitment"
type="string"
optional={true}
href="/api/http#configuring-state-commitment"
></Field>
</Parameter>
### Result:
The result will be an RpcResponse JSON object with `value` equal to a JSON object containing:
- `amount: <string>` - the raw balance without decimals, a string representation of u64
- `decimals: <u8>` - number of base 10 digits to the right of the decimal place
- `uiAmount: <number|null>` - the balance, using mint-prescribed decimals **DEPRECATED**
- `uiAmountString: <string>` - the balance as a string, using mint-prescribed decimals
For more details on returned data, the [Token Balances Structure](#token-balances-structure)
response from [getBlock](#getblock) follows a similar structure.
</CodeParams>
<CodeSnippets>
### Code sample:
```bash
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0", "id": 1,
"method": "getTokenAccountBalance",
"params": [
"7fUAJdStEuGbc3sM84cKRL6yYaaSstyLSU4ve5oovLS7"
]
}
'
```
### Response:
```json
{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 1114
},
"value": {
"amount": "9864",
"decimals": 2,
"uiAmount": 98.64,
"uiAmountString": "98.64"
},
"id": 1
}
}
```
</CodeSnippets>
</DocSideBySide>
</DocBlock>