0

I've seen this question here a lot, but just to restate for my purposes, I'm using truffle and attempting to monitor the blockchain for price swaps. I do not currently have a contract deployed but, I believe, I shouldn't need that just to watch it without running any transactions, right?

Solutions that I've seen are, effectively, that I need to declare gas and/or gasLimit. This is fine, but I have attempted it in many different places with no success. Specifically, in these places:

inside truffle-config.js

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*", 
      gasLimit: process.env.GAS_LIMIT
    },
    live: {
      provider: () => new HDWalletProvider(MNEMONIC, `wss://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`) 
    }
  }

//I should note I have also attempted to just add mainnet as the network here as you'll see above, but that also had no effect.


Inside deploy_contracts.js

module.exports = async function (deployer) {
    await deployer.deploy(
        Arbitrage,
        config.SUSHISWAP.V2_ROUTER_02_ADDRESS,
        config.UNISWAP.V2_ROUTER_02_ADDRESS,
        {gas: process.env.GAS_LIMIT}
    );
};

Inside my own methods like so:

await arbitrage.methods.executeTrade(startOnUniswap, _token0Contract._address, _token1Contract._address, amount).send({ from: account, gas: eth.getBlock("latest").gasLimit })

// I have also used web3.eth.estimateGas() and MyContract.methods.myMethod.estimateGas() in place of getBlock.gasLimit here

So far, each time I receive the same error. Here's the error stack:

Error: Returned error: err: intrinsic gas too low: have 0, want 21064 (supplied gas 0)
    at Object.ErrorResponse (/Users/Me/trading_bot_V2/node_modules/web3-core-helpers/lib/errors.js:28:19)
    at Object.callback (/Users/Me/trading_bot_V2/node_modules/web3-core-requestmanager/lib/index.js:300:36)
    at /Users/Me/trading_bot_V2/node_modules/web3-providers-ws/lib/index.js:114:45
    at Array.forEach (<anonymous>)
    at WebsocketProvider._onMessage (/Users/Me/trading_bot_V2/node_modules/web3-providers-ws/lib/index.js:102:69)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/Me/trading_bot_V2/node_modules/yaeti/lib/EventTarget.js:115:12)
    at W3CWebSocket.onMessage (/Users/Me/trading_bot_V2/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/Users/Me/trading_bot_V2/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (node:events:513:28)
    at WebSocketConnection.processFrame (/Users/Me/trading_bot_V2/node_modules/websocket/lib/WebSocketConnection.js:554:26)
    at /Users/Me/trading_bot_V2/node_modules/websocket/lib/WebSocketConnection.js:323:40
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  data: null
}

I'm bald or I'd be ripping my hair out on this one. Any thoughts?

**Update - as the module.exports method is concerned, I discovered that I could actually make things work. The problem is that I don't want to actually launch the contract until I've been able to watch live swaps for a brief time in order to verify a few things.

**Edit - I neglected to mention, but the gas, as you notice, is currently hardcoded in the .env file. I could put that amount at 21000, 21064, 0, 4000000, or 3999999. The result is the same.

1 Answer 1

0

Solved my own issue here.

Changed web3 = new Web3(`wss://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`)

To web3 = new Web3(Web3.givenProvider || wss://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY})

This change was made in my initialization file and my helper file. That's all that was seemingly needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.