[solved] getDateToBlock only gives me undefined

Hi everyone, I am trying to use the getDateToBlock method of the Moralis SDK as described here:

However, no matter what values I pass in (chain: β€œeth” / β€œ1” / β€œ0x1”, date: β€œ2023-03-15T10:00:00+00:00” / UNIX timestamp as int or as string) the only response I get is β€˜undefined’. I copy pasted the code from the above page in my Nodejs code.

Any help appreciated.

Best, Tom

try to test it in docs interface directly:

like click on try it button there to see the results

It works in the docs interface, but it doesn’t work in the SDK

That is the code that you use in the sdk? What version of the sdk you are using?

In the SDK I use the exact same code of the docs interface. I am on SDK version 2.14.3

can you paste the code here?

import Moralis from 'moralis';

try {
  await Moralis.start({
    apiKey: "XXX"
  });

  const response = Moralis.EvmApi.block.getDateToBlock({
    "chain": "1",
    "date": "2023-03-15T10:00:00+00:00"
  });

  console.log(response.raw);
} catch (e) {
  console.error(e);
}

I had to make some changes to make it work:

Moralis = require("moralis").default

r = async () => {
  await Moralis.start({
    apiKey: "API_KEY_HERE"
  });

  const response = await Moralis.EvmApi.block.getDateToBlock({
    "chain": "1",
    "date": "2023-03-15T10:00:00+00:00"
  });

  console.log(response.raw);
}

r()

it looks like it is missing an await for Moralis.EvmAPI.block.getDateToBlock

Yes, works now for me as well. Thank you!

2 Likes