Skip to content
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

beta51 return broken BigNumber from contract methods #2603

Closed
vshab opened this issue Mar 28, 2019 · 3 comments
Closed

beta51 return broken BigNumber from contract methods #2603

vshab opened this issue Mar 28, 2019 · 3 comments
Labels
2.x 2.0 related issues Enhancement Includes improvements or optimizations On Ice Important but no longer pursued for the near future Stale Has not received enough activity

Comments

@vshab
Copy link

vshab commented Mar 28, 2019

Description

It is said that

Instead of transforming numbers to string values do we return now the BigNumber object we get from the AbiCoder.

Seems like these BigNumber come from ethers.js which enwraps BN's making it impossible to operate them in conjuncture with pure BN.

import BN from 'bn.js';

// ...

const value = await myContract.methods.method.call();
const half = value.div(new BN(2)); //  <-- Throws here 

Expected behavior

Code above works

Actual behavior

The error is Error: invalid BigNumber value (arg="value", value="2", version=4.0.27)

Versions

  • web3.js: 1.0.0-beta.51
  • browser: Chrome 71
  • ethereum node: Rinkeby
@nivida
Copy link
Contributor

nivida commented Mar 28, 2019

This is because the AbiCoder of ethers.js is returning his own BigNumber implementation.
The real solution would be if ethers.js and web3.js are moving to BigInt which is already implemented in chrome and as an experimental feature in Firefox. There is also a polyfill from google called JSBI.

I would really like to switch to BigInt and the JSBI polyfill.

I will talk to Richard from ethers.js if we can find a solution for both libraries which is also future proof.

Edit:
I've also proposed the idea of using JSBI/BigInt here: ethereumjs/fixed-bn.js#9

@nivida nivida added Enhancement Includes improvements or optimizations On Ice Important but no longer pursued for the near future labels Mar 28, 2019
@vshab
Copy link
Author

vshab commented Mar 28, 2019

The solution would be to move to the same BigNumber package ethers.js using.

In my opinion it's not the best solution - exporting some internal types. Then there should be some kind of typing for them, documentation and the way to instantiate in user code.

But I would personally like to switch to BigInt and the JSBI polyfill.

That's a good idea i think 👍

@nivida nivida added the 2.x 2.0 related issues label Jun 20, 2019
@github-actions
Copy link

github-actions bot commented Jul 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x 2.0 related issues Enhancement Includes improvements or optimizations On Ice Important but no longer pursued for the near future Stale Has not received enough activity
Projects
None yet
Development

No branches or pull requests

2 participants