1

Was wondering if anyone has come across this before. I am using Ropsten through Infura and no matter what I set the gas to it will always return either transaction underpriced or exceeds block gas limit.

  • 1
    It sounds like the function you're calling uses too much gas. What are you trying to call? – Edmund Edgar Sep 12 '17 at 19:28
  • When you say "no matter what I set the gas to", that's vague because there's gas price and gas limit. Which one are you changing? What are the current values? What are you calling? There isn't enough information here to diagnose anything. – jordaniac89 Nov 14 '17 at 15:52
1

I had this problem recently but it was my own error. Here's how to debug it.

First let's deal with the "transaction underpriced" error. Call web3.eth.getBalance(address,console.log).

Does the address you are sending from have the balance you expect? If not, you may be connected to a mainnet node, or you may have sent Ether to this address on the wrong network. You may just need to visit the Ropsten faucet to get coins.

Now you have the upper bound for your gas*gasPrice + value that will throw the transaction underPriced error.

Second, Web3 has some helper functions like estimateGas (returns Wei) and getGasPrice (returns Gwei) that will help you determine the best gas settings for your contract. Multiply the returned gas price by 1.5. Use the function web3.utils.toWei to convert your address balance, gasPrice, and value to Wei. Remember to set "Gwei" as the second argument for the gasPrice in toWei

Now you have all your details in Wei. Is gas*gasPrice + value < addressBalance? Do you still get the exceeds block gas limit? The 1.5 multiplier was necessary for this to work for me.

0

Just increase gasPrice and gasLimit. For example

gasPrice: 400000000000,
gasLimit: 4000000,
0

Check the gas limit of the most recently mined block( you can find this from etherscan home page for Ropsten in your case). Set the gas limit closer to that. Then decrease the gas price. For me it worked when gas price was set to 10 Gwei but it could vary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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