Error invalid bignumber string

I am trying to approve a larger amount of erc-20 tokens (it has 18 decimals). await token.connect(signer).approve(contractAddress, BigNumber.from((1000*(tenToPowerOf18Digits)).toString())) : If I ...

I am trying to approve a larger amount of erc-20 tokens (it has 18 decimals).

await token.connect(signer).approve(contractAddress, BigNumber.from((1000*(tenToPowerOf18Digits)).toString())) :

If I try to approve more than 999 tokens, it gives me this err

Uncaught (in promise) Error: invalid BigNumber string (argument="value", value="1e+21", code=INVALID_ARGUMENT, version=bignumber/5.5.0)

Can anyone help me with this issue? How can I approve more than 999 tokens?

asked Jan 23, 2022 at 13:18

David's user avatar

The problem is that the toString of the number will convert it to a scientific representation which cannot be interpreted by the BigNumber.

The cleanest way to get around this is to use BigNumber when adding the decimals:

const decimals = 18;
const input = 999;
const amount = BigNumber.from(input).mul(BigNumber.from(10).pow(decimals));

Another way is using ethers to parse this:

const decimals = 18;
const input = "999"; // Note: this is a string, e.g. user input
const amount = ethers.utils.parseUnits(input, decimals)

answered Jan 23, 2022 at 15:08

Richard's user avatar

RichardRichard

4,3092 gold badges6 silver badges25 bronze badges

1

solidity newbie here. when I try to read the value of the people array. I’m getting an error:

call to SimpleStorage.people errored: Error encoding arguments: Error:
invalid BigNumber string (argument=»value» value=»»
code=INVALID_ARGUMENT version=bignumber/5.4.2)

my compiler version is 0.6.6. not sure what’s wrong? any suggestions?

// SPD-License_Identifier: MIT

pragma solidity ^0.6.0;

contract SimpleStorage {
    uint256 favNum;
    
    struct People {
        uint256 favNum;
        string name;
    }
    
    People[] public people;
    
    function store(uint256 _favNum) public {
        favNum = _favNum;
    }
    
    function retrieve() public view returns(uint256) {
        return favNum;
    }
    
    function addPerson(string memory _name, uint256 _favNum) public {
        people.push(People(_favNum, _name));
    }
}

asked Nov 17, 2021 at 20:34

Xaarth's user avatar

0

The error happens when you’re trying to call the people() function (from Remix IDE) without passing any value.

Since the People[] public people is a public property, it autogenerates a getter function during compilation. But because it’s an array, the getter function requires an uint256 param specifying the index of the array that you want to retrieve.

When you pass an empty string, Remix tries to encode it to the BigNumber instance, but this fails. Only when you pass an (existing) index of the array, it works correctly:

people() call


If you want to get the whole array in one call, you need to create a separate getter function:

function getAllPeople() public view returns (People[] memory) {
    return people;
}

getAllPeople() call

answered Nov 18, 2021 at 9:40

Petr Hejda's user avatar

Petr HejdaPetr Hejda

37.3k8 gold badges70 silver badges93 bronze badges

6

You must click on the small arrow to the right of the deploy button, then the fields will be displayed so that you can complete the data that the contract must receive.
enter image description here

answered Apr 20, 2022 at 1:11

Ale DC's user avatar

Ale DCAle DC

1,44812 silver badges18 bronze badges

@beejaz

Hi,

Following your latest youtube video with PancakeSwap trading bot, I get this error and can’t seem to find why or where it happens:

(node:21378) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument="value", value="0.1", code=INVALID_ARGUMENT, version=bignumber/5.1.1)
    at Logger.makeError (/home/pancake-trading-bot/node_modules/@ethersproject/logger/lib/index.js:180:21)
    at Logger.throwError (/home/pancake-trading-bot/node_modules/@ethersproject/logger/lib/index.js:189:20)
    at Logger.throwArgumentError (/home//pancake-trading-bot/node_modules/@ethersproject/logger/lib/index.js:192:21)
    at Function.BigNumber.from (/home/pancake-trading-bot/node_modules/@ethersproject/bignumber/lib/bignumber.js:201:27)
    at NumberCoder.encode (/home/pancake-trading-bot/node_modules/@ethersproject/abi/lib/coders/number.js:36:39)
    at /home/pancake-trading-bot/node_modules/@ethersproject/abi/lib/coders/array.js:74:19
    at Array.forEach (<anonymous>)
    at Object.pack (/home/pancake-trading-bot/node_modules/@ethersproject/abi/lib/coders/array.js:60:12)
    at TupleCoder.encode (/home/pancake-trading-bot/node_modules/@ethersproject/abi/lib/coders/tuple.js:71:24)
    at AbiCoder.encode (/home/pancake-trading-bot/node_modules/@ethersproject/abi/lib/abi-coder.js:93:15)
(node:21378) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21378) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Any idea?

@DeVoresyah

@beejaz

Okay, so I got this error because if this line
https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41

I had to use ‘1’ or larger amount on approve. But now I get this error instead:

