List User Wallets API
This API endpoint allows authenticated users to retrieve a list of all Ethereum wallets associated with their account, including the primary wallet and any additional wallets.
Endpointβ
GET /api/wallet/list
Authenticationβ
This endpoint requires authentication. Ensure that the user is logged in and has a valid session.
Requestβ
This endpoint does not require any parameters in the request body or query string. The user's information is obtained from the authenticated session.
Responseβ
The API returns a JSON object with the following structure:
{
wallets: Array<{
address: string;
isPrimary: boolean;
}>
}
Where:
-
wallets
is an array of wallet objects. -
Each wallet object contains:
-
address
: The Ethereum wallet address. -
isPrimary
: A boolean indicating whether this is the user's primary wallet.
Retrieve the list of wallets for the authenticated user:
const response = await fetch('/api/wallet/list', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
console.log(data.wallets); // Array of user's wallets
Error Responsesβ
The API may return the following error responses:
401 Unauthorized
: If the user is not authenticated.404 Not Found
: If the authenticated user's data is not found in the database.500 Internal Server Error
: If there's an error fetching the user's wallet data from the database.
- The endpoint first checks if the user is authenticated using the
auth()
function. - It then retrieves the user's data from the Firebase Admin database.
- The primary wallet is identified and marked with
isPrimary: true
. - Any additional wallets are extracted from the
additionalWallets
array in the user data. - All wallets are combined into a single array and returned to the client.
Ensure that proper authentication and authorization checks are in place to prevent unauthorized access to user wallet information.
- Implement proper error handling in your client-side code to manage potential API errors.
- Consider implementing rate limiting to prevent abuse of this endpoint.
- Cache the wallet list results for a short period to reduce database load and improve response times.
- Regularly audit and clean up unused or inactive additional wallets to maintain data hygiene.
- This API currently only lists Ethereum-compatible wallets.
- The API does not provide balance information for the wallets. To get balance information, you would need to call the balance API for each wallet separately.
- The order of additional wallets in the list is not guaranteed and may change between calls.
Stay tuned for updates and feel free to provide feedback for improvements!