[Solved] React-moralis, function useMoralisQuery, searching item by owner's address

I’m trying to query the item by owner’s address but can’t.

function GamePlay() {
  const { account, isAuthenticated } = useMoralis();
  const { data, error, isLoading } = useMoralisQuery("Game", (query) => query.equalTo("owner", String(account)), [], { live: true });

  if (!isAuthenticated || !account) {
    return (
        <h1>login first</h1>

  return (
    /// component here
    </div >

both String(account) and account don’t work.
It will work only using “0x…abc” instead of String(account).
Does it has a way to use account as params?
and it doesn’t work on the first load.

Hi @wk1319,

You could try something in the lines of this:

  const { account, isAuthenticated, Moralis } = useMoralis();
  const { data, error, isLoading } = useMoralisQuery("Game");

  useEffect(() => {
    if(account && account !== null){
      let playerDetails = JSON.parse(JSON.stringify((data))).find(
        (response) =>
          response.owner === String(account)

Also when storing the owner addresses in the Moralis database, remember to save them to lowercase as the account variable has the addresses formated in all lowercase.

1 Like

TT. didn’t work. const { account, isAuthenticated } = useMoralis();
account returns all lowercase and using as string too(I guess).
my goal is to create items for users by store it in database on moralis. Are there another way should I do?

if you hardcode a variable account_str with that “0x…abc” and then you use account_str then it works?

1 Like


did you use console.log(account) to see what it is there?

1 Like

yep, I see address as lowercase and type ‘string’.
thanks all of you. I solved this by wrap it and use prop changes it works for now.

1 Like