(node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not a function
    at init (/home/pancake-trading-bot/bot.js:44:28)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which I dont understand either because wbnb.approve returns bool so tx = true, there is no function called wait

@DeVoresyah

Okay, so I got this error because if this line
https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41

I had to use ‘1’ or larger amount on approve. But now I get this error instead:

(node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not a function
    at init (/home/pancake-trading-bot/bot.js:44:28)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which I dont understand either because wbnb.approve returns bool so tx = true, there is no function called wait

I already solved my previous problem above, but I got this error

UnhandledPromiseRejectionWarning: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT"

@ozgurk78

I have same problem , What can we do?

(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

@ivekivek

I have same problem , What can we do?

(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

You need to replace «replace by amount covering several trades» with value, put «1» or more.
Anyway after solving this one, I got «tx.wait() is not function» and solve this, but can see he solve it too yesterday. After that we need to figure out how to solve gas estimate error. I think it should work with this, not sure, but it worked with Uniswap.

We need to set gas price and limit manual.

const tx = await router.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    [tokenIn, tokenOut],
    addresses.recipient,
    {
      value: '0',
      gasPrice: ethers.BigNumber.from(1000000).toHexString(),
      gasLimit: ethers.BigNumber.from(1000000).toHexString() 
    },
    Date.now() + 1000 * 60 * 10, // 10 minutes
); 

@thekooldev1232

Yea this is the error where I am stuck too !! Hope this helps 🤘

@ivekivek

Yea this is the error where I am stuck too !! Hope this helps 🤘

Try it and let know

@DioLorenzo

Promise {
ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
}

(node:76719) UnhandledPromiseRejectionWarning: ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
(node:76719) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

I have this error, how I can solve it?

@mujahidazamcsm

Hello Everyone..

Getting this error.. any idea how to fix this?

events.js:174 throw er; // unhandled ‘error’ event

@ivekivek

Promise {
ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
}

(node:76719) UnhandledPromiseRejectionWarning: ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
(node:76719) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

I have this error, how I can solve it?

Can you share your code?

@ivekivek

Hello Everyone..

Getting this error.. any idea how to fix this?

events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

@DioLorenzo

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

const provider = new ethers.providers.WebSocketProvider(‘my url here in https not wss’)
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);

const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);

const init = async () => {
const tx = await wbnb.approve(
router.address,
’10’
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
}

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => {
console.log(New pair detected ================= token0: ${token0} token1: ${token1} pairAddress: ${pairAddress});

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}

if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) {
return;
}

//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//’ether’ === ‘bnb’ on BSC
const amountIn = ethers.utils.parseUnits(‘0.001’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(Buying new token ================= tokenIn: ${amountIn.toString()} ${tokenIn} (WBNB) tokenOut: ${amounOutMin.toString()} ${tokenOut});
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
{
value: ‘0’,
gasPrice: ethers.BigNumber.from(1000000).toHexString(),
gasLimit: ethers.BigNumber.from(1000000).toHexString()
},
Date.now() + 1000 * 60 * 10, // 10 minutes
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
});

init();

@mujahidazamcsm

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

Hi @ivekivek,

It is pretty much the stock code.. just commented out a few lines as I dont want to make a purchase or approve WBNB.. added logs.. to see where it is failing.. let me know if u r able to get it to work

const ethers = require(‘ethers’);

const addresses = {
WBNB: ‘0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c’,
factory: ‘0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73’,
router: ‘0x10ED43C718714eb63d5aA57B78B54704E256024E’,
recipient: ‘- put ur address here’
}

//First address of this mnemonic must have enough BNB to pay for tx fess
const mnemonic = ‘- put ur mnemonic here’

const provider = new ethers.providers.WebSocketProvider(‘wss://apis.ankr.com/wss/….’); //Ankr websocket url to mainnet
console.log(‘provider’);
//console.log(provider);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
console.log(‘wallet’);
//console.log(wallet);
const account = wallet.connect(provider);
console.log(‘account’);
//console.log(account);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
console.log(‘factory’);
//console.log(factory);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);
console.log(‘router’);
//console.log(router);
const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);
console.log(‘wbnb’);
//console.log(wbnb);
const init = async () => {
/*const tx = await wbnb.approve(
router.address,
‘replace by amount covering several trades’
);
const receipt = await tx.wait(); */

console.log(‘Transaction receipt11’);
//console.log(receipt);
}
console.log(‘PairCreated’);

factory.on(‘error’, function(err){
console.log(‘onerror’);
console.log(err);
});

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => {

console.log('on PairCreated');

console.log(New pair detected ================= token0: ${token0} token1: ${token1} pairAddress: ${pairAddress});

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}

if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) {
return;
}

//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//’ether’ === ‘bnb’ on BSC
const amountIn = ethers.utils.parseUnits(‘0.01’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(Buying new token ================= tokenIn: ${amountIn.toString()} ${tokenIn} (WBNB) tokenOut: ${amounOutMin.toString()} ${tokenOut});

/* const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
Date.now() + 1000 * 60 * 10 //10 minutes
);

const receipt = await tx.wait();
*/
console.log(‘Transaction receipt’);
console.log(receipt);
});

init();

@thekooldev1232

You

