Skip to main content

Legacy Account Key

Import necessary utils from eth_utils and eth_account

Import extend from web3py_ext to extend web3 to kaia web3

Define a wallet from private key using Account.from_key

Define any message to sign

Format the message using encode_defunct to make it compatible with EIP-191 standard.

Sign the transaction with the created account

Recover sender address with Account.recover_message from signed message

web3_legacy_value_transfer_message_recover.py

from eth_account import Account
from eth_account.messages import encode_defunct
from eth_utils.curried import to_hex
from web3py_ext import extend
def web3_legacy_value_transfer_sign_recover():
user = Account.from_key('0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8')
message_text = "I♥KLAYTN"
msghash = encode_defunct(text=message_text)
signature = Account.sign_message(msghash, user.key)
recovered = Account.recover_message(msghash, signature=signature.signature)
print("\nsender", user.address, "\nrecovered", recovered)
web3_legacy_value_transfer_sign_recover()

output

❯ python web3_legacy_value_transfer_message_recover.py
sender 0xA2a8854b1802D8Cd5De631E690817c253d6a9153
recovered 0xA2a8854b1802D8Cd5De631E690817c253d6a9153

Make this page better