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.
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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:
src/nft-marketplace.ts
: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/schema.ts
: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));
}
}
}