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.

Error provider.getBlock in ethers v5, working in v4

See original GitHub issue

Getting error in ethers 5.0 while it works in 4.0,

ethers.version
"ethers/5.0.0-beta.169"

provider = ethers.getDefaultProvider('kovan')
FallbackProvider {_isProvider: true, formatter: Formatter, _network: {…}, ready: Promise, _maxInternalBlockNumber: -1024, …}

await provider.getBlock(16265864);
ethers.umd.js:4555 Uncaught (in promise) TypeError: Cannot read property '_hex' of null TypeError: Cannot read property '_hex' of null
    at Function.BigNumber.from (ethers.umd.js:4554)
    at Formatter.difficulty (ethers.umd.js:20091)
    at Function.Formatter.check (ethers.umd.js:20270)
    at Formatter._block (ethers.umd.js:20113)
    at Formatter.block (ethers.umd.js:20117)
    at FallbackProvider.<anonymous> (ethers.umd.js:21716)
    at step (ethers.umd.js:20481)
    at Object.next (ethers.umd.js:20412)
    at fulfilled (ethers.umd.js:20366)
BigNumber.from @ ethers.umd.js:4554
Formatter.difficulty @ ethers.umd.js:20091
Formatter.check @ ethers.umd.js:20270
Formatter._block @ ethers.umd.js:20113
Formatter.block @ ethers.umd.js:20117
(anonymous) @ ethers.umd.js:21716
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
load (async)
(anonymous) @ ethers.umd.js:18879
fileReaderReady @ ethers.umd.js:18878
readBlobAsText @ ethers.umd.js:18898
Body.text @ ethers.umd.js:18997
(anonymous) @ ethers.umd.js:19661
step @ ethers.umd.js:19456
(anonymous) @ ethers.umd.js:19387
fulfilled @ ethers.umd.js:19341
Promise.then (async)
step @ ethers.umd.js:19356
(anonymous) @ ethers.umd.js:19359
__awaiter @ ethers.umd.js:19338
(anonymous) @ ethers.umd.js:19623
fetchJson @ ethers.umd.js:19740
JsonRpcProvider.send @ ethers.umd.js:22963
JsonRpcProvider.perform @ ethers.umd.js:23019
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
getRunner @ ethers.umd.js:24625
_loop_2 @ ethers.umd.js:24790
(anonymous) @ ethers.umd.js:24842
step @ ethers.umd.js:24336
(anonymous) @ ethers.umd.js:24267
step @ ethers.umd.js:24275
(anonymous) @ ethers.umd.js:24267
(anonymous) @ ethers.umd.js:24239
__awaiter @ ethers.umd.js:24218
FallbackProvider.perform @ ethers.umd.js:24728
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
(anonymous) @ VM13701:1
(anonymous) @ VM13701:2
ethers.umd.js:4554 Uncaught (in promise) TypeError: Cannot read property '_hex' of null
    at Function.BigNumber.from (ethers.umd.js:4554)
    at Formatter.difficulty (ethers.umd.js:20091)
    at Function.Formatter.check (ethers.umd.js:20270)
    at Formatter._block (ethers.umd.js:20113)
    at Formatter.block (ethers.umd.js:20117)
    at FallbackProvider.<anonymous> (ethers.umd.js:21716)
    at step (ethers.umd.js:20481)
    at Object.next (ethers.umd.js:20412)
    at fulfilled (ethers.umd.js:20366)
BigNumber.from @ ethers.umd.js:4554
Formatter.difficulty @ ethers.umd.js:20091
Formatter.check @ ethers.umd.js:20270
Formatter._block @ ethers.umd.js:20113
Formatter.block @ ethers.umd.js:20117
(anonymous) @ ethers.umd.js:21716
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
load (async)
(anonymous) @ ethers.umd.js:18879
fileReaderReady @ ethers.umd.js:18878
readBlobAsText @ ethers.umd.js:18898
Body.text @ ethers.umd.js:18997
(anonymous) @ ethers.umd.js:19661
step @ ethers.umd.js:19456
(anonymous) @ ethers.umd.js:19387
fulfilled @ ethers.umd.js:19341
Promise.then (async)
step @ ethers.umd.js:19356
(anonymous) @ ethers.umd.js:19359
__awaiter @ ethers.umd.js:19338
(anonymous) @ ethers.umd.js:19623
fetchJson @ ethers.umd.js:19740
JsonRpcProvider.send @ ethers.umd.js:22963
JsonRpcProvider.perform @ ethers.umd.js:23019
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
getRunner @ ethers.umd.js:24625
_loop_2 @ ethers.umd.js:24790
(anonymous) @ ethers.umd.js:24842
step @ ethers.umd.js:24336
(anonymous) @ ethers.umd.js:24267
step @ ethers.umd.js:24275
(anonymous) @ ethers.umd.js:24267
(anonymous) @ ethers.umd.js:24239
__awaiter @ ethers.umd.js:24218
FallbackProvider.perform @ ethers.umd.js:24728
(anonymous) @ ethers.umd.js:21625
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
lib$l.poll.onceBlock @ ethers.umd.js:21618
check @ ethers.umd.js:19796
(anonymous) @ ethers.umd.js:19836
poll @ ethers.umd.js:19766
(anonymous) @ ethers.umd.js:21617
step @ ethers.umd.js:20481
(anonymous) @ ethers.umd.js:20412
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
fulfilled @ ethers.umd.js:20366
Promise.then (async)
step @ ethers.umd.js:20381
(anonymous) @ ethers.umd.js:20384
__awaiter @ ethers.umd.js:20363
BaseProvider._getBlock @ ethers.umd.js:21548
BaseProvider.getBlock @ ethers.umd.js:21729
(anonymous) @ VM13701:1
(anonymous) @ VM13701:2

Tried it for homestead seems to be working for that.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ricmoocommented, Jan 22, 2020

This should be fixed now in the npm version, 5.0.0-beta.170. Please give it a go and let me know if you still have issues. 😃

1reaction
zemsecommented, Jan 21, 2020

Okay, this was pretty quick response 😛

Read more comments on GitHub >

github_iconTop Results From Across the Web

Provider - Ethers.js
Returns the contract code of address as of the blockTag block height. If there is no contract currently deployed, the result is 0x...
Read more >
Documentation - ethers
Get the block from the network, where the result.transactions is a list of transaction hashes. await provider.getBlock(100004) // { // _difficulty: { BigNumber: ......
Read more >
ethers-io - Bountysource
I am struggling to get ethers.js to work with rollup. The specific error that I am encountering in browser is: Uncaught SyntaxError: The...
Read more >
I am getting a transaction was replaced error in ether js while ...
I want to input something in my database when something modifies on a blockchain.So I am using this for the check const receipt...
Read more >
deploy contract with ether.js - Ethereum Stack Exchange
You can deploy a contract using Ethers.js' ContractFactory . ... Here I have used 'getblock' as web3 provider for example (see ...
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