4

I try to create and sign a transaction using ethereumjs-tx, as follows: (same code as in here, except the private key)

var Transaction = require('ethereumjs-tx')
var tx = new Transaction()
tx.nonce = 0
tx.gasPrice = 100
tx.gasLimit = 1000
tx.value = 0
tx.data = '0x7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d6552656700000000000000000000000000000000000000000000000000573360455760415160566000396000f20036602259604556330e0f600f5933ff33560f601e5960003356576000335700604158600035560f602b590033560f60365960003356573360003557600035335700'
var privateKey = new Buffer ('8ad6...........................................................', 'hex')
tx.sign(privateKey)
console.log("tx.from = "+tx.getSenderAddress().toString('hex'));

For privateKey, the first argument I supply is the value of "ciphertext" in my private key file (64 characters). However, in the last line, the address generated does not match my account's address. Am I doing something wrong?

My address is on testnet. Is this library only valid for the mainnet? I don't think so, moreover, I think private key files are interchangeable among the two networks, but I'm not sure.

Thanks for any help,

Update

According to this answer, the text I copy-pasted from the keystore file is not the private key, but its encrypted version with my passphrase. Decrypting it leads to the question How do I get the raw private key from my Mist keystore file?

  • If you have another question, just ask it by clicking the Ask Question button. This will help with visibility of the follow-up question. – Waqar Lim Jan 10 '17 at 9:25
3

I solved my problem by using helpeth as follows:

helpeth --password 'my_password' --keyfile 'path_to/keystore/UTC--filename'  --show-private keyDetails

which gave me the correct private key that can derive my address.

However this doesn't look like a safe solution since it requires the users to send their private key files to the server. Can I obtain this private key in the browser JS, without it being uploaded to the server?

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.