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

React Dev/Build Web3@1.0.0-beta.50 BigNumber support mismatch #2562

Closed
dillonsvincent opened this issue Mar 24, 2019 · 1 comment
Closed
Labels
Bug Addressing a bug

Comments

@dillonsvincent
Copy link

Description

When using Web3@1.0.00-beta.50 in a React Web development environment contract type uints are returned from infura and parsed into js ints. When creating a build of the React project and running it on the server numbers are being parsed into BigNumber objects. The jsonrpc response is the same for both local dev and production server.

Local Host React Dev Behavior

Network response:
{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000001"}

       contract.methods.GetLength().call().then((res)=>{
          console.log('Length result',res);
         // Length result 1
        },(err)=>{
        });

Production React Build Behavior

Network response:
{"jsonrpc":"2.0","id":1,"result":"0x0000000000000000000000000000000000000000000000000000000000000001"}

       contract.methods.GetLength().call().then((res)=>{
          console.log('Length result',res);
         // Length result e {_hex: "0x01", _ethersType: "BigNumber"}
        },(err)=>{
        });

Steps to reproduce the behavior

1. Import web3
2. Set the provider to infura/v3
3. Create contract instance
4. Call method that returns a uint solidity type
5. Run npm start on local machine
6. Run npm build
7. Compare the result of the promise callback between the two

  import Web3React from 'web3';
       var web3react = new Web3React("https://rinkeby.infura.io/v3/key");
       var contract = new web3react.eth.Contract(_abi, _addr);
        contract.methods.GetLength().call().then((res)=>{
          console.log('Length result',res);
        },(err)=>{
        });

Versions

  • web3.js: web3@1.0.0-beta.50
  • nodejs:
  • browser: Chrome
  • ethereum node:
@nivida nivida added the Bug Addressing a bug label Mar 25, 2019
@nivida
Copy link
Contributor

nivida commented Mar 25, 2019

I've checked it closer and it should return a BigNumber object instead of the string. I've created an issue for it. It should return a BigNumber object because JS can't handle the returned numbers from the node. The BigNumber objects give you also some additional features you can work with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

2 participants