I have same problem , What can we do?
(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

You need to replace «replace by amount covering several trades» with value, put «1» or more.
Anyway after solving this one, I got «tx.wait() is not function» and solve this, but can see he solve it too yesterday. After that we need to figure out how to solve gas estimate error. I think it should work with this, not sure, but it worked with Uniswap.

We need to set gas price and limit manual.

const tx = await router.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    [tokenIn, tokenOut],
    addresses.recipient,
    {
      value: '0',
      gasPrice: ethers.BigNumber.from(1000000).toHexString(),
      gasLimit: ethers.BigNumber.from(1000000).toHexString() 
    },
    Date.now() + 1000 * 60 * 10, // 10 minutes
); 

this doesn’t work dude! still issue persist

@agoralive

Really looking forward to hopefully fixing this issue guys :)

@thekooldev1232

add nounce inside the tx object

@ivekivek

add nounce inside the tx object

It is working like that?

@agoralive

@tuxforensics

// i added the line below this comment to solve my issues for the approve.
const valueToapprove = ethers.utils.parseUnits(‘0.05’, ‘ether’);
const init = async () => {
const tx = await wbnb.approve(
router.address,
valueToapprove
// valueToapprove is the constant before this block
);

Now I need help with setting gas limit and gas because estimation isn’t working and i don’t know where to put them for the transaction

@hbtj123

Hi All,
I have something similar.

Can anyone advise here?

transaction failed (transactionHash=»», transaction={«nonce»:,»gasPrice»:{«type»:»BigNumber»,»hex»:»»},»gasLimit»:{«type»:»BigNumber»,»hex»:»0x061a80″},»to»:»»,»value»:{«type»:»BigNumber»,»hex»:»0x00″},»data»:»0xa5be382e000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b083653f11a5133868d56dacd723b837e27b7d17000000000000000000000000000000000000000000000000000001799a15a8690000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000b3225ac90b741f762beca76dea1ead278ef26a96″,»chainId»:56,»v»:148,»r»:»»,»s»:»»,»from»:»»,»hash»:»»}, receipt={«to»:»»,»from»:»»,»contractAddress»:null,»transactionIndex»:324,»gasUsed»:{«type»:»BigNumber»,»hex»:»0x5a8b»},»logsBloom»:»0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000″,»blockHash»:»0x2ee5c5c282a605193f282aa34e31fa18c62ff3fdc6cd996e1592be49cdb60e03″,»transactionHash»:»0x35bb3f987f4f99fab4572db341886220a400f791cb68bce401dcf00fd5099396″,»logs»:[],»blockNumber»:7663738,»confirmations»:1,»cumulativeGasUsed»:{«type»:»BigNumber»,»hex»:»0x02bf7565″},»status»:0,»byzantium»:true}, code=CALL_EXCEPTION, version=providers/5.0.24)
at Logger.makeError (trading-botnode_modules@ethersprojectloggerlibindex.js:180:21)
at Logger.throwError (trading-botnode_modules@ethersprojectloggerlibindex.js:189:20)
at WebSocketProvider. (trading-botnode_modules@ethersprojectproviderslibbase-provider.js:1162:36)

@mestan998

Hey After Fixing all the above issues I am getting error

Unexpected server response: 200
Emitted ‘error’ event on WebSocket instance at:
at abortHandshake (/home/shady/Projects/Tokens/PancakeBot/node_modules/ws/lib/websocket.js:698:15)
at ClientRequest. (/home/shady/Projects/Tokens/PancakeBot/node_modules/ws/lib/websocket.js:580:7)
[… lines matching original stack trace …]

@henrykash

Okay, so I got this error because if this line
https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41
I had to use ‘1’ or larger amount on approve. But now I get this error instead:

(node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not a function
    at init (/home/pancake-trading-bot/bot.js:44:28)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which I dont understand either because wbnb.approve returns bool so tx = true, there is no function called wait

I already solved my previous problem above, but I got this error

UnhandledPromiseRejectionWarning: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT"

you can try hardcode the gasLimit it will solve the issue

const tx = await wbnb.approve(
router.address,
valueToapprove,
{
gasLimit:100000
}
);

@henrykash

you can try hardcode the gasLimit

@GianluBLockchain-DEV

same here

Hey After Fixing all the above issues I am getting error

Unexpected server response: 200 Emitted ‘error’ event on WebSocket instance at: at abortHandshake (/home/shady/Projects/Tokens/PancakeBot/node_modules/ws/lib/websocket.js:698:15) at ClientRequest. (/home/shady/Projects/Tokens/PancakeBot/node_modules/ws/lib/websocket.js:580:7) [… lines matching original stack trace …]

i have same error how did you fix this?

@SloboZjalic

Hehe got it all sorted now

On Sat, 12 Nov 2022, 3:15 am Henry Kariuki Nyagah, ***@***.***> wrote:
Okay, so I got this error because if this line

https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41
I had to use ‘1’ or larger amount on approve. But now I get this error
instead:

(node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not a function
at init (/home/pancake-trading-bot/bot.js:44:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which I dont understand either because wbnb.approve returns bool so tx =
true, there is no function called wait

I already solved my previous problem above, but I got this error

UnhandledPromiseRejectionWarning: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={«reason»:»cannot estimate gas; transaction may fail or may require manual gas limit»,»code»:»UNPREDICTABLE_GAS_LIMIT»

you can try hardcode the gasLimit it will solve the issue

const tx = await wbnb.approve(
router.address,
valueToapprove,
{
gasLimit:100000
}
);


Reply to this email directly, view it on GitHub
<#58 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATGNCO443IWD5F3P7NCJARLWHZWLPANCNFSM443IC7LQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>

@henrykash

Did you get through the blocker?

On Mon, Nov 21, 2022 at 5:58 AM SloboZjalic ***@***.***>
wrote:

Hehe got it all sorted now

On Sat, 12 Nov 2022, 3:15 am Henry Kariuki Nyagah, ***@***.***>
wrote:

> Okay, so I got this error because if this line
>
>
https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41
> I had to use ‘1’ or larger amount on approve. But now I get this error
> instead:
>
> (node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not
a function
> at init (/home/pancake-trading-bot/bot.js:44:28)
> at process._tickCallback (internal/process/next_tick.js:68:7)
> (node:21550) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 1)
> (node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
>
> Which I dont understand either because wbnb.approve returns bool so tx =
> true, there is no function called wait
>
> I already solved my previous problem above, but I got this error
>
> UnhandledPromiseRejectionWarning: Error: cannot estimate gas;
transaction may fail or may require manual gas limit
(error={«reason»:»cannot estimate gas; transaction may fail or may require
manual gas limit»,»code»:»UNPREDICTABLE_GAS_LIMIT»
>
> you can try hardcode the gasLimit it will solve the issue
>
> const tx = await wbnb.approve(
> router.address,
> valueToapprove,
> {
> gasLimit:100000
> }
> );
>
> —
> Reply to this email directly, view it on GitHub
> <
#58 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/ATGNCO443IWD5F3P7NCJARLWHZWLPANCNFSM443IC7LQ
>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>


Reply to this email directly, view it on GitHub
<#58 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJLLIIYJAH6G3I6EHTBLJQ3WJLQONANCNFSM443IC7LQ>
.
You are receiving this because you commented.Message ID:
***@***.***>

@SloboZjalic

All the errors are there

On Sat, 12 Nov 2022, 3:15 am Henry Kariuki Nyagah, ***@***.***> wrote:
Okay, so I got this error because if this line

https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41
I had to use ‘1’ or larger amount on approve. But now I get this error
instead:

(node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not a function
at init (/home/pancake-trading-bot/bot.js:44:28)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21550) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Which I dont understand either because wbnb.approve returns bool so tx =
true, there is no function called wait

I already solved my previous problem above, but I got this error

UnhandledPromiseRejectionWarning: Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={«reason»:»cannot estimate gas; transaction may fail or may require manual gas limit»,»code»:»UNPREDICTABLE_GAS_LIMIT»

you can try hardcode the gasLimit it will solve the issue

const tx = await wbnb.approve(
router.address,
valueToapprove,
{
gasLimit:100000
}
);


Reply to this email directly, view it on GitHub
<#58 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATGNCO443IWD5F3P7NCJARLWHZWLPANCNFSM443IC7LQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>

@henrykash

Ok, I will check.

On Mon, Nov 21, 2022 at 12:13 PM SloboZjalic ***@***.***>
wrote:

All the errors are there

On Sat, 12 Nov 2022, 3:15 am Henry Kariuki Nyagah, ***@***.***>
wrote:

> Okay, so I got this error because if this line
>
>
https://github.com/jklepatch/eattheblocks/blob/master/screencast/348-pancakeswap-trading-bot/bot.js#L41
> I had to use ‘1’ or larger amount on approve. But now I get this error
> instead:
>
> (node:21550) UnhandledPromiseRejectionWarning: TypeError: tx.wait is not
a function
> at init (/home/pancake-trading-bot/bot.js:44:28)
> at process._tickCallback (internal/process/next_tick.js:68:7)
> (node:21550) UnhandledPromiseRejectionWarning: Unhandled promise
rejection. This error originated either by throwing inside of an async
function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 1)
> (node:21550) [DEP0018] DeprecationWarning: Unhandled promise rejections
are deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
>
> Which I dont understand either because wbnb.approve returns bool so tx =
> true, there is no function called wait
>
> I already solved my previous problem above, but I got this error
>
> UnhandledPromiseRejectionWarning: Error: cannot estimate gas;
transaction may fail or may require manual gas limit
(error={«reason»:»cannot estimate gas; transaction may fail or may require
manual gas limit»,»code»:»UNPREDICTABLE_GAS_LIMIT»
>
> you can try hardcode the gasLimit it will solve the issue
>
> const tx = await wbnb.approve(
> router.address,
> valueToapprove,
> {
> gasLimit:100000
> }
> );
>
> —
> Reply to this email directly, view it on GitHub
> <
#58 (comment)
>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/ATGNCO443IWD5F3P7NCJARLWHZWLPANCNFSM443IC7LQ
>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>


Reply to this email directly, view it on GitHub
<#58 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJLLII5HSBJRCFHMMQQHKC3WJM4MRANCNFSM443IC7LQ>
.
You are receiving this because you commented.Message ID:
***@***.***>

@henrykash

Alright so instead of using wait( ) function you can use the waitForTransaction function from ethers, which takes in the transaction hash of the transaction broadcasted , number of confirmation and timeout in milliseconds …assuming that the tx returns a successful transaction hash and that it’s accessed as tx.data : you can do the following example


const tx = await wbnb.approve(
router.address,
valueToapprove,
{
gasLimit:100000
}
);
const provider = new ethers.providers.WebSocketProvider('wss://apis.ankr.com/wss/....');
const receipt =  await  provider.waitForTransaction(tx.data, 1, 60000);

  if (receipt && receipt.status == 1) {

           //TODO: you can proceed with your code execution                                                   
    })

Содержание

  1. Error: invalid BigNumber string from PancakeSwap trading bot #58
  2. Comments
  3. web3 1.2.9 does not properly encode «-1» as int8 (signed) #3772
  4. Comments
  5. Expected behavior
  6. Actual behavior
  7. Steps to reproduce the behavior
  8. Environment

Error: invalid BigNumber string from PancakeSwap trading bot #58

Following your latest youtube video with PancakeSwap trading bot, I get this error and can’t seem to find why or where it happens:

The text was updated successfully, but these errors were encountered:

I had to use ‘1’ or larger amount on approve. But now I get this error instead:

Which I dont understand either because wbnb.approve returns bool so tx = true, there is no function called wait

I had to use ‘1’ or larger amount on approve. But now I get this error instead:

Which I dont understand either because wbnb.approve returns bool so tx = true, there is no function called wait

I already solved my previous problem above, but I got this error

I have same problem , What can we do?

(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

I have same problem , What can we do?

(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

You need to replace «replace by amount covering several trades» with value, put «1» or more.
Anyway after solving this one, I got «tx.wait() is not function» and solve this, but can see he solve it too yesterday. After that we need to figure out how to solve gas estimate error. I think it should work with this, not sure, but it worked with Uniswap.

We need to set gas price and limit manual.

Yea this is the error where I am stuck too !! Hope this helps 🤘

Yea this is the error where I am stuck too !! Hope this helps 🤘

Try it and let know

Promise <
ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
>

(node:76719) UnhandledPromiseRejectionWarning: ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
(node:76719) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag —unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

I have this error, how I can solve it?

Getting this error.. any idea how to fix this?

events.js:174 throw er; // unhandled ‘error’ event

Promise <
ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
>

(node:76719) UnhandledPromiseRejectionWarning: ReferenceError: wbnb is not defined
at init (REPL45:2:14)
at REPL415:1:1
at Script.runInThisContext (vm.js:133:18)
at REPLServer.defaultEval (repl.js:486:29)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:388:22)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:342:10)
(node:76719) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag —unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

I have this error, how I can solve it?

Can you share your code?

Getting this error.. any idea how to fix this?

events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

const provider = new ethers.providers.WebSocketProvider(‘my url here in https not wss’)
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);

const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);

const init = async () => <
const tx = await wbnb.approve(
router.address,
’10’
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
>

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => <
console.log( New pair detected ================= token0: $ token1: $ pairAddress: $ );

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) <
tokenIn = token0;
tokenOut = token1;
>

if(token1 == addresses.WBNB) <
tokenIn = token1;
tokenOut = token0;
>

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) <
return;
>

//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//’ether’ === ‘bnb’ on BSC
const amountIn = ethers.utils.parseUnits(‘0.001’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log( Buying new token ================= tokenIn: $ $ (WBNB) tokenOut: $ $ );
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
<
value: ‘0’,
gasPrice: ethers.BigNumber.from(1000000).toHexString(),
gasLimit: ethers.BigNumber.from(1000000).toHexString()
>,
Date.now() + 1000 * 60 * 10, // 10 minutes
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
>);

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

It is pretty much the stock code.. just commented out a few lines as I dont want to make a purchase or approve WBNB.. added logs.. to see where it is failing.. let me know if u r able to get it to work

const ethers = require(‘ethers’);

const addresses = <
WBNB: ‘0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c’,
factory: ‘0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73’,
router: ‘0x10ED43C718714eb63d5aA57B78B54704E256024E’,
recipient: ‘- put ur address here’
>

//First address of this mnemonic must have enough BNB to pay for tx fess
const mnemonic = ‘- put ur mnemonic here’

const provider = new ethers.providers.WebSocketProvider(‘wss://apis.ankr.com/wss/. ‘); //Ankr websocket url to mainnet
console.log(‘provider’);
//console.log(provider);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
console.log(‘wallet’);
//console.log(wallet);
const account = wallet.connect(provider);
console.log(‘account’);
//console.log(account);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
console.log(‘factory’);
//console.log(factory);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);
console.log(‘router’);
//console.log(router);
const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);
console.log(‘wbnb’);
//console.log(wbnb);
const init = async () => <
/*const tx = await wbnb.approve(
router.address,
‘replace by amount covering several trades’
);
const receipt = await tx.wait(); */

console.log(‘Transaction receipt11’);
//console.log(receipt);
>
console.log(‘PairCreated’);

factory.on(‘error’, function(err) <
console.log(‘onerror’);
console.log(err);
>);

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => <

console.log( New pair detected ================= token0: $ token1: $ pairAddress: $ );

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) <
tokenIn = token0;
tokenOut = token1;
>

if(token1 == addresses.WBNB) <
tokenIn = token1;
tokenOut = token0;
>

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) <
return;
>

Источник

web3 1.2.9 does not properly encode «-1» as int8 (signed) #3772

My current contract has a function with the following signature:

function submitCAVote(uint claimId, int8 verdict) . I’m trying to pass -1 as verdict value.

Expected behavior

-1 passed as a string or BN should be encoded correctly and function called.

Actual behavior

When calling the contract web3 throws the following error:

Error: invalid BigNumber string (argument=»value», value=»000000-1″, code=INVALID_ARGUMENT, version=bignumber/5.0.8)

Steps to reproduce the behavior

I hope this is enough to reproduce the issue. Currently this code is untested as I have extracted the relevant parts from my testing environment.

The stack trace does not include anything from node_modules (just the path to my test).

Environment

I’m using web3@1.2.9 on node v12.19.0 and npm 6.14.8 on Ubuntu.

The text was updated successfully, but these errors were encountered:

@shark0der you mentioned that there’s a version and properly encodes it. Which version was it?

@alcuadrado it works fine on web3@1.2.1

There’s also another issue which is more of an incompatibility rather than a bug. When passing -1 for a uint parameter it complains that the value is bad while previously it was converting it to MAX_UINT .

@ryanio @cgewecke I think we discussed some problems with the version of the ethers encoder used by web3. Can this be related?

Hi @shark0der — in an initial attempt I haven’t been able to reproduce this.

Could you show the complete stack trace of the error?

For both 1.2.9 and 1.3.0, the following seems to encode the params correctly

There’s also another issue which is more of an incompatibility rather than a bug. When passing -1 for a uint parameter it complains that the value is bad while previously it was converting it to MAX_UINT

There are a couple other behavioral changes listed in the 1.2.8 release notes. These are intended as bug-fixes, e.g. silently overflowing when a negative number is passed as an unsigned integer seems bad.

I’m not sure I’ve correctly identified the issue because running contract.methods.submitCAVote(‘1’, negativeOne).encodeABI() returns exactly what you have. The culprit might be truffle-contract but I’m really not sure where to dig because the stack trace does not show anything from node_modules :

npm i && npm test should suffice to reproduce the issue.

It looks like it is a problem here but only affects negative number strings.

Modifying the NexusMutual tests like this makes them pass

Native negative numbers also work (for both truffle/contract and pure Web3).

Relevant code at Web3 is around this location.

This was also working fine with web3 1.2.1

See comment above. In your view should this not be seen as a bug-fix?

I see it as a breaking change that should not be included in a patch version but rather in a minor version to follow the semver convention. If the library is silently updated — the tests start failing (which is exactly what happened).

Maybe that wasn’t the intention initially but this is what we are using and perhaps others could be using as well. It’s also similar to how solidity behaves so it was easy to understand and adopt it.

Might also be worth checking since when this started to happen. It was behaving like this in 1.2.1 which was released in Aug 6, 2019 so it was behaving like this for over 9 months until it was «fixed» — not sure how many people rely on this already.

Longterm, however, I strongly agree it should not silently overflow but rather throw to prevent unintended behaviour.

Источник

URL

https://uni.zksync.io/#/swap

swap state

{
  "INPUT": {
    "currencyId": "0x7457fc3f89ac99837d44f60B7860691fb2f09Bf5"
  },
  "OUTPUT": {
    "currencyId": "0xeb8f08a975Ab53E34D8a0330E0D34de942C95926"
  },
  "independentField": "INPUT",
  "typedValue": "-0.15117448",
  "recipient": null
}

Error

Error: invalid BigNumber string (argument="value", value="0x-e6ac88", code=INVALID_ARGUMENT, version=bignumber/5.4.1)

Stacktrace

Error: invalid BigNumber string (argument="value", value="0x-e6ac88", code=INVALID_ARGUMENT, version=bignumber/5.4.1)
    at e.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:92372)
    at e.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:92516)
    at e.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:92595)
    at Function.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:146744)
    at r.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:831620)
    at https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:827305
    at Array.forEach (<anonymous>)
    at v (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:827161)
    at r.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:833254)
    at e.value (https://uni.zksync.io/static/js/2.b4d56b63.chunk.js:2:835086)

Device data

{
  "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36",
  "browser": {
    "name": "Chrome",
    "version": "94.0.4606.71",
    "major": "94"
  },
  "engine": {
    "name": "Blink",
    "version": "94.0.4606.71"
  },
  "os": {
    "name": "Windows",
    "version": "10"
  },
  "device": {},
  "cpu": {
    "architecture": "amd64"
  }
}

I have same problem , What can we do?

(node:15408) UnhandledPromiseRejectionWarning: Error: invalid BigNumber string (argument=»value», value=»replace by amount covering several trades», code=INVALID_ARGUMENT, version=bignumber/5.0.15)

You need to replace «replace by amount covering several trades» with value, put «1» or more.
Anyway after solving this one, I got «tx.wait() is not function» and solve this, but can see he solve it too yesterday. After that we need to figure out how to solve gas estimate error. I think it should work with this, not sure, but it worked with Uniswap.

We need to set gas price and limit manual.

const tx = await router.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    [tokenIn, tokenOut],
    addresses.recipient,
    {
      value: '0',
      gasPrice: ethers.BigNumber.from(1000000).toHexString(),
      gasLimit: ethers.BigNumber.from(1000000).toHexString() 
    },
    Date.now() + 1000 * 60 * 10, // 10 minutes
); 

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

