trying to compile a contract and then send it to the network. The current error I'm getting is

Error: transaction underpriced

Here is my code for compiling the rawTx. I'm on Ropsten, and the gas price is: 21000000000 and the gasLimit latest is: 4712388(from the console.logs)

const gasPrice = web3.eth.gasPrice;
const gasPriceHex = web3.toHex(gasPrice);
var glimit = web3.eth.getBlock("latest").gasLimit;
gasLimitHex = web3.toHex(glimit);

nonce =  web3.eth.getTransactionCount(account1) ;
nonceHex = web3.toHex(nonce);

var payloadData = solidityFunction.data;

var rawTx = {
    nonce: nonceHex,
    gasPrice: gasPriceHex,
    gasLimit: gasLimitHex,
    value: web3.toHex(web3.toWei('.01', 'ether')),
    data: payloadData
  • 1
    Your gasLimit is set to be the latest block's gas limit, don't use that. Try web3.eth.estimateGas and set gas of the rawTx. Also, shouldn't to be 0? Sep 4, 2017 at 4:13
  • 1
    Thanks for the estimateGas solution. I'm still getting the underpriced error though. The to field is the contract address I'm trying to call and the payload data is the function bytecode
    – thefett
    Sep 4, 2017 at 13:11

2 Answers 2


no need hex data, web3 will deal with it.

var rawTx = {
    nonce: web3.eth.getTransactionCount(account1),
    gasPrice: web3.eth.gasPrice;,
    gasLimit: web3.eth.getBlock("latest").gasLimit,
    value: 0.1,
    data: payloadData

After you get the nonce of some account, you should add 1 as the new nonce of rawTx.


>>nonce =  web3.eth.getTransactionCount(account1) ;
>>nonceHex = web3.toHex(nonce);

I cannot find more data from the code of "payloadData", it is another way to make mistake.

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.