Do something when specific contract address transfers to another address

I want to make it so that I run something when there a new transaction appears in a specific contract address. What would I need to use in this case?

you can sync all the transfers for a specific address in your Moralis Server db and you an user a hook like beforeSave to run specific code when a new transaction is added there

I tried that and I used the code from the doc and changed it a bit which was


Moralis.Cloud.beforeSave("Transfers", (request) => {
  const from = request.object.get("from");

const to = request.object.get("to");

    request.object.set("fromusername", //data from User table);
  
});

I want to get data from another class such as User.

In the User class, I have a column for username and their wallet address.

Sorry if my explanation might’ve been confusing

what is the problem that you have with that code?

I want to set the usernamefrom value to the username from the User class

ok, you can do that, how do you identify that User?

Using the “from address” from the transfer class

There is a username column in the User class

ok, you can do a query in user class, you will have to use master key

Would I put the query in the cloud function?

Also, would I limit the query to 1 to get the latest one?

you can use .first, probably you will get only a result or no result, you will have to put that query in a cloud function so what you can use master key

What would I need to do if I want to get the attribute of an NFT from the PolygonNFTOwners class using the from address from Transfers class?

you can read more about how to write queries here: https://docs.moralis.io/moralis-server/database/queries

I have my NFT metadata stored inside the token_uri so I have to use fetch to get the attribute of the NFT. However it says that the cloud function cannot require fetch because it is not a whitelisted module.

you can use this in a cloud function: https://docs.moralis.io/moralis-server/cloud-code/httprequest