this errro PS C:\Users\lidor\Desktop\Trade Bot> node . <ref *1> Error: cannot estimate…
- User
this errro PS C:\Users\lidor\Desktop\Trade Bot> node . <ref *1> Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={“reason”:“cannot estimate gas; transaction may fail or may require manual gas limit”,“code”:“UNPREDICTABLE_GAS_LIMIT”,“error”:{“reason”:“processing response error”,“code”:“SERVER_ERROR”,“body”:“{“jsonrpc”:“2.0”,“id”:58,“error”:{“code”:-32000,“message”:“gas required exceeds allowance (0)”}}”,“error”:{“code”:-32000},“requestBody”:“{“method”:“eth_estimateGas”,“params”:[{“type”:“0x2”,“maxFeePerGas”:“0xe0a7358a2”,“maxPriorityFeePerGas”:“0x59682f00”,“from”:“0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266”,“to”:“0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”}],“id”:58,“jsonrpc”:“2.0”}”,“requestMethod”:“POST”,“url”:“https://mainnet.infura.io/v3/2d5bc62bb8d748cebfc64763e719cb4f"},“method”:“estimateGas”,“transaction”:{“from”:“0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266”,“maxPriorityFeePerGas”:{“type”:“BigNumber”,“hex”:“0x59682f00”},“maxFeePerGas”:{“type”:“BigNumber”,“hex”:“0x0e0a7358a2”},“to”:“0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”,“type”:2,"accessList”:null}}, tx={“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”,“to”:{},“from”:“0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266”,“type”:2,“maxFeePerGas”:{“type”:“BigNumber”,“hex”:“0x0e0a7358a2”},“maxPriorityFeePerGas”:{“type”:“BigNumber”,“hex”:“0x59682f00”},“nonce”:{},“gasLimit”:{},“chainId”:{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.7.0) at Logger.makeError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:238:21) at Logger.throwError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:247:20) at C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\abstract-signer\lib\index.js:365:47 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Promise.all (index 7) { reason: ‘cannot estimate gas; transaction may fail or may require manual gas limit’, code: ‘UNPREDICTABLE_GAS_LIMIT’, error: Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: ] (error={“reason”:“processing response error”,“code”:“SERVER_ERROR”,“body”:“{“jsonrpc”:“2.0”,“id”:58,“error”:{“code”:-32000,“message”:“gas required exceeds allowance (0)”}}”,“error”:{“code”:-32000},“requestBody”:“{“method”:“eth_estimateGas”,“params”:[{“type”:“0x2”,“maxFeePerGas”:“0xe0a7358a2”,“maxPriorityFeePerGas”:“0x59682f00”,“from”:“0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266”,“to”:“0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”}],“id”:58,“jsonrpc”:“2.0”}”,“requestMethod”:“POST”,“url”:“, method=“estimateGas”, transaction={“from”:“0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266”,“maxPriorityFeePerGas”:{“type”:“BigNumber”,“hex”:“0x59682f00”},“maxFeePerGas”:{“type”:“BigNumber”,“hex”:“0x0e0a7358a2”},“to”:“0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”,“type”:2,“accessList”:null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.2) at Logger.makeError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:238:21) at Logger.throwError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:247:20) at checkError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\providers\lib\json-rpc-provider.js:175:16) at JsonRpcProvider. (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\providers\lib\json-rpc-provider.js:751:47) at step (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\providers\lib\json-rpc-provider.js:48:23) at Object.throw (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\providers\lib\json-rpc-provider.js:29:53) at rejected (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\providers\lib\json-rpc-provider.js:21:65) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { reason: ‘cannot estimate gas; transaction may fail or may require manual gas limit’, code: ‘UNPREDICTABLE_GAS_LIMIT’, error: Error: processing response error (body=“{“jsonrpc”:“2.0”,“id”:58,“error”:{“code”:-32000,“message”:“gas required exceeds allowance (0)”}}”, error={“code”:-32000}, requestBody=“{“method”:“eth_estimateGas”,“params”:[{“type”:“0x2”,“maxFeePerGas”:“0xe0a7358a2”,“maxPriorityFeePerGas”:“0x59682f00”,“from”:“0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266”,“to”:“0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”}],“id”:58,“jsonrpc”:“2.0”}”, requestMethod=“POST”, url=“, code=SERVER_ERROR, version=web/5.7.1) at Logger.makeError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:238:21) at Logger.throwError (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\logger\lib\index.js:247:20) at C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\web\lib\index.js:313:32 at step (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\web\lib\index.js:33:23) at Object.next (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\web\lib\index.js:14:53) at fulfilled (C:\Users\lidor\Desktop\Trade Bot\node_modules@ethersproject\web\lib\index.js:5:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { reason: ‘processing response error’, code: ‘SERVER_ERROR’, body: ‘{“jsonrpc”:“2.0”,“id”:58,“error”:{“code”:-32000,“message”:“gas required exceeds allowance (0)”}}’, error: [Error], requestBody: ‘{“method”:“eth_estimateGas”,“params”:[{“type”:“0x2”,“maxFeePerGas”:“0xe0a7358a2”,“maxPriorityFeePerGas”:“0x59682f00”,“from”:“0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266”,“to”:“0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2”,“data”:“0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff”}],“id”:58,“jsonrpc”:“2.0”}’, requestMethod: ‘POST’, url: ‘ }, method: ‘estimateGas’, transaction: { from: ‘0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266’, maxPriorityFeePerGas: [BigNumber], maxFeePerGas: [BigNumber], to: ‘0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2’, data: ‘0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’, type: 2, accessList: null } }, tx: { data: ‘0x095ea7b3000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff’, to: Promise { ‘0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2’ }, from: ‘0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266’, type: 2, maxFeePerGas: BigNumber { _hex: ‘0x0e0a7358a2’, _isBigNumber: true }, maxPriorityFeePerGas: BigNumber { _hex: ‘0x59682f00’, _isBigNumber: true }, nonce: Promise { 467 }, gasLimit: Promise { [Circular *1] }, chainId: Promise { 1 } } } Error: undefined is not a valid address. at Object.validateAndParseAddress (C:\Users\lidor\Desktop\Trade Bot\node_modules@uniswap\sdk-core\dist\sdk-core.cjs.development.js:527:11) at Function.swapCallParameters (C:\Users\lidor\Desktop\Trade Bot\node_modules@uniswap\v3-sdk\dist\v3-sdk.cjs.development.js:3994:29) at main (C:\Users\lidor\Desktop\Trade Bot\index.js:47:41) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) PS C:\Users\lidor\Desktop\Trade Bot> with this code const { ethers } = require(‘ethers’); const { Token, CurrencyAmount, Percent, TradeType } = require(‘@uniswap/sdk-core’); const { Pool, Route, Trade, SwapRouter } = require(‘@uniswap/v3-sdk’); const IUniswapV3PoolABI = require(‘@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json’).abi; const Quoter = require(‘@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json’).abi; const IERC20 = require(‘@uniswap/v2-periphery/build/IERC20.json’);
- Assistant
The error "Error: undefined is not a valid address" is likely due to the
SWAP_ROUTER_ADDRESSbeing set to an incorrect value, or a value that cannot be resolved to a valid Ethereum address. Make sure you have the correct Swap Router contract address set in this line:const SWAP_ROUTER_ADDRESS = '0xe592427a0aece92de3edee1f18e0157c05861564';Also, the code snippet you shared seems to have incorrect formatting for some strings and variables. The following lines need to be fixed:
- Replace the
WALLET_ADDRESSandWALLET_SECRETwith hexadecimal string format (add quotes):
const WALLET_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'; const WALLET_SECRET = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';- Encode the
INFURA_TEST_URLstring in quotes:
const INFURA_TEST_URL = "https://mainnet.infura.io/v3/2d5bc62bb8d748cebfc64763e719cb4f";Make these changes and try running the code again to see if that resolves the issue. If the problem still persists, please provide more details or share the error message.
- Replace the
- User
- Assistant
Thank you for sharing the updated code. By reviewing it, I found a possible reason for the "Error: undefined is not a valid address" error.
Before the
const txobject is defined, this line is trying to estimate gas for the transaction:const gasEstimate = await provider.estimateGas({ ...tx, gasLimit: ethers.BigNumber.from('100000'), });The problem with this line is that you have not yet defined
txat this point in the code, which means it's spreading an undefined object. The error is related to this...txpart inside theestimateGasmethod call.To fix the error, remove the line that estimates the gas and set the gas limit directly when defining the
txobject. Update your code as follows:Replace this part:
const gasEstimate = await provider.estimateGas({ ...tx, gasLimit: ethers.BigNumber.from('100000'), }); const tx = { data: methodParameters.calldata, to: methodParameters.address, value: methodParameters.value, gasLimit: gasEstimate, gasPrice: await provider.getGasPrice(), };