Fix ERC-20 transfers showing as 0 ETH due to dedup bug
All checks were successful
check / check (push) Successful in 14s

When sending an ERC-20 token, Blockscout returns the same tx hash
from both the /transactions endpoint (as a 0 ETH contract call) and
the /token-transfers endpoint (as the actual token transfer with
amount and symbol). The old dedup logic kept the 0 ETH version and
skipped the token transfer.

Now token transfers replace normal transactions with the same hash,
since the token transfer has the real amount, symbol, and contract
address.
This commit is contained in:
2026-02-27 12:29:15 +07:00
parent 2467dfd09c
commit d29273114b

View File

@@ -94,19 +94,22 @@ async function fetchRecentTransactions(address, blockscoutUrl, count = 25) {
const txJson = txResp.ok ? await txResp.json() : {}; const txJson = txResp.ok ? await txResp.json() : {};
const ttJson = ttResp.ok ? await ttResp.json() : {}; const ttJson = ttResp.ok ? await ttResp.json() : {};
const txs = []; const txsByHash = new Map();
for (const tx of txJson.items || []) { for (const tx of txJson.items || []) {
txs.push(parseTx(tx, addrLower)); txsByHash.set(tx.hash, parseTx(tx, addrLower));
} }
// Deduplicate: skip token transfers whose tx hash is already present // When a token transfer shares a hash with a normal tx, the normal tx
const seenHashes = new Set(txs.map((t) => t.hash)); // is the contract call (0 ETH) and the token transfer has the real
// amount and symbol. Replace the normal tx with the token transfer.
for (const tt of ttJson.items || []) { for (const tt of ttJson.items || []) {
if (seenHashes.has(tt.transaction_hash)) continue; const parsed = parseTokenTransfer(tt, addrLower);
txs.push(parseTokenTransfer(tt, addrLower)); txsByHash.set(parsed.hash, parsed);
} }
const txs = [...txsByHash.values()];
txs.sort((a, b) => b.blockNumber - a.blockNumber); txs.sort((a, b) => b.blockNumber - a.blockNumber);
const result = txs.slice(0, count); const result = txs.slice(0, count);
log.debugf("fetchRecentTransactions done, count:", result.length); log.debugf("fetchRecentTransactions done, count:", result.length);