React Dev/Build [email protected] BigNumber support mismatch
Description
When using [email protected] 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: [email protected]
- nodejs:
- browser: Chrome
- ethereum node:
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.