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.
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.
JSONRPC doesn't require gasLimit or gasPrice by default. But if these fields are not set correctly, transaction underpriced error is occured. Because default gasPrice and gasLimit is too low. In my case, I encoded params twice. The signed result was valid JSONRPC format, but there's no field about gasLimit or gasPrice. Check your signed result using ethereum-tx-decoder. It will give you some insight.