Ok, so how’s this work? getTokenTransfers() is obviously not a

convienience function.
import { useEffect, useState } from "react";
import { useMoralis } from "react-moralis";

const emptyList = [];

export const useTokenShifts = (props) => {
  const { isAuthenticated, Moralis } = useMoralis();
  const [Txs, setTxs] = useState(emptyList);
  const [isLoading, setIsLoading] = useState(true);

  console.log("Loaded isAuthenticated: ", isAuthenticated);
  console.log("Received token name: ");

  useEffect(() => {
    if (isAuthenticated) {
      console.debug("Calling getTransactions...");
      Moralis.Web3.getTokenTransfers({ usePost: true }).then((userTrans) => {
        console.debug("All ERC20 transaction data: ", userTrans);
    } else {
  }, [Moralis, Moralis.Web3, isAuthenticated]);

  console.debug("Returning transactions: ", Txs);

  return { Txs, isLoading };

It must be an “inconvienience” function? Is TokenTransfers available as a server call? How do I go about calling it from my ReactJS front-end? Do I need to wrap my own server function around it? Any quick n’ easy examples you can point me to?

Please advise. Thanks!

The docs link above references one of the default installed plugins that syncs historical data for authenticated users and watched addresses. It has has no public API. The docs then go on to talk about the schema for the collections it creates. These are the collections (tables) you see in the Moralis Dashboard like EthTokenTransfers.

  • These collections can be queried directly using Moralis.Query (see Queries)
  • You can use the Convenience Functions like Moralis.Web3.getALLERC20() for token balances (see Token Balances). The Moralis.Web3.getTransactions() function will get the regular transactions not the token transfer events.
  • You can use the Deep Index REST API like /historical/token/erc20/transactions. See the Swagger docs on your Moralis Server and the getting started docs for using the API

There is a hook in react-moralis for calling Cloud Functions. All of the Convenience Functions are Cloud Functions with the same name under the hood and can be called as such using that hook.

A custom hook can be used for making API calls. Or you can use something like React Query

1 Like

Cool! Thanks for the context! I’ll begin experimenting with server functions…