@@ -41,7 +41,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
4141 getETHBalanceByAddress = async ( address : string ) : Promise < string > => {
4242 const balanceResponse : AxiosResponse < BalancesByAddressResponse > = await axios ( {
4343 baseURL : this . indexingBaseUrl ,
44- url : `/address /${ address . toLowerCase ( ) } /balance ` ,
44+ url : `/addresses /${ address . toLowerCase ( ) } /native_balance ` ,
4545 } ) ;
4646
4747 if ( balanceResponse . status !== 200 ) {
@@ -62,7 +62,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
6262 getBalanceByAddress = async ( address : string , options ?: balanceQueryBaseParams ) => {
6363 const balanceResponse : AxiosResponse < BalancesByAddressResponse > = await axios ( {
6464 baseURL : this . indexingBaseUrl ,
65- url : `/address /${ address . toLowerCase ( ) } /balance ` ,
65+ url : `/addresses /${ address . toLowerCase ( ) } /token_balance ` ,
6666 params : { ...options } ,
6767 } ) ;
6868
@@ -79,7 +79,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
7979
8080 getTxsByAddress = async ( address : string , options ?: txQueryBaseParams ) => {
8181 // Pagination params
82- let currentPage = options ?. page || 0 ;
82+ let currentPage = options ?. page || 1 ;
8383 const limit = options ?. pageSize || 100 ;
8484
8585 // Result
@@ -91,7 +91,6 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
9191 const txDataList = await this . getTxsByAddressPaginated ( address , {
9292 pageSize : limit ,
9393 page : currentPage ,
94- sort : 'timestamp:desc' ,
9594 } ) ;
9695
9796 // Append TxData list to the final response array
@@ -111,7 +110,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
111110 private getTxsByAddressPaginated = async ( address : string , options ?: txQueryBaseParams ) => {
112111 const txListResponse : AxiosResponse < TransactionsByAddressResponse > = await axios ( {
113112 baseURL : this . indexingBaseUrl ,
114- url : `/address /${ address . toLowerCase ( ) } /normal ` ,
113+ url : `/addresses /${ address . toLowerCase ( ) } /transactions ` ,
115114 params : { ...options } ,
116115 } ) ;
117116
@@ -134,4 +133,54 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
134133 getInternalTxsByAddress ( address : string , options ?: any ) {
135134 throw new Error ( 'Method not implemented.' ) ;
136135 }
136+
137+
138+ getERC20TransfersByAddress = async ( address : string , options ?: txQueryBaseParams ) => {
139+ // Pagination params
140+ let currentPage = options ?. page || 1 ;
141+ const limit = options ?. pageSize || 100 ;
142+
143+ // Result
144+ const finalList : TransactionData [ ] = [ ] ;
145+
146+ // eslint-disable-next-line no-constant-condition
147+ while ( true ) {
148+ // eslint-disable-next-line
149+ const txDataList = await this . getERC20TransfersByAddressPaginated ( address , {
150+ pageSize : limit ,
151+ page : currentPage ,
152+ sort : 'timestamp:desc' ,
153+ } ) ;
154+
155+ // Append TxData list to the final response array
156+ finalList . push ( ...txDataList ) ;
157+
158+ // Increment pagination params
159+ currentPage += 1 ;
160+
161+ if ( txDataList . length < 1 || txDataList . length < limit ) {
162+ break ;
163+ }
164+ }
165+
166+ return finalList ;
167+ } ;
168+
169+ private getERC20TransfersByAddressPaginated = async ( address : string , options ?: txQueryBaseParams ) => {
170+ const txListResponse : AxiosResponse < TransactionsByAddressResponse > = await axios ( {
171+ baseURL : this . indexingBaseUrl ,
172+ url : `/addresses/${ address . toLowerCase ( ) } /transfers` ,
173+ params : { ...options } ,
174+ } ) ;
175+
176+ if ( txListResponse . status !== 200 ) {
177+ return [ ] ;
178+ }
179+
180+ if ( ! txListResponse . data . data ) {
181+ return [ ] ;
182+ }
183+
184+ return txListResponse . data . data as TransactionData [ ] ;
185+ } ;
137186}
0 commit comments