본문으로 건너뛰기

Public Account Key

AccountKeyPublic is used for accounts having one public key. If an account has an AccountKeyPublic object, the transaction validation process is done like below:

Import necessary utils from eth_utils, web3 and eth_account

Import extend from web3py_ext to extend web3 to kaia web3

Define a web3 connection using Web3.HTTPProvider and RPC endpoint

Also, you can change the provider URL from baobab to allthatnode

Define a wallet from private key using Account.from_key_pair which is a member key of your multisig account

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

Print out the signature and its length

Recover sender address with Account.recover_message from signed message

web3_public_value_transfer_message_recover.py

from eth_account import Account
from web3 import Web3
from eth_account.messages import encode_defunct
from eth_utils.curried import to_hex
from web3py_ext import extend
w3 = Web3(Web3.HTTPProvider('https://public-en-kairos.node.kaia.io'))
def web3_public_value_transfer_message_recover():
user = Account.from_key_pair(
'0xe15cd70a41dfb05e7214004d7d054801b2a2f06b',
'0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8'
)
message = to_hex(text="I♥KLAYTN")
msghash = encode_defunct(hexstr=message)
signature = Account.sign_message(msghash, user.key)
print(signature.signature.hex())
print(len(signature.signature.hex()))
recovered = w3.klay.recover_from_message(user.address, message, signature.signature.hex(), "latest")
print("\nsender", user.address, "\nrecovered", recovered)
web3_public_value_transfer_message_recover()

output

❯ python web3_public_value_transfer_message_recover.py
0x875445e2197ec28e913a1775a40ca8c5a0a9e1806c72e08e01a54caf2b65640d09ff852643df23277c46469ef7f5e84ed96c5553b6ad648a4255a0c5dca58bdc1c
132
sender 0xe15Cd70A41dfb05e7214004d7D054801b2a2f06b
recovered 0xa2a8854b1802d8cd5de631e690817c253d6a9153