PatrickAlphaC / nextjs-nft-marketplace-thegraph-fcc

39 stars 33 forks source link

Subgraph INDEXING ERROR: Error: failed to process trigger: block... #1

Closed JMariadlcs closed 2 years ago

JMariadlcs commented 2 years ago

Hello everyone, I am getting an error when trying to synchronize a subgraph with the NftMarketplace.sol Smart Contract to listen for the events.

You can see my repos here:

I am uploading a screenshot with the error that I am getting. I have followed every step on the tutorial and have tried to solve it in different ways but it did not work. I am out of ideas right now. You can check my repos in case you want to help me.

I am posting some code from Graph repo:

export function handleItemListed(event: ItemListedEvent): void { let itemListed = ItemListed.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); let activeItem = ActiveItem.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); if (!itemListed) { itemListed = new ItemListed( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); } if (!activeItem) { activeItem = new ActiveItem( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); } itemListed.seller = event.params.seller; activeItem.seller = event.params.seller;

itemListed.nftAddress = event.params.nftAddress; activeItem.nftAddress = event.params.nftAddress;

itemListed.tokenId = event.params.tokenId; activeItem.tokenId = event.params.tokenId;

itemListed.price = event.params.price; activeItem.price = event.params.price;

itemListed.save(); activeItem.save(); }

export function handleItemCanceled(event: ItemCanceledEvent): void { let itemCanceled = ItemCanceled.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); let activeItem = ActiveItem.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); if (!itemCanceled) { itemCanceled = new ItemCanceled( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); } itemCanceled.seller = event.params.seller; itemCanceled.nftAddress = event.params.nftAddress; itemCanceled.tokenId = event.params.tokenId; activeItem!.buyer = Address.fromString( "0x000000000000000000000000000000000000dEaD" );

itemCanceled.save(); activeItem!.save(); }

export function handleItemBought(event: ItemBoughtEvent): void { let itemBought = ItemBought.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); let activeItem = ActiveItem.load( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); if (!itemBought) { itemBought = new ItemBought( getIdFromEventParams(event.params.tokenId, event.params.nftAddress) ); } itemBought.buyer = event.params.buyer; itemBought.nftAddress = event.params.nftAddress; itemBought.tokenId = event.params.tokenId; activeItem!.buyer = event.params.buyer;

itemBought.save(); activeItem!.save(); }

function getIdFromEventParams(tokenId: BigInt, nftAddress: Address): string { return tokenId.toHexString() + nftAddress.toHexString(); }


- `generated/NftMarketplace/NftMarketplace.ts`: 
```bash
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

import {
  ethereum,
  JSONValue,
  TypedMap,
  Entity,
  Bytes,
  Address,
  BigInt
} from "@graphprotocol/graph-ts";

export class ItemBought extends ethereum.Event {
  get params(): ItemBought__Params {
    return new ItemBought__Params(this);
  }
}

export class ItemBought__Params {
  _event: ItemBought;

  constructor(event: ItemBought) {
    this._event = event;
  }

  get buyer(): Address {
    return this._event.parameters[0].value.toAddress();
  }

  get nftAddress(): Address {
    return this._event.parameters[1].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._event.parameters[2].value.toBigInt();
  }

  get price(): BigInt {
    return this._event.parameters[3].value.toBigInt();
  }
}

export class ItemCanceled extends ethereum.Event {
  get params(): ItemCanceled__Params {
    return new ItemCanceled__Params(this);
  }
}

export class ItemCanceled__Params {
  _event: ItemCanceled;

  constructor(event: ItemCanceled) {
    this._event = event;
  }

  get seller(): Address {
    return this._event.parameters[0].value.toAddress();
  }

  get nftAddress(): Address {
    return this._event.parameters[1].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._event.parameters[2].value.toBigInt();
  }
}

export class ItemListed extends ethereum.Event {
  get params(): ItemListed__Params {
    return new ItemListed__Params(this);
  }
}

export class ItemListed__Params {
  _event: ItemListed;

  constructor(event: ItemListed) {
    this._event = event;
  }

  get seller(): Address {
    return this._event.parameters[0].value.toAddress();
  }

  get nftAddress(): Address {
    return this._event.parameters[1].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._event.parameters[2].value.toBigInt();
  }

  get price(): BigInt {
    return this._event.parameters[3].value.toBigInt();
  }
}

export class NftMarketplace__getListingResultValue0Struct extends ethereum.Tuple {
  get price(): BigInt {
    return this[0].toBigInt();
  }

  get seller(): Address {
    return this[1].toAddress();
  }
}

export class NftMarketplace extends ethereum.SmartContract {
  static bind(address: Address): NftMarketplace {
    return new NftMarketplace("NftMarketplace", address);
  }

  getListing(
    nftAddress: Address,
    tokenId: BigInt
  ): NftMarketplace__getListingResultValue0Struct {
    let result = super.call(
      "getListing",
      "getListing(address,uint256):((uint256,address))",
      [
        ethereum.Value.fromAddress(nftAddress),
        ethereum.Value.fromUnsignedBigInt(tokenId)
      ]
    );

    return changetype<NftMarketplace__getListingResultValue0Struct>(
      result[0].toTuple()
    );
  }

  try_getListing(
    nftAddress: Address,
    tokenId: BigInt
  ): ethereum.CallResult<NftMarketplace__getListingResultValue0Struct> {
    let result = super.tryCall(
      "getListing",
      "getListing(address,uint256):((uint256,address))",
      [
        ethereum.Value.fromAddress(nftAddress),
        ethereum.Value.fromUnsignedBigInt(tokenId)
      ]
    );
    if (result.reverted) {
      return new ethereum.CallResult();
    }
    let value = result.value;
    return ethereum.CallResult.fromValue(
      changetype<NftMarketplace__getListingResultValue0Struct>(
        value[0].toTuple()
      )
    );
  }

  getProceeds(seller: Address): BigInt {
    let result = super.call("getProceeds", "getProceeds(address):(uint256)", [
      ethereum.Value.fromAddress(seller)
    ]);

    return result[0].toBigInt();
  }

  try_getProceeds(seller: Address): ethereum.CallResult<BigInt> {
    let result = super.tryCall(
      "getProceeds",
      "getProceeds(address):(uint256)",
      [ethereum.Value.fromAddress(seller)]
    );
    if (result.reverted) {
      return new ethereum.CallResult();
    }
    let value = result.value;
    return ethereum.CallResult.fromValue(value[0].toBigInt());
  }
}

export class BuyItemCall extends ethereum.Call {
  get inputs(): BuyItemCall__Inputs {
    return new BuyItemCall__Inputs(this);
  }

  get outputs(): BuyItemCall__Outputs {
    return new BuyItemCall__Outputs(this);
  }
}

export class BuyItemCall__Inputs {
  _call: BuyItemCall;

  constructor(call: BuyItemCall) {
    this._call = call;
  }

  get nftAddress(): Address {
    return this._call.inputValues[0].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._call.inputValues[1].value.toBigInt();
  }
}

export class BuyItemCall__Outputs {
  _call: BuyItemCall;

  constructor(call: BuyItemCall) {
    this._call = call;
  }
}

export class CancelListingCall extends ethereum.Call {
  get inputs(): CancelListingCall__Inputs {
    return new CancelListingCall__Inputs(this);
  }

  get outputs(): CancelListingCall__Outputs {
    return new CancelListingCall__Outputs(this);
  }
}

export class CancelListingCall__Inputs {
  _call: CancelListingCall;

  constructor(call: CancelListingCall) {
    this._call = call;
  }

  get nftAddress(): Address {
    return this._call.inputValues[0].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._call.inputValues[1].value.toBigInt();
  }
}

export class CancelListingCall__Outputs {
  _call: CancelListingCall;

  constructor(call: CancelListingCall) {
    this._call = call;
  }
}

export class ListItemCall extends ethereum.Call {
  get inputs(): ListItemCall__Inputs {
    return new ListItemCall__Inputs(this);
  }

  get outputs(): ListItemCall__Outputs {
    return new ListItemCall__Outputs(this);
  }
}

export class ListItemCall__Inputs {
  _call: ListItemCall;

  constructor(call: ListItemCall) {
    this._call = call;
  }

  get nftAddress(): Address {
    return this._call.inputValues[0].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._call.inputValues[1].value.toBigInt();
  }

  get price(): BigInt {
    return this._call.inputValues[2].value.toBigInt();
  }
}

export class ListItemCall__Outputs {
  _call: ListItemCall;

  constructor(call: ListItemCall) {
    this._call = call;
  }
}

export class UpdateListingCall extends ethereum.Call {
  get inputs(): UpdateListingCall__Inputs {
    return new UpdateListingCall__Inputs(this);
  }

  get outputs(): UpdateListingCall__Outputs {
    return new UpdateListingCall__Outputs(this);
  }
}

export class UpdateListingCall__Inputs {
  _call: UpdateListingCall;

  constructor(call: UpdateListingCall) {
    this._call = call;
  }

  get nftAddress(): Address {
    return this._call.inputValues[0].value.toAddress();
  }

  get tokenId(): BigInt {
    return this._call.inputValues[1].value.toBigInt();
  }

  get newPrice(): BigInt {
    return this._call.inputValues[2].value.toBigInt();
  }
}

export class UpdateListingCall__Outputs {
  _call: UpdateListingCall;

  constructor(call: UpdateListingCall) {
    this._call = call;
  }
}

export class WithdrawProceedsCall extends ethereum.Call {
  get inputs(): WithdrawProceedsCall__Inputs {
    return new WithdrawProceedsCall__Inputs(this);
  }

  get outputs(): WithdrawProceedsCall__Outputs {
    return new WithdrawProceedsCall__Outputs(this);
  }
}

export class WithdrawProceedsCall__Inputs {
  _call: WithdrawProceedsCall;

  constructor(call: WithdrawProceedsCall) {
    this._call = call;
  }
}

export class WithdrawProceedsCall__Outputs {
  _call: WithdrawProceedsCall;

  constructor(call: WithdrawProceedsCall) {
    this._call = call;
  }
}

import { TypedMap, Entity, Value, ValueKind, store, Bytes, BigInt, BigDecimal } from "@graphprotocol/graph-ts";

export class ActiveItem extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); }

save(): void { let id = this.get("id"); assert(id != null, "Cannot save ActiveItem entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, Entities of type ActiveItem must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()} ); store.set("ActiveItem", id.toString(), this); } }

static load(id: string): ActiveItem | null { return changetype<ActiveItem | null>(store.get("ActiveItem", id)); }

get id(): string { let value = this.get("id"); return value!.toString(); }

set id(value: string) { this.set("id", Value.fromString(value)); }

get buyer(): Bytes { let value = this.get("buyer"); return value!.toBytes(); }

set buyer(value: Bytes) { this.set("buyer", Value.fromBytes(value)); }

get seller(): Bytes { let value = this.get("seller"); return value!.toBytes(); }

set seller(value: Bytes) { this.set("seller", Value.fromBytes(value)); }

get nftAddress(): Bytes { let value = this.get("nftAddress"); return value!.toBytes(); }

set nftAddress(value: Bytes) { this.set("nftAddress", Value.fromBytes(value)); }

get tokenId(): BigInt { let value = this.get("tokenId"); return value!.toBigInt(); }

set tokenId(value: BigInt) { this.set("tokenId", Value.fromBigInt(value)); }

get price(): BigInt | null { let value = this.get("price"); if (!value || value.kind == ValueKind.NULL) { return null; } else { return value.toBigInt(); } }

set price(value: BigInt | null) { if (!value) { this.unset("price"); } else { this.set("price", Value.fromBigInt(value)); } } }

export class ItemListed extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); }

save(): void { let id = this.get("id"); assert(id != null, "Cannot save ItemListed entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, Entities of type ItemListed must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()} ); store.set("ItemListed", id.toString(), this); } }

static load(id: string): ItemListed | null { return changetype<ItemListed | null>(store.get("ItemListed", id)); }

get id(): string { let value = this.get("id"); return value!.toString(); }

set id(value: string) { this.set("id", Value.fromString(value)); }

get seller(): Bytes { let value = this.get("seller"); return value!.toBytes(); }

set seller(value: Bytes) { this.set("seller", Value.fromBytes(value)); }

get nftAddress(): Bytes { let value = this.get("nftAddress"); return value!.toBytes(); }

set nftAddress(value: Bytes) { this.set("nftAddress", Value.fromBytes(value)); }

get tokenId(): BigInt { let value = this.get("tokenId"); return value!.toBigInt(); }

set tokenId(value: BigInt) { this.set("tokenId", Value.fromBigInt(value)); }

get price(): BigInt | null { let value = this.get("price"); if (!value || value.kind == ValueKind.NULL) { return null; } else { return value.toBigInt(); } }

set price(value: BigInt | null) { if (!value) { this.unset("price"); } else { this.set("price", Value.fromBigInt(value)); } } }

export class ItemCanceled extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); }

save(): void { let id = this.get("id"); assert(id != null, "Cannot save ItemCanceled entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, Entities of type ItemCanceled must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()} ); store.set("ItemCanceled", id.toString(), this); } }

static load(id: string): ItemCanceled | null { return changetype<ItemCanceled | null>(store.get("ItemCanceled", id)); }

get id(): string { let value = this.get("id"); return value!.toString(); }

set id(value: string) { this.set("id", Value.fromString(value)); }

get seller(): Bytes { let value = this.get("seller"); return value!.toBytes(); }

set seller(value: Bytes) { this.set("seller", Value.fromBytes(value)); }

get nftAddress(): Bytes { let value = this.get("nftAddress"); return value!.toBytes(); }

set nftAddress(value: Bytes) { this.set("nftAddress", Value.fromBytes(value)); }

get tokenId(): BigInt { let value = this.get("tokenId"); return value!.toBigInt(); }

set tokenId(value: BigInt) { this.set("tokenId", Value.fromBigInt(value)); } }

export class ItemBought extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); }

save(): void { let id = this.get("id"); assert(id != null, "Cannot save ItemBought entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, Entities of type ItemBought must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()} ); store.set("ItemBought", id.toString(), this); } }

static load(id: string): ItemBought | null { return changetype<ItemBought | null>(store.get("ItemBought", id)); }

get id(): string { let value = this.get("id"); return value!.toString(); }

set id(value: string) { this.set("id", Value.fromString(value)); }

get buyer(): Bytes { let value = this.get("buyer"); return value!.toBytes(); }

set buyer(value: Bytes) { this.set("buyer", Value.fromBytes(value)); }

get nftAddress(): Bytes { let value = this.get("nftAddress"); return value!.toBytes(); }

set nftAddress(value: Bytes) { this.set("nftAddress", Value.fromBytes(value)); }

get tokenId(): BigInt { let value = this.get("tokenId"); return value!.toBigInt(); }

set tokenId(value: BigInt) { this.set("tokenId", Value.fromBigInt(value)); }

get price(): BigInt | null { let value = this.get("price"); if (!value || value.kind == ValueKind.NULL) { return null; } else { return value.toBigInt(); } }

set price(value: BigInt | null) { if (!value) { this.unset("price"); } else { this.set("price", Value.fromBigInt(value)); } } }



Thank you!
JMariadlcs commented 2 years ago

Issue was solved here -> https://github.com/PatrickAlphaC/graph-nft-marketplace-fcc/issues/1