The `getBlockByHeight` function of `AptosApi` in the Moralis SDK is not working as expected, with the error [Moralis SDK Core Error]: [C0005] Invalid address provided: [object Object].

The getBlockByHeight function of AptosApi in the Moralis SDK is not working as expected, with the error [Moralis SDK Core Error]: [C0005] Invalid address provided: [object Object].

Reproduction code:

import Moralis from 'moralis';

const API_KEY = process.env.MORALIS_API_KEY;

async function bootstrap() {
  await Moralis.start({
    apiKey: API_KEY,
    logLevel: 'verbose',
  });

  const response = await Moralis.AptosApi.blocks.getBlockByHeight({
    withTransactions: true,
    blockHeight: 134715631,
    network: 'mainnet',
  });

  console.log('response', response);
}

bootstrap();

The main issue seems to be with the blockHeight parameter. When it is set to 134715631 or 134715600, this problem occurs.

Additionally, when withTransactions is set to false, it works fine.

During online documentation debugging, the return is normal.

This is strange, perhaps these two blocks have a peculiar structure?

Full Error:

npx esno ./src/moralis_test.ts
Moralis[core]: Starting all registered modules {
  moduleNames: [
    'evmUtils', 'solUtils',
    'auth',     'api',
    'evmApi',   'solApi',
    'streams'
  ]
}
Moralis[core]: Finished starting all registered modules {
  moduleNames: [
    'evmUtils', 'solUtils',
    'auth',     'api',
    'evmApi',   'solApi',
    'streams'
  ]
}
Moralis[core]: [RequestController] request started { url: '/blocks/134715631', method: 'get', body: undefined }
 <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:265
            throw new commonCore.CoreError({
                  ^

MoralisError [Moralis SDK Core Error]: [C0005] Invalid address provided: [object Object]
    at AptosAddress.parse ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:265:19)
    at AptosAddress.create ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:253:46)
    ... 6 lines matching cause stack trace ...
    at Array.map (<anonymous>)
    at AptosBlock.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:5779:65) {
  isMoralisError: true,
  code: 'C0005',
  details: undefined,
  [cause]: TypeError: address.noPrefix is not a function
      at AccountAddress.isValid ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:221:21)
      at AptosAddress.parse ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:260:33)
      at AptosAddress.create ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:253:46)
      at AptosAddress.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:256:29)
      at AptosMultiAgentSignatureRequest.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:3494:34)
      at AptosUserTransactionSignature.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:4189:52)
      at AptosUserTransaction.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:4305:54)
      at AptosBlockTransactionsItem.fromJSON ( <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:5721:41)
      at  <local path>/node_modules/@moralisweb3/common-aptos-utils/lib/cjs/index.cjs:5779:121
      at Array.map (<anonymous>)
}

Node.js v20.8.0

Hi @wearzdk

Thanks for the report. I will pass it to the devs.

Meanwhile can you try using the REST API directly? Since the error is only from the js sdk the API endpoint should work as expected.