Track NFT-Sales on Opensea

Hey,

Iā€™d like to track NFT-Sales on Opensea (in real-time if thats possible). I am new to blockchain development and having a hard time to get my head around whats happening here. As far as I know:

On Opensea once an offer is accepted the atomicMatch_ function gets called which as 2-3 internal transactions. Those vary depending on the NFT-Contract (at least I think so) - the only constant here is OrderMatched (from the Opensea Contract).

So I am listening to (sync) the OrderMatched Topic on the Opensea Contract. The catch here is that there is not actual reference to the NFT-Collection-Contract or token.

So my questions are:
1.) How do I monitor token transfers for a given Contract and store them into a Table/Class? I tried to add it to WatchedEthAddress but the data doesnā€™t show up in EthTokenTransfers as I would have hoped.
2) What would be the best approach to combine the OrdersMatched events with the actual Token-Info

Plus one bonus question: I do have an afterSave trigger on the OrderMatched event like so:

Moralis.Cloud.afterSave('OpenseaOrdersMatched', async (request) => {
  const confirmed = request.object.get('confirmed')
  if (!confirmed) {
    return
  }

  const ntfTransaction = {
    hash: request.object.get('transaction_hash'),
    maker: request.object.get('maker'),
    taker: request.object.get('taker'),
    price: request.object.get('price'),
    block_number: request.object.get('block_number'),
    confirmed,
    updatedAt: request.object.get('updatedAt'),
  }

  log.info('>' + JSON.stringify(ntfTransaction))

  const nftTx = await new NFTTx(ntfTransaction)
  nftTx.save()
})

And there are quiet a few records inserted every second - however the NFTTx Table has only a fraction of the OpenseaOrdersMatched records. Shouldnā€™t those numbers be the same?

did you try to sync and watch events?
https://docs.moralis.io/moralis-server/automatic-transaction-sync/smart-contract-events#sync-and-watch-contract-events

for last question, what do you see in logs for that log.info? (shouldnā€™t be logger.info?) as in do you see a lot of number of lines or only that fraction of records

you could also try to add more logging to see why the numbers are not equal.

Thanks for your reply! :pray:t2:

At the moment I am syncing only the Opensea Contract. The NFT-Collection-Contracts are somewhat random. I donā€™t want to manually insert every contract via the Admin-Dashboard. Is there a way to add contract-sync programmatically? Similar to ā€œwatchEthAddressā€?

As for the last q:
My Moralis.Cloud.logger is called log - so thats fine. It is really hard to debug since thereā€™s so much traffic. I cleared both tables and watched for a couple of seconds there were 2.07k events in OpenseaOrdersMatched but only 66 got stored into the NFTtx Table. Could have something to do with syncing history the whole history of all events - but thats an issue for another day :smiley: I would like to get the other roadblocks out of the way first.

there is a way with moralis-admin-cli, not super easy, and it also requires a restart to server (the restart is handled automatically by moralis-admin-cli): https://docs.moralis.io/moralis-server/tools/moralis-admin-cli#add-contract

you could also do it by connecting directly to mongo db, inserting the info for that event and then restarting the server

Would love to know how you solved these issues. Were you able to sync all OrdersMatched events to moralis?