[SOLVED] Cloud function to find user's username by searching their ethAddress

I’m attempting to search my db for a specific user by their eth address. I ultimately want to feed the cloud function a specific eth address, and have it return the user’s username, bio, etc. I’m storing all of the user’s info in the User class, including their eth addresses.

My code below. I’ve supplied a (fake) eth address in params, which I know exists in my User table. The cloud function only returns the objectId for the user, but nothing else. How can I have the cloud function return all attributes of the user, or maybe specific attributes like username or bio?

From my index.js file:

  const params = {ethAddress: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"}
  const { data, error, isLoading } = useMoralisCloudFunction("getSellerInfo", params);

My cloud function:

Moralis.Cloud.define("getSellerInfo", async (request) => {
    const query = new Moralis.Query("User");
    query.equalTo("ethAddress", request.params.ethAddress)
    const results = await query.find({useMasterKey:true});
    return results;

You have all the user information in the object attributes, you have to click on attributes to see all the info. Or you can use console.log(JSON.stringify(results)) to see all the info.

1 Like

Ah! There it is. Perfect. Thanks for your help!