I’m working on creating a subgraph that tracks just active NFTs in a marketplace.
But I’m running into the following issue:
Error: wasm trap: out of bounds memory access wasm backtrace: 0: 0x15c1 - <unknown>!~lib/@graphprotocol/graph-ts/common/value/Value#toBigInt 1: 0x162c - <unknown>!~lib/@graphprotocol/graph-ts/common/value/Value#toBytes 2: 0x2b85 - <unknown>!generated/schema/ItemCanceled#get:tokenId in handler `handleItemListed` at block #10371597 (5f8865fcd8429b1300c51d92bcffcd7b5537ec754a15a1f40a065cd1ba94e9f8)
My schema.graphql:
type ItemBought @entity {
id: ID!
buyer: Bytes! # Address
nftAddress: Bytes! # address
tokenId: BigInt! # address
price: BigInt!
}
type ItemListed @entity {
id: ID!
seller: Bytes! # Address
nftAddress: Bytes! # address
tokenId: BigInt! # address
price: BigInt!
}
type ItemCanceled @entity {
id: ID!
seller: Bytes! # Address
nftAddress: Bytes! # address
tokenId: BigInt!
}
type ActiveItem @entity {
id: ID!
nftAddress: Bytes! # address
seller: Bytes
buyer: Bytes
price: BigInt
tokenId: BigInt
}
And my main mapping function:
export function getActiveItemId(tokenId: BigInt, nftAddress: Bytes): string {
return tokenId.toString() + nftAddress.toHexString()
}
export function handleItemListed(event: ItemListed): void {
// Our ID will be tokenId + nftAddress
let activeItem = ActiveItem.load(getActiveItemId(event.tokenId, event.nftAddress))
if (!activeItem) {
activeItem = new ActiveItem(event.tokenId.toString() + event.nftAddress.toHexString())
}
activeItem.seller = event.seller
activeItem.tokenId = event.tokenId
activeItem.nftAddress = event.nftAddress
activeItem.price = event.price
activeItem.save()
}
And my event in solidity being emitted:
event ItemListed(
address indexed seller,
address indexed nftAddress,
uint256 indexed tokenId,
uint256 price
);
Any thoughts?
The current studio is located here: Subgraph Studio