I've been using local_account = w3.eth.account.create(keys['private_key_1'])
to create a local account offline. When I check the public key returned from local_account.address
it does not match the existing public key. What should I do?
P.S. The key returned is a string & I've tried changing the private key format from "0x12345" to "12345". I think this is a solution but I can't figure out how to instantiate the class and call the from_key method.
Best Answer
That's because the attribute of the function
w3.eth.account.create(...)
is not the private key.To generate an account from an external private key you must use the function
w3.eth.account.privateKeyToAccount(...)
.Example:
privateKeyToAccount
will be deprecated for version 0.5 and replaced byw3.eth.account.from_key(...)
.Example: