如何通过API接口查询IOTA代币余额?
How to Fetch IOTA Coin Balance via Official API
Got it, let's walk through how to get your IOTA Coin balance directly using the official API step by step—no need to dig through docs for hours anymore.
Core Endpoint: getBalances
The official getBalances endpoint is designed specifically for pulling balance data for one or more IOTA addresses. It returns both total and confirmed balances based on your specified confirmation threshold.
Key Parameters
addresses(required): An array of IOTA addresses (in Bech32 format, starting withiota1q...for mainnet) you want to check. You can pass multiple addresses in a single request.threshold(optional, default: 100): The number of confirmations needed for a transaction to be considered "confirmed". Higher values mean more secure, finalized balance data.
Example Request (curl)
Here's a quick command-line example to test the endpoint:
curl -X POST https://api.iota.org/api/v1/getBalances \ -H "Content-Type: application/json" \ -d '{ "addresses": ["iota1qzxyz...your-full-address-here..."], "threshold": 100 }'
Example Response
A successful response will structure data like this:
{ "balances": ["987654321"], "references": ["txHash123..."], "milestoneIndex": 456789, "duration": 15 }
balances: An array matching the order of your input addresses, showing the total balance in IOTA tokens (1 IOTA = 10^-9 MIOTA).references: The latest confirmed transaction hash for each address.milestoneIndex: The current network milestone index when the balance was calculated.duration: Time taken to process the request (in milliseconds).
Quick Tips
- Double-check that your addresses are correctly formatted—invalid addresses will throw an error.
- Stick to the default
thresholdvalue of 100 unless you have a specific need for more/less confirmations. - Add error handling in your code to account for network timeouts or invalid requests.
内容的提问来源于stack exchange,提问作者venkat venki
相关产品推荐
相关产品推荐

