#
ETH Account
ApeworX uses the package eth_account to create new accounts
Let's look at a few ways to create accounts with this package
#
create
Creates a new private key, and returns it as a LocalAccount
from eth_account import Account
acct = Account.create('KEYSMASH FJAFJKLDSKF7JKFDJ 1530')
print("Address:", acct.address)
print("Private key:", acct.privateKey.hex())
You can optionally add extra randomness to whatever randomness your OS can provide
#
create_with_mnemonic
Creates a new private key, and returns it as a LocalAccount, alongside the mnemonic that can be used to regenerate it using any BIP39-compatible wallet.
from eth_account import Account
Account.enable_unaudited_hdwallet_features()
acct, mnemonic = Account.create_with_mnemonic()
print("Address:", acct.address)
print("Private key:", acct.privateKey.hex())
print("Mnemonic:", mnemonic)
NOTE
enable_unaudited_hdwallet_features() Use this flag to enable unaudited HD Wallet features.
One set of mnemonic can be used to create multiple addresses. This method of generating account was introduced in BIP32 & BIP39
This BIP describes the implementation of a mnemonic code or mnemonic sentence — a group of easy to remember words — for the generation of deterministic wallets.
It consists of two parts: generating the mnemonic, and converting it into a binary seed. This seed can be later used to generate deterministic wallets using BIP-0032 or similar methods. Lets understand first part of it.
#
from_key
Returns a convenient object for working with the given private key.
from dotenv import dotenv_values
config = dotenv_values(".env")
user = Account.from_key(config.get('PRIVATE_KEY'))
#
from_mnemonic
Generate an account from a mnemonic.
user = Account.from_mnemonic("cheap gauge cradle profit fantasy report album water tobacco very tired smart")
To learn more about Ethereum accounts, see the Ethereum documentation