Skip to content

fix(hashrate): calculation based on network difficulty - #2

Open
IzioDev wants to merge 1 commit into
imalfect:mainfrom
IzioDev:fix/hashrate
Open

fix(hashrate): calculation based on network difficulty#2
IzioDev wants to merge 1 commit into
imalfect:mainfrom
IzioDev:fix/hashrate

Conversation

@IzioDev

@IzioDev IzioDev commented Jun 26, 2025

Copy link
Copy Markdown

No description provided.

return hashrateData.networkHashesPerSecond;
const hashrateData = await kaspa.getBlockDagInfo({});

const hashRate = hashrateData.difficulty * 2 * 10;

@IzioDev IzioDev Jun 26, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe cast hashrateData.difficulty to BigInt before hand?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value I had: 909161465263109888n (closer to the explorer)

@imalfect

Copy link
Copy Markdown
Owner

gm! sorry for the late reply. The solution checks out, but the result hashrate is bigger than javascript's maximum safe integer so the math could return inaccurate results, matter of fact it seems like the difficulty itself is already bigger than the maximum safe integer, so wasm should return it as a bigint in the first place, and then we can just multiply it by 20n.

I'll check to see if perhaps it was already fixed in a newer WASM release, if not I'll raise and issue and once that's solved we can get this one working all solid 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants