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

Error from doing production optimization - Error: invalid BigNumber value (argument="value" #305

Closed
jjhesk opened this issue Oct 17, 2021 · 7 comments

Comments

@jjhesk
Copy link

jjhesk commented Oct 17, 2021

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.

  public async approve(spender: string, amount: BigNumber,): Promise<void> {
        const self = this as any as Ori20Contract;

        assert.isString('spender', spender);
        assert.isNumberOrBigNumber('amount', amount);

        const promizz = self._contract.methods.approve(
            spender,
            amount,
        )

        await promizz.send({
            from: this._blockwrap.getAccountAddress(),
            gas: this.gas,
            gasPrice: this.gasPrice
        }).on('transactionHash', (hash) => {
            this.onBroadcast(hash);
        }).on('confirmation', (confirmationNumber, receipt) => {
            this.onConfirmation(receipt);
        }).on('receipt', (r) => {
            this.pushReceiptSuccess(r);
        }).on('error', (error, receipt) => {
            this.onError(receipt, error);
        }).catch((e) => {
            this.catchErro(e)
        });

    };

compile and optimize into distribution:
npm run nuxtbuild-demo or vue-cli-service build --name index ./src/main.js

results:

chunk-vendors.7148939b.js:24 Error: invalid BigNumber value (argument="value", value="1000000000000000000000000000000000000", code=INVALID_ARGUMENT, version=bignumber/5.4.2)
    at h.makeError (chunk-vendors.7148939b.js:1)
    at h.throwError (chunk-vendors.7148939b.js:1)
    at h.throwArgumentError (chunk-vendors.7148939b.js:1)
    at Function.from (chunk-vendors.7148939b.js:54)
    at Z.encode (chunk-vendors.7148939b.js:18)
    at chunk-vendors.7148939b.js:18
    at Array.forEach (<anonymous>)
    at D (chunk-vendors.7148939b.js:18)
    at W.encode (chunk-vendors.7148939b.js:18)
    at ae.encode (chunk-vendors.7148939b.js:18)
nt @ chunk-vendors.7148939b.js:24
ct @ chunk-vendors.7148939b.js:24
at @ chunk-vendors.7148939b.js:24
(anonymous) @ chunk-vendors.7148939b.js:24
Promise.catch (async)
rt @ chunk-vendors.7148939b.js:24
a @ chunk-vendors.7148939b.js:24
Wc.n._wrapper @ chunk-vendors.7148939b.js:24

image

However, there is no problem when the function is called under development mode:
image

It gives me the same result for 1000 or 100000000 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.

@jjhesk jjhesk changed the title Error from doing production optimization Error from doing production optimization - Error: invalid BigNumber value (argument="value" Oct 17, 2021
@jjhesk
Copy link
Author

jjhesk commented Oct 17, 2021

Looks like the same in #290

@jjhesk
Copy link
Author

jjhesk commented Oct 17, 2021

Try discuss: nuxt/nuxt#9957

@MikeMcl
Copy link
Owner

MikeMcl commented Oct 17, 2021

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.

@jjhesk jjhesk closed this as completed Oct 17, 2021
@jjhesk
Copy link
Author

jjhesk commented Oct 17, 2021

It has nothing to with web3 and ethers.js I just confirmed. @MikeMcl

@shuckster
Copy link

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.

@jjhesk
Copy link
Author

jjhesk commented Oct 17, 2021

@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?

@montera82
Copy link

montera82 commented May 17, 2022

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";

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

No branches or pull requests

4 participants