Skip to content

Commit

Permalink
Improved the key since many events, crypto-transfers could have the s…
Browse files Browse the repository at this point in the history
…ame transactionHash but different logIndex.

Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Jun 10, 2024
1 parent d397551 commit b40f662
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions subgraphs/starter-example/src/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b40f662

Please sign in to comment.