@@ -181,11 +181,13 @@ export async function getErc20Transfers(
181181 if ( query . wallet ) filter . wallet = hexToBytes ( query . wallet ) ;
182182 if ( query . contractAddress ) filter . tokens = [ hexToBytes ( query . contractAddress ) ] ;
183183
184- // Fetch decimals if filtering by a specific contract
185- let decimals : number | undefined ;
186- if ( query . contractAddress ) {
187- const metadata = await getErc20TokenMetadata ( client , query . contractAddress ) ;
188- decimals = metadata [ 0 ] ?. decimals ;
184+ // Fetch all token metadata to build a decimals lookup
185+ const allMetadata = await getErc20TokenMetadata ( client , query . contractAddress || undefined ) ;
186+ const decimalsMap = new Map < string , number > ( ) ;
187+ for ( const m of allMetadata ) {
188+ if ( m . decimals != null ) {
189+ decimalsMap . set ( m . token , m . decimals ) ;
190+ }
189191 }
190192
191193 const response = await client . call (
@@ -198,15 +200,19 @@ export async function getErc20Transfers(
198200 const transfers = response . transfers ;
199201 const list = Array . isArray ( transfers ) ? transfers : transfers ? [ transfers ] : [ ] ;
200202
201- return list . map ( ( t : Record < string , unknown > ) => ( {
202- token : bytesToHex ( t . token as string | Uint8Array | undefined ) ,
203- from : bytesToHex ( t . from as string | Uint8Array | undefined ) ,
204- to : bytesToHex ( t . to as string | Uint8Array | undefined ) ,
205- amount : formatU256 ( t . amount as string | Uint8Array | undefined , decimals ) ,
206- blockNumber : Number ( t . blockNumber ?? 0 ) ,
207- txHash : bytesToHex ( t . txHash as string | Uint8Array | undefined ) ,
208- timestamp : Number ( t . timestamp ?? 0 ) ,
209- } ) ) ;
203+ return list . map ( ( t : Record < string , unknown > ) => {
204+ const token = bytesToHex ( t . token as string | Uint8Array | undefined ) ;
205+ const decimals = decimalsMap . get ( token ) ;
206+ return {
207+ token,
208+ from : bytesToHex ( t . from as string | Uint8Array | undefined ) ,
209+ to : bytesToHex ( t . to as string | Uint8Array | undefined ) ,
210+ amount : formatU256 ( t . amount as string | Uint8Array | undefined , decimals ) ,
211+ blockNumber : Number ( t . blockNumber ?? 0 ) ,
212+ txHash : bytesToHex ( t . txHash as string | Uint8Array | undefined ) ,
213+ timestamp : Number ( t . timestamp ?? 0 ) ,
214+ } ;
215+ } ) ;
210216}
211217
212218export async function getErc721Transfers (
0 commit comments