From b40f66237c7cd33fe5cce958c31a43c7fde978e3 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Mon, 10 Jun 2024 12:51:52 -0600 Subject: [PATCH] Improved the key since many events, crypto-transfers could have the same transactionHash but different logIndex. Signed-off-by: Alfredo Gutierrez --- subgraphs/starter-example/src/mappings.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subgraphs/starter-example/src/mappings.ts b/subgraphs/starter-example/src/mappings.ts index 23dc4fd..3315cae 100644 --- a/subgraphs/starter-example/src/mappings.ts +++ b/subgraphs/starter-example/src/mappings.ts @@ -2,14 +2,17 @@ import { Transfer as TransferEvent } from '../generated/ERC20/ERC20'; import { Transfer } from "../generated/schema"; export function handleTransfer(event: TransferEvent): void { + + let id = event.transaction.hash.toHex() + "-" + event.logIndex.toString(); + // Entities can be loaded from the store using a string ID; this ID // needs to be unique across all entities of the same type - let entity = Transfer.load(event.transaction.hash.toHexString()); + let entity = Transfer.load(id); // Entities only exist after they have been saved to the store; // `null` checks allow to create entities on demand if (!entity) { - entity = new Transfer(event.transaction.hash.toHex()); + entity = new Transfer(id); } // Entity fields can be set based on event parameters