I am looking into getting the public key from ANY ethereum address (not owned by me) that has sent a transaction at least once. It seems that the most viable solution here would be to use ethereumjs-utils

 * ECDSA public key recovery from signature
 * @param {Buffer} msgHash
 * @param {Number} v
 * @param {Buffer} r
 * @param {Buffer} s
 * @return {Buffer} publicKey
exports.ecrecover = function (msgHash, v, r, s) {
  var signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64)
  var recovery = v - 27
  if (recovery !== 0 && recovery !== 1) {
    throw new Error('Invalid signature v value')
  var senderPubKey = secp256k1.recover(msgHash, signature, recovery)
  return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)

The user mentions that

when you send a transaction, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then pass these v r and s values and the has of the transaction back into a function and it'll spit out the public key

This last step is completely unclear to me. I do not understand how we parse "v", "r" and "s".

Picking a random transaction hash on Etherscan.io, how are we going to "parse" the v,r and s parameters?

1 Answer 1


If you have the transaction hash you can call eth_getTransactionByHash which will return the parsed fields of transaction including r, s and v.

    "blockNumber":"0x5daf3b", // 6139707
    "gas":"0xc350", // 50000
    "gasPrice":"0x4a817c800", // 20000000000
    "nonce":"0x15", // 21
    "transactionIndex":"0x41", // 65
    "value":"0xf3dbb76162000", // 4290000000000000
    "v":"0x25", // 37

Your Answer

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

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