Ethers.js: Error provider.getBlock in ethers v5, working in v4

Created on 21 Jan 2020  路  7Comments  路  Source: ethers-io/ethers.js

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.

bug fixed

All 7 comments

I鈥檒l investigate this immediately once I get to Starbucks for the day. It may be relate to some of the refactoring of the FallbackProvider I鈥檝e been working on... :s

Okay, this was pretty quick response :P

Looks like it is probably PoA related (difficulty is null), I need to figure out why the Kovan tests didn鈥檛 detect this...

Sorry for the delay, I forgot I had prior engagements today, but I'm looking at this now and have reproduced it...

Ok...Found the problem; it had nothing to do with the other changes... Just that time moved forward. :)

The test cases I have from Kovan are from early on when the difficulty was quite low and fit in a 53-bit number. Not that it is over 53-bits, it is no longer fits. The ethers API specifies that difficulty over 53-bits gets converted to null (this is only relevant for PoA networks, where the difficulty does not have any significant meaning anyways).

So, I've made the parser check for null difficulty before trying to parse it and added your block as a test case to the test suite, so this should be caught before being published next time.

I have 2 or 3 other small things I'm going to look into first, but I should be publishing this to npm within a hour or so and will keep this issue updated.

Thanks for your patience! :)

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. :)

Thank you, it's now working :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crazyrabbitLTC picture crazyrabbitLTC  路  3Comments

jochenonline picture jochenonline  路  3Comments

dave-dm picture dave-dm  路  3Comments

GFJHogue picture GFJHogue  路  3Comments

dagogodboss picture dagogodboss  路  3Comments