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

getTransaction breaks trying to access blockNumber of null response #2375

Closed
mateuspiresl opened this issue Feb 13, 2019 · 5 comments · Fixed by #2389
Closed

getTransaction breaks trying to access blockNumber of null response #2375

mateuspiresl opened this issue Feb 13, 2019 · 5 comments · Fixed by #2389
Labels
Bug Addressing a bug

Comments

@mateuspiresl
Copy link

mateuspiresl commented Feb 13, 2019

Expected behavior

The method getTransaction should return null or error for specifying a non-existent transaction.

Actual behavior

The method getTransaction breaks trying to access blockNumber of null response.

Steps to reproduce the behavior

  1. Connect to the main network (I used the Infura provider to do so);
  2. Call getTransaction with a transaction hash that does not exist, like 0x6b39f5caf5907ae686ac42f91527ab6897047027ce688f35b9e28ec4a21e8667, which is an existent transaction hash from the Rinkeby network.
this.web3.eth.getTransaction(transactionHash).catch(console.log);

Error Logs

TypeError: Cannot read property 'blockNumber' of null
      at Object.outputTransactionFormatter (node_modules/web3-core-helpers/dist/web3-core-helpers.cjs.js:91:14)
      at GetTransactionMethod.afterExecution (node_modules/web3-core-method/dist/web3-core-method.cjs.js:961:30)
      at GetTransactionMethod._callee$ (node_modules/web3-core-method/dist/web3-core-method.cjs.js:457:39)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at GeneratorFunctionPrototype.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
      at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
      at process._tickCallback (internal/process/next_tick.js:109:7)

Versions

NPM: v6.15.1
Node: v10.15.1
Web3.js: 1.0.0-beta.46 (latest)
OS: Ubuntu 16.04

@mateuspiresl
Copy link
Author

This issue seems to be related but happens for sendTransaction. This one is for getTransaction alone.

@OFRBG
Copy link

OFRBG commented Feb 13, 2019

Yup, you're right. The afterExecution processing is also missing the undefined return case. Guilty lines below.

https://github.com/ethereum/web3.js/blob/35ebbcacbecc75a6cac033fc648d0091e0235a83/packages/web3-core-method/src/methods/transaction/GetTransactionMethod.js#L45-L47

@nivida nivida added the Bug Addressing a bug label Feb 18, 2019
@nivida
Copy link
Contributor

nivida commented Feb 18, 2019

Thanks for submitting this issue! I will fix and release it asap.

@oleiba
Copy link

oleiba commented Apr 11, 2019

This still happens on "1.0.0-beta.52"...
Reproduce:

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws'));

const batch = new web3.BatchRequest();
batch.add(web3.eth.getTransaction.request('0x223b3f5892a7c20c333b68c4e95729100e7143a8c4ca8134502c3f0a2a87aadd', function (err, res) {
    console.log(err);
}));
batch.execute();
// TypeError: Cannot read property 'blockNumber' of null
// ...

@romanbolshakov
Copy link

romanbolshakov commented Aug 23, 2019

Can be wrong, but looks like still happens on '1.2.1'.
Or tell me please where is my mistake...
Reproduce (via subscribe for pendingTransactions):

web3.eth.subscribe('pendingTransactions')
    .on("data", async (txHash) => {
      try {
        let transaction = await web3http.eth.getTransaction(txHash);
        console.log(transaction.from);
      } catch (err) {
        console.log(err.message);
      }
    })```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants