EthNftOwners, EthNftOwnersPending not updating any more

What exactly do you do when you set a new instance, I tested yesterday and it worked for me
It was a time when I waited some minutes to see the data in dashboard, and you’ll have to authenticate with an address to the new server before seeing any data.

  1. Create new instance
  2. Add events for Sold Items and Item Added to Marketplace
  3. Update Cloud Functions with BeforeSave methods.

for User

  1. Authenticate User with Ropsten network
  2. Create NFT metadata Data with Image URL
  3. Mint NFT
  4. Approve for Marketplace
  5. Add to Marketplace

Nothing shows up in EthNFTOwnersPending or EthNftOwners
If its new server, these tables never gets created.

This was all working fine with the earlier version and only recently have stopped working. without any changes in code this end.

When did you test this last time? Asking because it should have been fixed ~1-2 days ago.

I just did it again on new server created about 15 minutes back

https://wceb5gycvcho.grandmoralis.com:2053/server

and its still not populating the EthNFTOwners and EthNFTOwnersPending

image

ok, you could try on bsc testnet until we figure it out why is not working

Can you try again now?

It shows up now. NICE! .

2 Likes

This is broken again, it’s not updating EthNFTOwners or EthNFTOwnersPending

1 Like

Same issue here … Not creating EthNFTOwners

do you have users on that server with NFTs on eth, or did you add to watch address an address that has?

I added to watch address and also minted some items on the same server

Another thing that is happening is that the row inserted is not being updated with the user and token set by my cloud beforeSave function then when I mint another item the previous row is updated.

strage, are you sure, did you refresh the dashboard page?

what is the server url that has that problem with EthNFTOwners?

Yes, I’m struggled to do that since yesterday.

The server is very slow too, I don’t know why … I keep creating new servers because every time there is a new problem.

Server: https://ve04zm8tainc.usemoralis.com:2053/server

on a dev server (Ganache) you also have EthNFTOwnersPending where the transactions will stay until you make more transactions

I see that there are 2 rows now in EthNFTOwners table on that server

Yes, should I try getting from EthNFTOwnersPending first then?

In our application the user mints an item and then when he wants to sell it he lists the item.
That’s why I realized I should have these 3 events. Does that makes sense?

Here is how my beforeSave functions are:

Moralis.Cloud.beforeSave("ItemsPublished", async (request) => {

  const query = new Moralis.Query("EthNFTOwners");

  query.equalTo("token_id", request.object.get("uid"));

  query.equalTo("token_address", request.object.get("tokenAddress"));

  query.equalTo("owner_of", request.object.get("from"));

  const object = await query.first({ useMasterKey: true });

  logger.info(`OBJECT -> ${JSON.stringify(object)}`);

  if (object) {

    logger.info(`OBJECT ->>>> ${JSON.stringify(object)}`);

    const owner = object.attributes.owner_of;

    const userQuery = new Moralis.Query(Moralis.User);

    userQuery.equalTo("accounts", owner);

    const userObject = await userQuery.first({ useMasterKey: true });

    if (userObject) {

      logger.info(`SET USER ->>>> ${JSON.stringify(userObject)}`);

      request.object.set("user", userObject);

    }

    request.object.set("token", object);

  }

});
Moralis.Cloud.beforeSave("ItemsForSale", async (request) => {
  const query = new Moralis.Query("EthNFTOwners");
  query.equalTo("token_id", request.object.get("uid"));
  //query.equalTo("token_address", request.object.get("tokenAddress"));
  query.equalTo("owner_of", request.object.get("owner"));

  const object = await query.first({ useMasterKey: true });
  if (object) {
    const owner = object.attributes.owner_of;
    const userQuery = new Moralis.Query(Moralis.User);
    userQuery.equalTo("accounts", owner);

    const userObject = userQuery.first({ useMasterKey: true });
    if (userObject) {
      request.object.set("user", userObject);
    }

    request.object.set("token", object);
  }
});
Moralis.Cloud.beforeSave("SoldItems", async (request) => {
  // Item published
  const queryPublishedItems = new Moralis.Query("ItemsPublished");
  queryPublishedItems.equalTo("uid", request.object.get("uid"));

  const itemPublished = await queryPublishedItems.first();
  if (itemPublished) {
    itemPublished.set("isSold", true);
    itemPublished.set("owner", request.object.get("buyer"));
    await itemPublished.save();
  }

  // Item for sale
  const queryItemsForSale = new Moralis.Query("ItemsForSale");
  queryItemsForSale.equalTo("uid", request.object.get("uid"));

  const item = await queryItemsForSale.first();
  if (item) {
    item.set("isSold", true);
    item.set("owner", request.object.get("buyer"));
    await item.save();
  }

  if (item || itemPublished) {
    request.object.set("item", item);

    const userQuery = new Moralis.Query(Moralis.User);
    userQuery.equalTo("accounts", request.object.get("buyer"));

    const userObject = userQuery.first({ useMasterKey: true });
    if (userObject) {
      request.object.set("user", userObject);
    }
  }
});

when you are on mainnet or testnet, what is in EthNFTOwnersPending will move fast to EthNFTOwners because there are many other transactions made on that chain.

Now, on local devchain you could see a delay when a row is in EthNFTOwnersPending and then moved in EthNFTOwners when another new transaction is made on chain.

1 Like

Would you have any suggestions for my beforeSave functions in this case?

I’m not able to concentrate now to understand all that function, maybe you could query both tables for now

1 Like