I was trying to create my own wallet on etherum test network Rinkeby. When I successfully created wallet:

const newAccount = await web3.eth.accounts.create()

and got wallet address 0x267634Db8890Ad1F05e214dD9De961484c078895 and wallet private key 0x27fc2c9ba1cba2c519f5423ab4dde5777cfe1f4d462c5bb64ba223a570f3efeb

I added some test ether on my new account (3 ether) , and tried to send some value on other account which I was also create

const main = async () => {
  let nonce = await web3.eth.getTransactionCount(web3.eth.defaultAccount)
  let gasPrices = await getCurrentGasPrices()
  let details = {
    "value": amountToSend,
    "gas": 21000,
    "gasPrice": gasPrices.low * 1000000000, 
    "nonce": nonce,
    "chainId": 4,
  const transaction = new EthereumTx(details, { chain: 'rinkeby', hardfork: 'petersburg' })
  await transaction.sign(Buffer.from(PRIVATE_KEY_DESTINATION_ACCOUNT, 'hex'))
  const serializedTransaction = await transaction.serialize()
  const transactionId = await web3.eth.sendSignedTransaction('0x' + serializedTransaction.toString('hex') )


but i got error message : "private key length is invalid", and when I cleared 0x from my private key I got other error "insufficient funds for gas * price + value"

Can anyone help me?

  • 1
    await transaction.sign(Buffer.from(PRIVATE_KEY_DESTINATION_ACCOUNT.substring(2), 'hex')) should help – Baracuda Aug 6 at 15:21
  • Or slice(2)... – goodvibration Aug 6 at 17:30
  • I found solution ..I created wallet using command : web3.eth.accounts.create() ,but I forgot encrypt that wallet .. I added web3.eth.accounts.encrypt(privateKey, password), and now I can send etherium from that wallet – gaboja__ Aug 7 at 12:02
  • Also I had to remove 0x from my private key – gaboja__ Aug 7 at 12:08

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.