GeezerVison is showing github.com — Add `stellar token balance` command by fnando · Pull Request #2651 · stellar/stellar-cli
Conversation
fnando
commented
Jul 20, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
What
Add a stellar token balance command that reads the token balance of an account or contract. The token can be specified as a contract id or alias, native, or a classic asset as CODE:ISSUER. By default the balance is returned in the token's raw smallest unit (stroops for a Stellar Asset Contract); --decimal formats it using the token's decimals. Output is available as text (default) or JSON via --output.
$ $stellar token balance --id native --account fnando --output=json
{"balance":"100000000000"}
$ $stellar token balance --id native --account fnando
100000000000
$ $stellar token balance --id usdc --account fnando --network testnet
2000000
$ $stellar token balance --id USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 --account fnando --network testnet
2000000
$ $stellar token balance --id USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5 --account fnando --network testnet --decimal
0.2
$ http https://horizon-testnet.stellar.org/accounts/$($stellar keys address fnando) | jq '.balances | first | {asset_code, asset_issuer, balance}'
{
"asset_code": "USDC",
"asset_issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
"balance": "0.2000000"
}
Why
Reading a token balance previously required a manual stellar contract invoke ... -- balance call and hand-decoding the result. This adds a first-class, read-only command that resolves the token (including classic assets and native) and returns a clean value, with token-aware errors when a Stellar Asset Contract isn't deployed yet.
Known limitations
N/A
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds first-class token balance queries with raw/decimal and text/JSON output.
Changes:
- Adds
stellar token balance and token resolution/error handling.
- Extends JSON errors with machine-readable types.
- Adds integration tests and help documentation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File |
Description |
FULL_HELP_DOCS.md |
Documents the balance command. |
cmd/soroban-cli/src/output.rs |
Adds typed JSON errors. |
cmd/soroban-cli/src/commands/token/transfer.rs |
Reuses shared token errors. |
cmd/soroban-cli/src/commands/token/mod.rs |
Registers the balance subcommand. |
cmd/soroban-cli/src/commands/token/balance.rs |
Implements balance queries. |
cmd/soroban-cli/src/commands/token/args.rs |
Adds shared deployment errors. |
cmd/soroban-cli/src/cli.rs |
Routes typed JSON failures. |
cmd/crates/soroban-test/tests/it/integration/token/mod.rs |
Registers balance tests. |
cmd/crates/soroban-test/tests/it/integration/token/balance.rs |
Tests balance behavior and errors. |
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions, but defer to you and looks good otherwise. The UX looks good with defaulting to raw values and offering decimal encoding if specified. I like how the flag is named --decimal which aligns with the decimals function name.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
mootz12
Awaiting requested review from mootz12
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|