How to get sender’s Ethereum address and public key from signed transaction.
1 min readAug 5, 2018
In this article, I’d like to explain how to get Ethereum address and public key of sender (who signs to transaction) from signed transaction.
Example of signed transaction
Below is an actual signed transaction which has been sent to Ropsten network: https://ropsten.etherscan.io/tx/0xf4727b35f10cbe2256b38adcc594f25854a7f16c8461e280079e7003a18d446d
0xf86b808504a817c800825208942890228d4478e2c3b0ebf5a38479e3396c1d6074872386f26fc100008029a0520e5053c1b573d747f823a0b23d52e5a619298f46cd781d677d0e5e78fbc750a075be461137c2c2a5594beff76ecb11a215384c574a7e5b620dba5cc63b0a0f13
Retrieve sender’s Ethereum address and public key
- Create a
Transaction
object of the ethereumjs-tx from the signed transaction. - Then use getSenderAddress() and getSenderPublicKey() method to get sender’s Ethereum address and public key.
const EthUtil = require('ethereumjs-util')
const EthTx = require('ethereumjs-tx')// signed tx
const signedTx = "0xf86b808504a817c800825208942890228d4478e2c3b0ebf5a38479e3396c1d6074872386f26fc100008029a0520e5053c1b573d747f823a0b23d52e5a619298f46cd781d677d0e5e78fbc750a075be461137c2c2a5594beff76ecb11a215384c574a7e5b620dba5cc63b0a0f13"// Create a tx object from signed tx
const tx = new EthTx(signedTx)// Get an address of sender
const address = EthUtil.bufferToHex(tx.getSenderAddress())// get a public key of sender
const publicKey = EthUtil.bufferToHex(tx.getSenderPublicKey())console.log(address)
// => 0x89c24a88bad4abe0a4f5b2eb5a86db1fb323832cconsole.log(publicKey)
// => 0xfff49b58b83104ff16875452852466a46c7169ba4e368d11830c9170624e0a9509080a05a38c18841718ea4fc13483ac467d3e2d728d41ff16b73b9c943734f8
Notes
- Internally ethereumjs-tx uses
ecrecover
to verify signature and get a public key. - Ethereum address can be calculated from a public key.
References
- https://scrapbox.io/sushiether/Ethereum_%E3%81%AE%E7%BD%B2%E5%90%8D%E6%B8%88%E3%81%BF%E3%83%88%E3%83%A9%E3%83%B3%E3%82%B6%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%8B%E3%82%89%E7%BD%B2%E5%90%8D%E3%81%97%E3%81%9F%E3%82%A2%E3%82%AB%E3%82%A6%E3%83%B3%E3%83%88%E3%81%AE%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%81%A8%E5%85%AC%E9%96%8B%E9%8D%B5%E3%82%92%E5%8F%96%E5%BE%97
- https://github.com/ethereumjs/ethereumjs-tx