1

Im using "web3": "^1.0.0-beta.37"

And I want to understand How can I send rawTransaction

My code is:

const pk = 'xxxxxxx';
const rawTransaction = {
    "to": "0xa53709839ab6Da3ad9c1518Ed39a4a0fFCbA3684",
    "value": web3.utils.toWei('1', 'wei'),
    "gas": 2000000,
    "chainId": 3
};
let signedTx = await web3.eth.accounts.signTransaction(rawTransaction, pk).catch(console.dir);
let sendTx = await web3.eth.sendSignedTransaction(signedTx.rawTransaction).catch(console.error);

My account has 4Eth (on ropsten) and my httpProvider is ropsten (using infura)

but I get this error

Error: Returned error: insufficient funds for gas * price + value

I follow:

https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html?highlight=signTransaction#signtransaction

and then

https://web3js.readthedocs.io/en/1.0/web3-eth.html#eth-sendsignedtransaction

10
  • Most of the time when I receive that error it's due to not being fully synced with the chain. Make sure you're fully synchronized. Dec 21, 2018 at 11:25
  • @LauriPeltonen thanks for reply, I don't have ropsten locally, I use infura to broadcast my TX. It's wrong ?
    – monkeyUser
    Dec 21, 2018 at 11:30
  • Oh, if you use Infura then it's synchronized. Another thing I noticed is that I'm unsure if toWei supports decimal numbers - just to be sure use only integers. Check details: web3js.readthedocs.io/en/1.0/web3-utils.html#towei Dec 21, 2018 at 11:45
  • why from field is missing in your raw transaction?, Try adding it and run.
    – Aniket
    Dec 21, 2018 at 12:02
  • Shouldn't 21000 gas be enough for this type of transaction? Dec 21, 2018 at 12:14

3 Answers 3

3

Well, the message is saying that you don’t have funds. Here’s what you can do:

  1. Double check that the pk you are using to sign that transaction is actually the private key of the account with enough balance.

  2. Double check the web3 provider is actually pointing to the same network you have ethers in. Are you sure the infura node is connected to ropsten?

  3. Try to execute getBalance() for that account and verify the output is displaying correctly your balance

6
  • 1. Im sure, Can I verify the integrity of signature ? 2. yes, the url is ropsten.infura.io/v3/API_KEY 3. await web3.eth.getBalance(address) => 12285448249427863490
    – monkeyUser
    Dec 21, 2018 at 15:38
  • Add a ‘from’ parameter to the transaction object with value your address
    – abed
    Dec 21, 2018 at 15:43
  • I try but not lucky
    – monkeyUser
    Dec 21, 2018 at 15:46
  • Then the problem is probably from the private key that you are using, I think it’s not correct
    – abed
    Dec 21, 2018 at 15:49
  • 1
    I get PK from metamask
    – monkeyUser
    Dec 21, 2018 at 15:49
2

@abed Thanks for your reply and your suggests, the problem is PK, I have to add 0x before my PK that I get form Metamask

https://github.com/ethereum/web3.js/issues/1094

1
  • awesome. This saves my life! Feb 21, 2019 at 7:45
0

nonce, gasPrice and gasLimit must be in hex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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