Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

getBlock() returns difficulty null #3136

Closed
ayushch80 opened this issue Jul 4, 2022 · 9 comments
Closed

getBlock() returns difficulty null #3136

ayushch80 opened this issue Jul 4, 2022 · 9 comments
Assignees

Comments

@ayushch80
Copy link

Ethers Version

5.2

Search Terms

Blocks Methods, Providers

Describe the Problem

getBlock() and getBlockWithTransactions() are returning difficulty : null but if I tried same code snippet from your documentation https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlock it returns correct difficulty: 3849295379889

Code Snippet

await provider.getBlock(15077324)

Contract ABI

No response

Errors

No response

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), Browser (Chrome, Safari, etc)

Environment (Other)

No response

@ayushch80 ayushch80 added the investigate Under investigation and may be a bug. label Jul 4, 2022
@BlackBoxEngineering
Copy link

The example in the documentation is correct for the following block on chain 1

await provider.getBlock(100004)
// _difficulty: { BigNumber: "3849295379889" },
// difficulty: 3849295379889,

image

@BlackBoxEngineering
Copy link

BlackBoxEngineering commented Jul 5, 2022

getBlock() Fine too bud.

async function f_lookupGetBlockDiff( _blockno ){
    provider = new ethers.providers.Web3Provider( window.ethereum );
    const blockNo = await provider.getBlock( _blockno );
    return blockNo.difficulty;
}
f_lookupGetBlockDiff(100004);

@ayushch80
Copy link
Author

image

image

@ayushch80
Copy link
Author

The example in the documentation is correct for the following block on chain 1

await provider.getBlock(100004) // _difficulty: { BigNumber: "3849295379889" }, // difficulty: 3849295379889,

image

it's not about example in docs
I tried some other valid block numbers

@BlackBoxEngineering
Copy link

BlackBoxEngineering commented Jul 5, 2022

Sorry, I understand now you have shown another example:

I too am receiving null for that block (15077324), and can see it has a large difficulty 11,849,458,542,468,467 in eth explorer

I did try your block number again and it returns a difficultly no problem. I checked 15077300 too 15077400 and got all the difficulties returned
image

Can you check that block number again 15077324 ?

@BlackBoxEngineering
Copy link

Has this suddenly and magically been fixed, because I did also return a null like ayushch80 for 15077324 originally :octocat:

@ayushch80
Copy link
Author

ayushch80 commented Jul 5, 2022

@Ancientzero
I tried again but didn't got any
Can you pls share the piece of code you tried

@ayushch80
Copy link
Author

i made some calculations and found that we are getting difficulty : null after block number 13199441

@ricmoo
Copy link
Member

ricmoo commented Jul 5, 2022

The difficulty is a number in JavaScript, which means that once the difficulty exceeded 53 bits, it becomes null. The _difficulty is a BigNumber which allows for arbitrary values, and for applications that require access to difficulty, that property should be used.

In v6, difficulty is a BigInt.

See #2036 for more details.

Make sense?

@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Jul 5, 2022
@ethers-io ethers-io locked and limited conversation to collaborators Jul 5, 2022
@ricmoo ricmoo converted this issue into discussion #3142 Jul 5, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants