question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getBlock & getBlockNumber produce odd results

See original GitHub issue

I’ve got a loom test chain running on AWS (single node).

I can see it and make http calls to it at: http://52.88.113.238:46658/rpc.

Contracts are deployed on it, and I can change their state, but, I can’t see it in the loom block explorer (separate issue, maybe). I can put the block explorer address into a browser and read the json, though.

What’s most odd is that the block height doesn’t seem to match reality. I see web3.eth.getBlockNumber() returning 2.2million, and both the block explorer json and the web3.eth.getBlock(‘latest’) giving 210k (210k is correct; it’s been running over the w/e Also, getBlock doesn’t seem to return a proper “Block” obect - it has blockNumber, but no number

Further, the returned data from web3.eth.getBlock() is wrong; I get the following, not a proper Block object: {"blockNumber":"0x34fa2","transactionHash":"0xdee07e7f845caf52c76c0a30e762a03214455ee2","parentHash":"0x625965193b355527ed51550023694249768d091e","logsBloom":"0x","timestamp":1534198065,"transactions":[]} The data does appear to be correct, just formatted incorrectly.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
paulbarclaycommented, Aug 14, 2018

More oddness with getBlock: If you try a numerical getBlock in a block with a transaction, the getBlock fails with a BigNumber error (Something’s undefined).

On that same server, the following calls might work or not: loomWeb3.eth.getBlock(217777) > success loomWeb3.eth.getBlock(217778) > fails loomWeb3.eth.getBlock(217779) > success

Error log (we’ve added logging into loom_provider, so line numbers might not match):

Error: Error: [number-to-bn] while converting number undefined to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported. Given value: "undefined"
server_1  | [worker]     at Object.toBN (/srv/server/node_modules/web3-utils/src/utils.js:64:15)
server_1  | [worker]     at outputBigNumberFormatter (/srv/server/node_modules/web3-core-helpers/src/formatters.js:39:18)
server_1  | [worker]     at outputTransactionFormatter (/srv/server/node_modules/web3-core-helpers/src/formatters.js:176:19)
server_1  | [worker]     at /srv/server/node_modules/web3-core-helpers/src/formatters.js:251:24
server_1  | [worker]     at Array.forEach (<anonymous>)
server_1  | [worker]     at Method.outputBlockFormatter [as outputFormatter] (/srv/server/node_modules/web3-core-helpers/src/formatters.js:249:28)
server_1  | [worker]     at Method.formatOutput (/srv/server/node_modules/web3-core-method/src/index.js:163:54)
server_1  | [worker]     at sendTxCallback (/srv/server/node_modules/web3-core-method/src/index.js:476:33)
server_1  | [worker]     at /srv/server/node_modules/web3-core-requestmanager/src/index.js:147:9
server_1  | [worker]     at LoomProvider.<anonymous> (/srv/server/node_modules/loom-js/dist/loom-provider.js:250:25)
server_1  | [worker]     at step (/srv/server/node_modules/loom-js/dist/loom-provider.js:32:23)
server_1  | [worker]     at Object.f [as next] (/srv/server/node_modules/loom-js/dist/loom-provider.js:13:53)
server_1  | [worker]     at fulfilled (/srv/server/node_modules/loom-js/dist/loom-provider.js:4:58)
server_1  | [worker]     at <anonymous>
server_1  | [worker]     at process._tickCallback (internal/process/next_tick.js:188:7)

1reaction
eduardonunespcommented, Aug 13, 2018

Thanks @paulbarclay we’ll going to check

Read more comments on GitHub >

github_iconTop Results From Across the Web

getBlock - Alchemy Docs
Returns identity and transaction information about a confirmed block in the ledger.
Read more >
How can I get the data of the latest 10 blocks via web3.js?
There are a few issues with the accepted answer: as @Lam-Le mentions, .getBlock() and .getBlockNumber() are both asynchronous so if a new ...
Read more >
Bitcoin (BTC) Fails to Produce Block in 85 Minutes | GetBlock.io
Bitcoin (BTC) Fails to Produce Block in 85 Minutes. Bitcoin (BTC), a largest blockchain, registers an unusual event: 13,000 stuck in mempool.
Read more >
web3.eth — web3.js 1.0.0 documentation
Number - The transaction's index position. Function - (optional) Optional callback, returns an error object as first parameter and the result as second....
Read more >
Documentation - Ethers.js
Get the block from the network, where the result.transactions is a list of transaction hashes. await provider.getBlock(100004) // { // _difficulty: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found