2

I'm creating new address with web3.py with this code:

from web3 import Web3 
w3 = Web3(Web3.HTTPProvider('http://localhost:8545')) 
w3.personal.newAccount('the-passphrase')

And have few questions:

  1. Is there a way to get the-passphrase from address returned from the code below? Need the same behaviour as dumpprivkey from bitcoin-cli
  2. Why I'm getting different addres every time when I'm using same passphrase? Does it means that I can use inputs of every of these addresses with using only this passhprase? Is structure of keys is different than bitcoin's privatekey-publickey-address?
  3. When I use signTransaction method, should I use 'passphrase' or its hash?

Thanks!

2

I think you may be confused about the purpose of the passphrase. The passphrase argument is not a seed for generating the private key, but a passphrase for encrypting the private key once it is generated.

When you call w3.personal.newAccount('the-passphrase') the node generates a random private key, derives the address from it, then encrypts the key using your passphrase and stores the encrypted key on disk. It then returns the address.

Thus, you can create as many unrelated accounts as you want, all encrypted by the same passphrase.


The core issue is that you probably should be using the eth_account library instead of the personal api. The account API is for constructing wallets and accounts in memory, client side, while the personal API is for managing accounts on the server side, on-disk. There is no way to fetch a server-side private key via web3, but if you construct the account client side then you can manually deal with private keys all you want.

See https://web3py.readthedocs.io/en/stable/web3.eth.account.html#working-with-local-private-keys for more examples

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.