const provider = new ethers.providers.WebSocketProvider(‘my url here in https not wss’)
const account = wallet.connect(provider);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);

const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);

const init = async () => {
const tx = await wbnb.approve(
router.address,
’10’
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
}

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => {
console.log(New pair detected ================= token0: ${token0} token1: ${token1} pairAddress: ${pairAddress});

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}

if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) {
return;
}

//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//’ether’ === ‘bnb’ on BSC
const amountIn = ethers.utils.parseUnits(‘0.001’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(Buying new token ================= tokenIn: ${amountIn.toString()} ${tokenIn} (WBNB) tokenOut: ${amounOutMin.toString()} ${tokenOut});
const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
{
value: ‘0’,
gasPrice: ethers.BigNumber.from(1000000).toHexString(),
gasLimit: ethers.BigNumber.from(1000000).toHexString()
},
Date.now() + 1000 * 60 * 10, // 10 minutes
);
const receipt = await tx.wait();
console.log(‘Transaction receipt’);
console.log(receipt);
});

init();

Hello Everyone..
Getting this error.. any idea how to fix this?
events.js:174 throw er; // unhandled ‘error’ event

Can you share code?

Hi @ivekivek,

It is pretty much the stock code.. just commented out a few lines as I dont want to make a purchase or approve WBNB.. added logs.. to see where it is failing.. let me know if u r able to get it to work

const ethers = require(‘ethers’);

const addresses = {
WBNB: ‘0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c’,
factory: ‘0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73’,
router: ‘0x10ED43C718714eb63d5aA57B78B54704E256024E’,
recipient: ‘- put ur address here’
}

//First address of this mnemonic must have enough BNB to pay for tx fess
const mnemonic = ‘- put ur mnemonic here’

const provider = new ethers.providers.WebSocketProvider(‘wss://apis.ankr.com/wss/….’); //Ankr websocket url to mainnet
console.log(‘provider’);
//console.log(provider);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
console.log(‘wallet’);
//console.log(wallet);
const account = wallet.connect(provider);
console.log(‘account’);
//console.log(account);
const factory = new ethers.Contract(
addresses.factory,
[‘event PairCreated(address indexed token0, address indexed token1, address pair, uint)’],
account
);
console.log(‘factory’);
//console.log(factory);
const router = new ethers.Contract(
addresses.router,
[
‘function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)’,
‘function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)’
],
account
);
console.log(‘router’);
//console.log(router);
const wbnb = new ethers.Contract(
addresses.WBNB,
[
‘function approve(address spender, uint amount) public returns(bool)’,
],
account
);
console.log(‘wbnb’);
//console.log(wbnb);
const init = async () => {
/*const tx = await wbnb.approve(
router.address,
‘replace by amount covering several trades’
);
const receipt = await tx.wait(); */

console.log(‘Transaction receipt11’);
//console.log(receipt);
}
console.log(‘PairCreated’);

factory.on(‘error’, function(err){
console.log(‘onerror’);
console.log(err);
});

factory.on(‘PairCreated’, async (token0, token1, pairAddress) => {

console.log('on PairCreated');

console.log(New pair detected ================= token0: ${token0} token1: ${token1} pairAddress: ${pairAddress});

//The quote currency needs to be WBNB (we will pay with WBNB)
let tokenIn, tokenOut;
if(token0 === addresses.WBNB) {
tokenIn = token0;
tokenOut = token1;
}

if(token1 == addresses.WBNB) {
tokenIn = token1;
tokenOut = token0;
}

//The quote currency is not WBNB
if(typeof tokenIn === ‘undefined’) {
return;
}

//We buy for 0.1 BNB of the new token
//ethers was originally created for Ethereum, both also work for BSC
//’ether’ === ‘bnb’ on BSC
const amountIn = ethers.utils.parseUnits(‘0.01’, ‘ether’);
const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
//Our execution price will be a bit different, we need some flexbility
const amountOutMin = amounts[1].sub(amounts[1].div(10));
console.log(Buying new token ================= tokenIn: ${amountIn.toString()} ${tokenIn} (WBNB) tokenOut: ${amounOutMin.toString()} ${tokenOut});

/* const tx = await router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
Date.now() + 1000 * 60 * 10 //10 minutes
);

const receipt = await tx.wait();
*/
console.log(‘Transaction receipt’);
console.log(receipt);
});

init();

Hi All,
I have something similar.

Can anyone advise here?

transaction failed (transactionHash=»», transaction={«nonce»:,»gasPrice»:{«type»:»BigNumber»,»hex»:»»},»gasLimit»:{«type»:»BigNumber»,»hex»:»0x061a80″},»to»:»»,»value»:{«type»:»BigNumber»,»hex»:»0x00″},»data»:»0xa5be382e000000000000000000000000000000000000000000000000000009184e72a000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000b083653f11a5133868d56dacd723b837e27b7d17000000000000000000000000000000000000000000000000000001799a15a8690000000000000000000000000000000000000000000000000000000000000002000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000000000000000000000000b3225ac90b741f762beca76dea1ead278ef26a96″,»chainId»:56,»v»:148,»r»:»»,»s»:»»,»from»:»»,»hash»:»»}, receipt={«to»:»»,»from»:»»,»contractAddress»:null,»transactionIndex»:324,»gasUsed»:{«type»:»BigNumber»,»hex»:»0x5a8b»},»logsBloom»:»0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000″,»blockHash»:»0x2ee5c5c282a605193f282aa34e31fa18c62ff3fdc6cd996e1592be49cdb60e03″,»transactionHash»:»0x35bb3f987f4f99fab4572db341886220a400f791cb68bce401dcf00fd5099396″,»logs»:[],»blockNumber»:7663738,»confirmations»:1,»cumulativeGasUsed»:{«type»:»BigNumber»,»hex»:»0x02bf7565″},»status»:0,»byzantium»:true}, code=CALL_EXCEPTION, version=providers/5.0.24)
at Logger.makeError (trading-bot[email protected]loggerlibindex.js:180:21)
at Logger.throwError (trading-bot[email protected]loggerlibindex.js:189:20)
at WebSocketProvider. (trading-bot[email protected]providerslibbase-provider.js:1162:36)

I’m trying to get a random number with Chainlink VRF,
So Hi have follow this demo step by step : https://www.youtube.com/watch?v=JqZWariqh5s

here is what i’ve copied on Remix :

pragma solidity 0.6.6;

import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";

contract RandomNumberConsumer is VRFConsumerBase {
    
    bytes32 public keyHash;
    uint256 public fee;
    uint256 public randomResult;
    
    constructor() VRFConsumerBase(
            0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator
            0xa36085F69e2889c224210F603D836748e7dC0088  // LINK Token
        ) public
    {
        keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
        fee = 0.1 * 10 ** 18; // 0.1 LINK
    }
    

    function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
        return requestRandomness(keyHash, fee, userProvidedSeed);
    }

    function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        randomResult = randomness.mod(50).add(1);
    }
}

when i click on getRandomNumber, i always get this error :
Error encoding arguments: Error: invalid BigNumber string (argument=»value», value=»», code=INVALID_ARGUMENT, version=bignumber/5.0.8)

and with the fulfillRandomness, i get this error :
Error encoding arguments: Error: invalid arrayify value (argument=»value», value=»», code=INVALID_ARGUMENT, version=bytes/5.0.5)

a019 Asks: Complex equations: NDSolveValue / FEM,
So, I am trying to solve a simple problem using the FEM method.

The distribution of Voltage over a region,

The region is,

Code:

  << NDSolve`FEM`
bm = ToBoundaryMesh[
   "Coordinates" -> {{0., 0.}, {1., 0.}, {12/10, 0.}, {12/10, 1.}, {1., 
      1.}, {0., 1.}}, 
   "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 
        5}, {5, 6}, {6, 1}, {5, 2}}]}];
em = ToElementMesh[bm, 
   "RegionMarker" -> {{{0.5, 0.5}, 1}, {{1.2, 0.5}, 2}}];

which look like this,

Code:

     Show[{
  em["Wireframe"["MeshElementStyle" -> Directive[EdgeForm[Red], Thin],
     "MeshElementMarkerStyle" -> Blue]],
  bm["Wireframe"["MeshElementStyle" -> Black]]
  }, ImageSize -> 300]

enter image description here

I have two equations,

Code:

op1 = Laplacian[v1[x, y], {x, y}];
op2= Laplacian[v2[x, y], {x, y}];

bc1=DirichletCondition[v1[x, y] == 4, x == 12/10];
bc2=DirichletCondition[v2[x, y] == 0, x == 0];

omg=376.991;
dd=100;
d=25*10^-6;

 eef={4.18382,4.22462,9.95342,12.8216,13.9473,14.4967,14.8028,14.9896,15.1113,15.195,15.2551,15.2998,15.3341,15.3611,15.3829,15.4007,15.4155,15.428,15.4387,15.4478,15.4556,15.4624,15.4682,15.4733,15.4777};
    ee1 = ListInterpolation[eef, InterpolationOrder -> 1]

ee1 has dependence on v1[x,y]-v2[x,y], as ee1[Abs[v1[x,y]-v2[x,y]]]

Code:

{v1fun,v2fun} = NDSolveValue[{op1==If[ElementMarker == 1, ((I omg ee1[
     Abs[v1[x, y] - v2[x, y]]])/(dd d)) (v1[x, y] - 
     v2[x, y]), 0], op2==If[ElementMarker == 1, (
   (I omg ee1[
     Abs[v1[x, y] - v2[x, y]]])/(dd d)) (v2[x, y] - 
     v1[x, y]), 0],bc1,bc2},{v1[x, y],v2{x,y}}, {x, y} ∈ em]

The output contour plot of (Abs[v1[x,y]-v2[x,y]]) should be the distribution of voltage over the entire mesh region with the highest values at the x=0 and x=1.2.

I am getting different errors in versions 11.1 and 13.1. I am trying to solve complex equations in NdSolveValue and FEM.

SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.

Понравилась статья? Поделить с друзьями:
  • Error invalid arch independent elf magic grub rescue
  • Error invalid app version you need to update droidcam on your device ок
  • Error invalid ajax data
  • Error interpreting jpeg image file not a jpeg file starts with 0x52 0x49
  • Error internet unrecognized scheme