0

I am doing raw transaction to send token from one account to another. But I don't have private key of my account but i do have the password. How can I send raw transaction using my password only. Here is my code:

var Tx = require('ethereumjs-tx')
var Web3 = require('web3');
var web3 = new Web3(new 
Web3.providers.HttpProvider('https://rinkeby.infura.io/infurakey'));
var Personal = require('web3-eth-personal')
var personal = new Personal(Personal.givenProvider)

var ABI =[{"constant":true,......","type":"event"}]

var contract =new web3.eth.Contract(ABI, '0x9...5bf3f4f')

const account1 = "0xd94acc...5071240364364c86f45";
const account2 = "0xf7689d04139...ad668CBF2Af2D29";

web3.eth.getTransactionCount(account1,(err, txCount)=>{
const txObject ={
from: account1, 
nonce : web3.utils.toHex(txCount),
gasLimit: web3.utils.toHex(800000),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
to: '0x9...a42255bf3f4f',
data: contract.methods.transfer(account2, 1000).encodeABI()
 }
 var password = new Buffer("mypassword", 'hex');
 const tx = new Tx(txObject)

tx.sign(password);
const serializedTransaction = tx.serialize();

const raw = '0x' + serializedTransaction.toString('hex')
web3.eth.sendSignedTransaction(raw, (err, txHash)=> {
    console.log('err:', err, 'txHash:', txHash)
  })
})

I am getting error:

RangeError: private key length is invalid

1 Answer 1

1

Ethereum does not understand your password and cannot use it. Your password is only used within your client - it's typically used to encrypt the file which contains your private key. Password is therefore not directly linked to the private key in any way.

So whenever you want to use your private key the process goes something like this (at least in Geth, probably similar in other clients):

1) You unlock your account with password

2) Your client decrypts the file on-the-fly with your private key with the given password- The file itself remains always encrypted - the private key is only decrypted in memory.

3) Your client uses the private key to sign a transaction

So you also need access to the (enrypted) private key file. The password is useless by itself.

2

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.