1

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;
console.log(gasPrice);
const gasPriceHex = web3.toHex(gasPrice);
var glimit = web3.eth.getBlock("latest").gasLimit;
console.log(glimit);
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,
    to:contractAddress,
    from:account1,
    value: web3.toHex(web3.toWei('.01', 'ether')),
    data: payloadData
};
2
  • 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? – libertylocked Sep 4 '17 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 '17 at 13:11
1

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,
    to:contractAddress,
    from:account1,
    value: 0.1,
    data: payloadData
};
0

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

Example:

>>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, privacy policy and cookie policy

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