I am using web3 and infura node to send my raw transaction but I am having difficulty in setting gasprice. I constructed rawtransaction as follows

 web3js.eth.getTransactionCount(myAddress, 'pending').then(function(v){
             count = v+1;
             var transfer =  contract.methods.createdegree(uniquekey);
             var encodedABI = transfer.encodeABI();
             const rawTransaction = {
                            "nonce": count,
                            "from": "xxx",
                            "to": "xxx",
                            "value": 0,
                            "gas": 566540,
                            "data": encodedABI,
                            "chainId": 1

           var transaction = new Tx(rawTransaction);
           var signedtx = '0x'+transaction.serialize().toString('hex');
           var transactionidfinal = new Tx(signedtx).hash().toString('hex');
           var transactionidfinaldated = '0x'+transactionidfinal;
           var transactionarray = [transactionidfinaldated,signedtx];



But I noticed that in etherscan gasprice is shown as 0.85879608 Gwei. which is very low considering market price . Here is an example transaction https://etherscan.io/tx/0x91d0bc123de43cc182c5ef6da363c7cfb723830066c055f1c324b664859705cb .

Am I doing something wrong here?

How can I set 3 Gwei gasprice in my raw transaction?

  • 0.85879608 Gwei = 85879608 > 3000. So etherscan gas price is in fact much higher than your configuration. A gwei is "1" followed by 9 zeros, so if you want 3 gwei, then use "3" followed by 9 zeros. – goodvibration May 7 '19 at 15:42
  • @goodvibration What unit is used by GasPrice in raw transaction? if I want to set 3 Gwei then how can I set in my raw transaction? Also should I define my value inside double quotes or without quotes? – mohammad obaid May 7 '19 at 15:46
  • What part of if you want 3 gwei, then use "3" followed by 9 zeros did you not understand??? – goodvibration May 7 '19 at 15:56
  • "What unit is used by GasPrice in raw transaction?" <-- It's in wei. Double quotes is not necessary for the sort of numbers you'll be using, but it's a good practice just because numbers in JavaScript have somewhat low precision. – user19510 May 7 '19 at 17:19

Your Answer

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

Browse other questions tagged or ask your own question.