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

ethers.js throws invalid BigNumber error from estimateGas #1243

Closed
yuetloo opened this issue Jan 15, 2021 · 7 comments
Closed

ethers.js throws invalid BigNumber error from estimateGas #1243

yuetloo opened this issue Jan 15, 2021 · 7 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@yuetloo
Copy link
Collaborator

yuetloo commented Jan 15, 2021

The following error was received when estimating gas on a contract function that reverts.

This error seems to only happen if the walletConnect web3-provider was used. I tested with the Infura and etherscan providers, they both throw with the revert reason as expected.

 invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.0.13)

The error was thrown in the return statement in the following code. The BigNumber.from() didn't expect an undefined returned from the estimateGas().

// base-provider.ts
async estimateGas(transaction: Deferrable<TransactionRequest>): Promise<BigNumber> {
        await this.getNetwork();
        const params = await resolveProperties({
            transaction: this._getTransactionRequest(transaction)
        });
        return BigNumber.from(await this.perform("estimateGas", params));
    }
@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. labels Jan 15, 2021
@ricmoo
Copy link
Member

ricmoo commented Jan 15, 2021

Thanks! I’ll go through the provider methods a bit and make sure better errors are bubbled up. :)

@edward-arinin-web-dev
Copy link

I'm also facing this issue when trying to perform payable Contract method and specifying amount i'm want to send.

You can test deployUserWallet method from etherscan contract writeContract

factory_address: 0xdDB10cFC3cea471708B1647415F71BCeA9f96145
w2w_address: 0x41b2E493D3698F6D23466b46266BBEAd6a07Bf56

Works when not specified amount

Screenshot 2021-01-23 at 14 41 14

Error when amount passed to overrides

Screenshot 2021-01-23 at 14 42 34

is it fixed somehow ?

@yuetloo
Copy link
Collaborator Author

yuetloo commented Jan 25, 2021

@edward-arinin-web-dev , this issue was about the original error being swallowed instead of bubbling up and it's not fixed yet.

For your case, were you using the same signer to call createUserWallet()? The contract reverts if the same signer was used to createUserWallet(), regardless of whether amount is passed in or not.

@ricmoo
Copy link
Member

ricmoo commented Feb 13, 2021

This should be fixed in 5.0.31. Try it out and let me know! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 13, 2021
@ricmoo
Copy link
Member

ricmoo commented Feb 16, 2021

Closing this now, but if you still have issues, please feel free to re-open.

Thanks! :)

@ywuywu
Copy link

ywuywu commented Jul 5, 2021

Hi I am getting the same error from ethers abi. Here is the error stack from node --trace-warnings

(node:52910) UnhandledPromiseRejectionWarning: Error: invalid BigNumber value (argument="value", value=[-1407939205,25777879], code=INVALID_ARGUMENT, version=bignumber/5.4.0)
    at Logger.makeError (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/logger/lib/index.js:187:21)
    at Logger.throwError (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/logger/lib/index.js:196:20)
    at Logger.throwArgumentError (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/logger/lib/index.js:199:21)
    at Function.BigNumber.from (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/bignumber/lib/bignumber.js:241:23)
    at NumberCoder.encode (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/abi/lib/coders/number.js:36:39)
    at /Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/abi/lib/coders/array.js:74:19
    at Array.forEach (<anonymous>)
    at Object.pack (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/abi/lib/coders/array.js:60:12)
    at TupleCoder.encode (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/abi/lib/coders/tuple.js:71:24)
    at AbiCoder.encode (/Users/wyiming/code/TeamSilver/defi/javascript/node_modules/@ethersproject/abi/lib/abi-coder.js:93:15)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:96:32)

My code is:

const uniswap = new ethers.Contract(
        "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", // Router V2
        [
            "function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)"
        ],
        account
    );
    const to = "0x7Df54B22Bf8B7eB6b19B667aABe977B2dfD1c5db";
    const path = [weth.address, uni.address];
    const tx = await uniswap.swapExactETHForTokens(. // <-------------- Error comming from this
        1,
        path,
        to,
        deadline,
        {value, gasPrice: ethers.utils.parseUnits('20', 'gwei')}
    );

Could anyone help on this?

A bit more info:

  • the path is resolved into:
[
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
  '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984'
]

@ricmoo
Copy link
Member

ricmoo commented Jul 5, 2021

Can you please add this console.log directly above the call:

console.log({ path, to, deadline, value });

My first guess is that your value is an array; perhaps you have a variable with the same name shadowing the local variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

4 participants