2

I am signing this raw transaction and I can't seem to find the correct gas parameters to make the transaction valid. The from address/private key has over 3 ETH as seen here: https://rinkeby.etherscan.io/address/0x22dd8860db83a962e8d2ec734eae62fab63e73ae

    var Web3 = require("web3")
    var web3 = new Web3("https://rinkeby.infura.io/TOKEN")
    var privateKey =
      "PRIVATE_KEY"

    var account = web3.eth.accounts.wallet.add(privateKey)

    var tx = {
      chainId: 4,
      from: "22dd8860db83a962e8d2ec734eae62fab63e73ae",
      gas: "12880",
      gasPrice: web3.utils.toWei("0.0000000001", "ether"),
      nonce: "0x0",
      to: "0x8a09e76a5255E3d07854647f4DBef7323F98323d",
      value: web3.utils.toWei(".000001", "ether")
    }

    var signed = account.signTransaction(tx)

    web3.eth.sendSignedTransaction(signed.rawTransaction).then(console.log)

I also tried converting to Hex and I receive the same error:

var tx = {
  chainId: 4,
  from: "22dd8860db83a962e8d2ec734eae62fab63e73ae",
  gas: web3.utils.toHex("21000"),
  gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
  nonce: "0x0",
  to: "0x8a09e76a5255E3d07854647f4DBef7323F98323d",
  value: web3.utils.toHex(web3.utils.toWei(".000001", "ether"))
}
  • If you are sending ethers only (without any data) try gas of 21000. – Prashant Prabhakar Singh Nov 17 '17 at 18:12
  • I tried your suggestion and received the same error message. I'm not sure what I am doing wrong... – John Heeter Nov 17 '17 at 19:16
  • Oh, wait. Sorry I didn't absorb the error message correctly. This error is because may not have sufficient ethers, Check balance of your from address (22dd8860db83a962e8d2ec734eae62fab63e73ae). – Prashant Prabhakar Singh Nov 17 '17 at 20:55
  • I am signing this raw transaction and I can't seem to find the correct gas parameters to make the transaction valid. The from address/private key has over 3 ETH as seen here: rinkeby.etherscan.io/address/… – John Heeter Nov 17 '17 at 23:58
  • @JohnHeeter can You do console.log(account) to see if wallet address is correct? – num8er Nov 18 '17 at 3:48
9

I found the problem with the help of @num8er so I will document the issue here:

I used the BlockCypher API service to generate the key pairs. What I did not notice, is that Blockcypher removes the 0x from the addresses. When the 0x is not present, web3 generates the incorrect public address. This is why it kept giving me the error "insufficient funds".

if privateKey = "ec5fd9511901a87615d93ba088b4cce57a376efc9176ca5a9caa783607fe9e87"

account = web3.eth.accounts.wallet.add(privateKey)

> { address: '0x46c1e3E78A2Fc28943f2BD637e8b615e8906BB8F', privateKey: 'ec5fd9511901a87615d93ba088b4cce57a376efc9176ca5a9caa783607fe9e87', signTransaction: [Function: signTransaction], sign: [Function: sign], encrypt: [Function: encrypt], index: 0 }

if privateKey ="0xec5fd9511901a87615d93ba088b4cce57a376efc9176ca5a9caa783607fe9e87"

account = web3.eth.accounts.wallet.add(privateKey)

> { address: '0x22DD8860db83a962E8d2ec734eAE62faB63e73aE', privateKey: '0xec5fd9511901a87615d93ba088b4cce57a376efc9176ca5a9caa783607fe9e87', signTransaction: [Function: signTransaction], sign: [Function: sign], encrypt: [Function: encrypt], index: 0 }

  • I think You've to delete this answer and repost it with some gibberish private key ;) or better change private key also for You wallet. It's Private key not public))) – num8er Nov 18 '17 at 4:05
  • 1
    Yeah you are correct, thankfully I'm not using this key to hold any real funds. – John Heeter Nov 18 '17 at 4:06
  • 1
    thanks man, I had the same issue trying to hunt it down for hours (I just copy pasted my private key from metamask export private key) – szerte Mar 7 '18 at 1:48
  • Thanks for this, I spent too much time getting various error messages only to realize this was the issue. It would be nice if web3.eth.accounts.signTransaction(tx, privateKey) & account.signTransaction(tx) threw an error if the private key doesn't have the leading '0x' ! – Chuck Bergeron Jun 26 '18 at 22:09

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.