Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'getBlockWithTransactions' does not include 'size' in its response #471

Open
edyionescu opened this issue Nov 13, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@edyionescu
Copy link

Environment

  • Node.js version: 22.11.0
  • Alchemy SDK version: 3.4.8

The problem

getBlockWithTransactions does not include size in its response as mentioned in the docs. It is listed in the response object parameters, but does not appear in the example response.

How to reproduce:

import { Alchemy, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

console.log((await alchemy.core.getBlockWithTransactions(21179399)).size);
// undefined

The size is present in the JSON-RPC response of eth_getBlockByNumber. Here is the sandbox link for the same block.

@edyionescu edyionescu added the bug Something isn't working label Nov 13, 2024
@edyionescu
Copy link
Author

edyionescu commented Nov 13, 2024

Given that the core Alchemy method getBlockWithTransactions calls the Ethers.js provider method of the same name and this does not return the size, the docs should be updated and have the parameter removed from the response object.

For now, the alternative is to use the JSON-RPC call of eth_getBlockByNumber:

import { Alchemy, Utils, Network } from 'alchemy-sdk';

const alchemy = new Alchemy({
  apiKey: ALCHEMY_API_KEY,
  network: Network.ETH_MAINNET,
});

const ethersProvider = await alchemy.config.getProvider();
const block = await ethersProvider.send(
  'eth_getBlockByNumber',
  [
    Utils.hexValue(21179399),
    true
  ]
);

console.log(Number(block.size)); 
// 32548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant