Calculate what a Cosmos account can spend today
A vesting account can hold coins it cannot transfer yet. A withdrawal form needs the spendable amount for the selected denomination.
Query the spendable balance
Set ADDR to the address and GRPC to a TLS gRPC endpoint with reflection. This example targets a chain with the bank query service and the denomination uatom.
grpcurl -d "{\"address\":\"$ADDR\",\"denom\":\"uatom\"}" "$GRPC" cosmos.bank.v1beta1.Query/SpendableBalanceByDenom
If the total is 9,000,000 uatom and the spendable result is 2,000,000, the latter caps the amount available before fees. Parse the returned amount as an integer in base units.
Leave room for the transaction fee
When the fee is paid from the same account in uatom, subtract it before proposing a maximum send. A separate fee payer or fee grant changes that calculation. An unsupported query method requires checking the chain’s SDK version. github.com Cosmos SDK Query API