2

I want to get public key from transaction.

For example, TXID : 0x191095343fd26cbb4c58996aa6512d5cdf43281d565072bab8d0d5ea9e3d644e

I have tried "Get Raw Transaction Hex" in etherscan and use https://toolkit.abdk.consulting/ethereum#recover-address

but it says "invalid rlp data"

I referenced this : Get public key of any ethereum account

But i think the solution is not working now.

Am i wrong? and how can I get public key from transaciton?

3 Answers3

0

Usually, by using the mentioned method(s), you won't be able to get the public key of an Ethereum account if that transaction has no spend transactions. It happens the same with BTC. Without the private key, you can get the public key of the address only if it has spend transactions.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Dec 13 '21 at 22:06
0

That TX is a type 2 transaction (raw data starts with 0x02....), as per EIP-1559, which changes the transaction format. The ABDK toolkit seems compatible only with legacy transactions (EIP-155), hence giving the error.

orutra
  • 1
0

Got this code from Reddit.

from hexbytes import HexBytes
from coincurve import PublicKey as CCPublicKey
from eth_account._utils.signing import to_standard_v
from eth_account._utils.legacy_transactions import serializable_unsigned_transaction_from_dict
from eth_keys.datatypes import Signature
from eth_rlp import HashableRLP
from web3 import Web3

INFURA_URL_MAINNET = "..." INFURA_URL_TESTNET = "..."

def pub_key_from_tx_eth(txid, chain): """Obtain the public key from an Ethereum transaction """ w3test = Web3(Web3.HTTPProvider(INFURA_URL_TESTNET)) transaction = w3test.eth.get_transaction(txid) vrs = (to_standard_v(transaction['v']), int.from_bytes(transaction['r'], "big"), int.from_bytes(transaction['s'], "big")) signature = Signature(vrs=vrs)
tx_dict = {'nonce': transaction.nonce, 'gasPrice': transaction.gasPrice, 'gas': transaction.gas, 'to': transaction.to, 'value': transaction.value } if chain == "ETH": tx_dict['chainId'] = "0x01" elif chain == "tETH": tx_dict['chainId'] = "0x03" if 'input' in transaction: tx_dict['data'] = transaction['input'] serialized_tx = serializable_unsigned_transaction_from_dict(tx_dict) rec_pub = signature.recover_public_key_from_msg_hash(serialized_tx.hash()) if rec_pub.to_checksum_address() != transaction['from']: raise ValueError("Unable to obtain public key from transaction: " + f"{txid}") return(rec_pub)

Original post: https://www.reddit.com/r/ethdev/comments/poqlb4/recover_a_public_key_from_a_transaction/