Querying transaction records for an Ethereum address is a common challenge in ETH wallet development, especially since Web3j lacks direct APIs for this purpose. This guide explores two practical solutions and provides implementation details.
Solution 1: Etherscan API Integration
Etherscan's API offers a straightforward way to retrieve transaction histories in JSON format:
API Endpoint Structure
https://api.etherscan.io/api?
module=account&
action=txlist&
address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&
startblock=0&
endblock=99999999&
sort=asc&
apikey=YourApiKeyTokenKey Parameters
- module/action: Fixed values (
accountandtxlist) block range:
startblock: Initial block (typically 0)endblock: Final block (use "latest" for most recent)
Pagination:
- Add
pageandoffsetparameters for customized result counts
- Add
๐ Boost your ETH development with these pro tips
Limitations
- Returns maximum 1,000 recent transactions
- Requires API key (register on Etherscan for free tokens)
Response Handling
The API returns JSON containing:
- Transaction hashes
- Block confirmations
- Value transfers
- Gas details
Solution 2: Web3j Filter Approach
For developers needing complete historical data:
Implementation Steps
Set up transaction listener:
EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST, "walletAddress");Log transactions:
- Store filtered data in local database
Query locally:
- Retrieve records from your database when needed
Considerations
- Requires backend infrastructure
- May encounter synchronization issues on mobile
- Best for applications needing full historical access
Comparative Analysis
| Feature | Etherscan API | Web3j Filter |
|---|---|---|
| Historical Depth | Limited (1k tx) | Complete history |
| Implementation | HTTP requests | Continuous syncing |
| Maintenance | None required | Database management |
| Real-time Updates | Manual polling | Automatic |
FAQ Section
Q: Which solution is better for mobile wallets?
A: Etherscan API is generally preferable for mobile due to simpler implementation and lower resource requirements.
Q: How frequently should I poll Etherscan's API?
A: For most applications, polling every 5-10 minutes balances freshness with API rate limits.
Q: Can I combine both solutions?
A: Absolutely! Use Etherscan for initial data and Web3j filters for ongoing transactions.
Q: What about private chains?
A: Neither solution works directly - you'll need to implement custom RPC calls to your node.
๐ Discover advanced Ethereum development strategies
Best Practices
- Cache responses to reduce API calls
- Implement error handling for network issues
- Consider rate limits (Etherscan allows 5 calls/sec)
- Use proper indexing for local databases
By implementing either (or both) of these solutions, you can effectively query transaction records for ETH wallet addresses while maintaining good performance and user experience.