Introduction
Managing a Web3 wallet involves keeping track of numerous addresses across different blockchain networks. A common task for developers and advanced users is programmatically retrieving a list of all addresses bound to a specific master account. This process is essential for portfolio tracking, generating reports, or managing funds across various chains. This guide provides a clear, step-by-step explanation of how to use a Wallet-as-a-Service (WaaS) API to query these addresses efficiently.
Understanding Account Address Retrieval
When you create a wallet account with a WaaS provider, it typically acts as a master account that can generate and manage multiple individual blockchain addresses. These addresses are often spread across different supported networks like Ethereum, Bitcoin, or other Layer 2 solutions. The ability to query all these addresses from a single point simplifies asset management and enhances operational oversight. The API endpoint designed for this purpose returns a structured list, often including chain identifiers and any user-added remarks for each address.
API Request Path and Method
To begin the retrieval process, you must call the correct API endpoint using the GET HTTP method.
The specific request path is:https://web3.okx.com/api/v5/wallet/account/account-detail
Required and Optional Request Parameters
Your API call must include specific parameters to receive the desired data. The following table details each parameter.
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | String | Yes | The unique identifier for your master account. |
chainIndex | String | No | A unique identifier for a specific blockchain to filter results. |
limit | String | No | The number of records to return per request. Default is 50, maximum is 100. |
cursor | String | No | A pagination cursor; used to retrieve the next set of results. |
Understanding the Response Data
A successful API response will contain a JSON object with the following structure, providing you with the list of addresses and necessary information for pagination.
| Parameter | Type | Description |
|---|---|---|
cursor | String | Indicates the current position for pagination. |
addresses | Array | A list of address objects. |
>chainIndex | String | The unique identifier of the blockchain for the address. |
>address | String | The actual public blockchain address. |
>remark | String | Any remark or note associated with the address. |
Step-by-Step Request Example
The following example demonstrates how to construct a curl command to call the API. Remember to replace all placeholder values (like your API keys and account ID) with your actual credentials.
curl --location --request GET 'https://web3.okx.com/api/v5/wallet/account/account-detail?accountId=44486e05-3235-2f8e-5fe2-a8ab46217863' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-PROJECT: 86af********d1bc' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'Interpreting the Response Example
After making the request, you will receive a response similar to the one below. A "code": "0" signifies a successful request. The data array contains the cursor for the next page and the addresses array with the requested details.
{
"code": "0",
"data": [
{
"cursor": "50",
"addresses": [
{
"chainIndex": "1",
"address": "0xdf54b6c6195ea4d948d03bfd818d365cf175cfc2"
},
{
"chainIndex": "3",
"address": "0x04ad62387d1f1c7034087bbe4d16163d06fae42d"
}
]
}
],
"msg": "success"
}Best Practices for Implementation
- Error Handling: Always check the response code. A non-zero value indicates an error, and the
msgfield will describe the issue. - Pagination Management: If you have many addresses, use the
limitandcursorparameters to paginate through the results efficiently, ensuring your application handles large datasets smoothly. - Security: Never hardcode API keys, passphrases, or other sensitive credentials directly in your application's source code. Use secure environment variables or a dedicated secrets management service.
- Data Caching: To reduce API calls and improve performance, consider caching the list of addresses if they do not change frequently.
For a deeper dive into secure API integration and advanced management techniques, you can explore more strategies here.
Frequently Asked Questions
What is an accountId and where can I find it?
The accountId is a unique identifier assigned to your master wallet account upon creation. You can typically find it within your wallet dashboard or through the provider's account management API. It is not your public blockchain address.
Why would I use the chainIndex parameter?
The chainIndex parameter is optional but useful for filtering. If you only want to retrieve addresses for a specific blockchain (e.g., only Ethereum addresses), providing the correct chainIndex value will narrow down the results, making the response more relevant.
How does the cursor work for pagination?
The API uses cursor-based pagination. The response will include a cursor value if more records are available. To get the next page of results, you simply include this cursor value in your subsequent API request.
What should I do if the API returns an error code?
First, consult the API documentation for a list of error codes and their meanings. Common issues include invalid authentication, a missing or incorrect accountId, or rate limiting. Ensure your request headers and parameters are formatted correctly.
Can I add or modify remarks for an address via this API?
No, this API endpoint is specifically for querying (reading) data. To add or modify remarks for an address, you would need to use a different API endpoint designed for updating address information.
Is this functionality available on all blockchain networks?
The supported networks depend entirely on your WaaS provider. The API will only return addresses for the blockchains that the provider and your account are configured to support. Always check the official documentation for a list of integrated networks.