tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
431 stars 272 forks source link

Invalid type for block.transactions #522

Closed sharifzadesina closed 2 months ago

sharifzadesina commented 4 months ago

When a block doesn't have any transactions, block.transaction property won't be present and it will be undefined.

but the type for block.transaction is an array TronTransaction<ContractParamter>[] it should be TronTransaction<ContractParamter>[] | undefined or make it return an empty array.

This is a simple code that retrives an empty block:

import { AxiosHeaders } from "axios";
import { TronWeb } from "tronweb";

const tw = new TronWeb({
  fullHost: 'https://api.shasta.trongrid.io',
  headers: new AxiosHeaders({ 'TRON-PRO-API-KEY': 'x-x-x-x-x' })
});

// const block = await tw.trx.getBlock(44711520); // empty block
const block = await tw.trx.getBlock(33273991); // non-empty block

console.log(block);
start940315 commented 4 months ago

Thanks for your issue. We'll fix it in our next version.

start940315 commented 2 months ago

We just published TronWeb@v6.0.0-beta.4 which fixed this issue. Welcome to try:

npm install tronweb@beta