You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### TL;DR
Added a new API endpoint to fetch token balances by type (ERC20, ERC721, ERC1155) for a given address.
### What changed?
- Added `/balances/:owner/:type` endpoint to retrieve token balances
- Created materialized views in ClickHouse to track token balances from transfer events
- Implemented balance querying with support for pagination and filtering
- Added support for hiding zero balances
- Introduced token balance data structures and query filters
### How to test?
1. Start the API server
2. Query the endpoint: `/balances/{address}/{token_type}`
- `token_type`: "erc20", "erc721", or "erc1155"
- Optional query params:
- `hide_zero_balances`: true/false
- `token_address`: specific token contract
- `page` and `limit`: for pagination
- `sort_by` and `sort_order`: for sorting
### Why make this change?
To provide a convenient way to fetch token balances for addresses across different token standards, enabling better wallet integration and portfolio tracking capabilities.
query:=fmt.Sprintf("SELECT %s FROM %s.token_balances FINAL WHERE chain_id = ? AND token_type = ? AND owner = ? AND balance %s 0", columns, c.cfg.Database, balanceCondition)
1380
+
1381
+
ifqf.TokenAddress!="" {
1382
+
query+=fmt.Sprintf(" AND address = '%s'", qf.TokenAddress)
1383
+
}
1384
+
1385
+
// Add ORDER BY clause
1386
+
ifqf.SortBy!="" {
1387
+
query+=fmt.Sprintf(" ORDER BY %s %s", qf.SortBy, qf.SortOrder)
0 commit comments