Closed jjhesk closed 3 years ago
Looks like the same in https://github.com/MikeMcl/bignumber.js/issues/290
Try discuss: https://github.com/nuxt/nuxt.js/discussions/9957
This is nothing to do with this library. It is to do with web3.js and ethers.js and your confusion about which BigNumber library is being used.
ethers.js has its own the BigNumber library, and it looks like your problems are caused by mixing the two.
Please stop opening issues or spamming other issues about this and linking here for no good reason.
It has nothing to with web3 and ethers.js I just confirmed. @MikeMcl
Sorry to chip-in on a closed thread, but I notice Ethers has a BigNumber API that is NOT BigNumber.js
. It is based on BN.js, but provides a custom API. See their documentation.
@shuckster BigNumber cannot mixed with BN.js. Thats all I got. But why it would still work if I have BigNumber.js as class BigNumber instance at the first place?
You can monkey patch ethers by using this code
bignumber-monkeypatch.ts
import { BigNumber } from "bignumber.js";
class BigNumberExtended extends BigNumber {
public toHexString(): string {
return `0x${this.toString(16)}`;
}
}
BigNumber.prototype = Object.create(BigNumberExtended.prototype);
BigNumber.prototype.constructor = BigNumber;
and then importing it in your hardhat.config.ts with the following line
import "./lib/bignumber-monkeypatch";
version: 9.0.1 web3.js: 1.6.0 ethers: 5.0.17 @vue/cli-service: 4.5.13
The full package.json
Just call the web3.js the contract method that will take BigNumber or BN as parameters.
compile and optimize into distribution:
npm run nuxtbuild-demo
orvue-cli-service build --name index ./src/main.js
results:
However, there is no problem when the function is called under development mode:
It gives me the same result for
1000
or100000000
or any integers. However, it does not act as error on dev mode.vue-cli-service serve
So the final problem is that it does normal in local development environment but it reports error exceptions in the production environment.