[SOLVED] getTransaction, with date option

Hey,

I’m looking for a way to get transactions for a certain date.
Unfortunately we don’t have this option:
const transactions = await Moralis.Web3API.account.getTransactions(options);

Options:

  • chain(optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value Eth.

  • address (optional): A user address (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead.

  • to_block (optional): The block number on which the balances should be checked.

  • address (required): The address for which the native balance will be checked.

Guess we can do it this way, for each transaction t:
new Date(t.block_timestamp)
get the date with block_timestamp.
Save them.
Then look for transactions through saved dates.

Just asking if there is a better way?

If these are transactions for your users, then the transactions should be synced in your database with block_timestamp column too, if these are any transactions list that you want to process, then I don’t know a better way.

I have indeed the column block_timestamp column in the database with the transactions.
How can I request directly the list of transaction for a certain date (ex: 25/09/2021) from the database?

How can I adapt this to get transactions for block_timestamp = 25/09/2021 ?
Did you mean from cloud function, something like this?

Moralis.Cloud.define("getDateTransaction", async(request, date) => {

  const {userAddress} = request.params;
  if (!userAddress){
    return [];
  }

  const transactionQuery = new Moralis.Query("EthTransactions");
  transactionQuery.equalTo("address", userAddress);
  transactionQuery.equalTo("block_timestamp", date);
  const transactionResult = await tokenQuery.find();
  return transactionResult;

});

I think that is possible to do something similar with what you are trying there, but I would use greater than and lower than a particular date in order to get the transactions for a particular time interval.

1 Like

Works like a charm! Thanks CK. Now that I also get better how queries work, looks like I’ll be having fun. :smirk:

1 Like