Wallet¶
The implementation of Hierarchical Deterministic (HD) wallets generator for Ethereum blockchain.
- class swap.providers.ethereum.wallet.Wallet(network: str = 'mainnet', provider: str = 'http', token: Optional[str] = None)¶
Ethereum Wallet class.
- Parameters
network (str) – Ethereum network, defaults to
mainnet
.provider (str) – Ethereum network provider, defaults to
http
.token (str) – Infura API endpoint token, defaults to
4414fea5f7454211956b1627621450b4
.
- Returns
Wallet – Ethereum wallet instance.
Note
Ethereum has only five networks,
mainnet
,ropsten
,kovan
,rinkeby
andtestnet
.- from_entropy(entropy: str, language: str = 'english', passphrase: Optional[str] = None) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from entropy.
- Parameters
entropy (str) – Ethereum wallet entropy.
language (str) – Ethereum wallet language, default to
english
.passphrase (str) – Ethereum wallet passphrase, default to
None
.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_mnemonic(mnemonic: str, language: Optional[str] = None, passphrase: Optional[str] = None) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from mnemonic.
- Parameters
mnemonic (str) – Ethereum wallet mnemonic.
language (str) – Ethereum wallet language, default to
english
.passphrase (str) – Ethereum wallet passphrase, default to
None
.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_mnemonic(mnemonic="unfair divorce remind addict add roof park clown build renew illness fault") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_seed(seed: str) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from seed.
- Parameters
seed (str) – Ethereum wallet seed.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_seed(seed="1cfd5df8a523d53a36cee369a93fac4e9efab5e4e138d479da2fb6df730697574409d572fe8325ec22e8ed25dea7495f498c3f5235fe6ae6d47b989267b6777c") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_root_xprivate_key(xprivate_key: str, strict: bool = True) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from root xprivate key.
- Parameters
xprivate_key (str) – Ethereum wallet root xprivate key.
strict (bool) – Strict for must be root xprivate key, default to
True
.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_root_xprivate_key(xprivate_key="xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_xprivate_key(xprivate_key: str) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from xprivate key.
- Parameters
xprivate_key (str) – Ethereum wallet xprivate key.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_xprivate_key(xprivate_key="xprvA3xrxQQVw6Kvc786WAccK4H7dLHhnb9XRsMUMqU3bJoZf5bWxtd5VePTNnn854tEbvV57ggjqkGHXc2u4Jx2veJzXRS1mBuokqz1aXL6tDW") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_wif(wif: str) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from wallet important format (WIF).
- Parameters
wif (str) – Ethereum wallet important format.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_wif(wif="L4AfqFc8aoBWYNTKU6PkiFbP9kbXRfVHXZWde6SpAdTewwJMc5VZ") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_private_key(private_key) → swap.providers.ethereum.wallet.Wallet¶
Initialize wallet from private key.
- Parameters
private_key (str) – Ethereum wallet private key.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_private_key(private_key="cf4c2fb2b88a556c211d5fe79335dcee6dd11403bbbc5b47a530e9cf56ee3aee") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_path(path: str) → swap.providers.ethereum.wallet.Wallet¶
Drive Ethereum wallet from path.
- Parameters
path (str) – Ethereum wallet path.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- from_index(index: int, hardened: bool = False) → swap.providers.ethereum.wallet.Wallet¶
Drive Ethereum wallet from index.
- Parameters
index (int) – Ethereum wallet index.
hardened (bool) – Use hardened index, default to
False
.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_index(44, harden=True) >>> wallet.from_index(60, harden=True) >>> wallet.from_index(0, harden=True) >>> wallet.from_index(0) >>> wallet.from_index(0) <swap.providers.ethereum.wallet.Wallet object at 0x040DA268>
- clean_derivation() → swap.providers.ethereum.wallet.Wallet¶
Clean derivation Ethereum wallet.
- Returns
Wallet – Ethereum wallet instance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path("m/44'/60'/0'/0/0") >>> wallet.path() "m/44'/60'/0'/0/0" >>> wallet.clean_derivation() <swap.providers.ethereum.wallet.Wallet object at 0x040DA268> >>> wallet.path() None
- strength() → Optional[int]¶
Get Ethereum wallet strength.
- Returns
int – Ethereum wallet strength.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.strength() 128
- entropy() → Optional[str]¶
Get Ethereum wallet entropy.
- Returns
str – Ethereum wallet entropy.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.entropy() "ed0802d701a033776811601dd6c5c4a9"
- mnemonic() → Optional[str]¶
Get Ethereum wallet mnemonic.
- Returns
str – Ethereum wallet mnemonic.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.mnemonic() "unfair divorce remind addict add roof park clown build renew illness fault"
- passphrase() → Optional[str]¶
Get Ethereum wallet passphrase.
- Returns
str – Ethereum wallet passphrase.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9", passphrase="meherett") >>> wallet.passphrase() "meherett"
- language() → Optional[str]¶
Get Ethereum wallet language.
- Returns
str – Ethereum wallet language.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.language() "english"
- seed() → Optional[str]¶
Get Ethereum wallet seed.
- Returns
str – Ethereum wallet seed.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.seed() "1cfd5df8a523d53a36cee369a93fac4e9efab5e4e138d479da2fb6df730697574409d572fe8325ec22e8ed25dea7495f498c3f5235fe6ae6d47b989267b6777c"
- root_xprivate_key(encoded: bool = True) → Optional[str]¶
Get Ethereum wallet root xprivate key.
- Parameters
encoded (bool) – Encoded root xprivate key, default to
True
.- Returns
str – Ethereum wallet root xprivate key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.root_xprivate_key() "xprv9s21ZrQH143K3Y3pdbkbjreZQ9RVmqTLhRgf86uZyCJk2ou36YdUJt5frjwihGWmV1fQEDioiGZXWXUbHLy3kQf5xmhvhp8dZ2tfn6tgGUj"
- root_xpublic_key(encoded: bool = True) → Optional[str]¶
Get Ethereum wallet root xpublic key.
- Parameters
encoded (bool) – Encoded root xprivate key, default to
True
.- Returns
str – Ethereum wallet root xpublic key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.root_xpublic_key() "xpub661MyMwAqRbcG28HjdHc6zbHxBFzBJBC4ecFvVKBXXqiucEBe5wirgQ9hzY2WQMjnurVjJbTjMWRskHi7jnSRkJdj4oRu4Vdh7Ln1F83mLJ"
- xprivate_key(encoded=True) → Optional[str]¶
Get Ethereum wallet xprivate key.
- Parameters
encoded (bool) – Encoded xprivate key, default to
True
.- Returns
str – Ethereum wallet xprivate key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.xprivate_key() "xprvA3xrxQQVw6Kvc786WAccK4H7dLHhnb9XRsMUMqU3bJoZf5bWxtd5VePTNnn854tEbvV57ggjqkGHXc2u4Jx2veJzXRS1mBuokqz1aXL6tDW"
- xpublic_key(encoded: bool = True) → Optional[str]¶
Get Ethereum wallet xpublic key.
- Parameters
encoded (bool) – Encoded xprivate key, default to
True
.- Returns
str – Ethereum wallet xpublic key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.xpublic_key() "xpub6GxDMuwPmTtDpbCZcC9cgCDrBN8CC3sNo6H5ADsf9eLYXsvfWRwL3ShwE5u4gxbPPcZj1yjSDrvvLxsHEPdjtFHHk81N2bskE2U7k9pmj9q"
- uncompressed() → str¶
Get Ethereum wallet uncompressed public key.
- Returns
str – Ethereum wallet uncompressed public key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.uncompressed() "e270f9d51cad2977c0a28182b9320bb5edc3c70e6d84ff5837f8d407ed9d676d447e195e1aff5494d1a0c8dc310c74692e053c2f27ab50c1ee7767a6b8a7be75"
- compressed() → str¶
Get Ethereum wallet compressed public key.
- Returns
str – Ethereum wallet compressed public key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.compressed() "03e270f9d51cad2977c0a28182b9320bb5edc3c70e6d84ff5837f8d407ed9d676d"
- chain_code() → str¶
Get Ethereum wallet chain code.
- Returns
str – Ethereum wallet chain code.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.chain_code() "9e5c492fa0a5c5cc649922c34ac3468a08473f3b61f59bba61b52cce364d6b0c"
- private_key() → str¶
Get Ethereum wallet private key.
- Returns
str – Ethereum wallet private key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.private_key() "cf4c2fb2b88a556c211d5fe79335dcee6dd11403bbbc5b47a530e9cf56ee3aee"
- public_key() → str¶
Get Ethereum wallet public key.
- Returns
str – Ethereum wallet public key.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path("m/44'/60'/0'/0/0") >>> wallet.public_key() "03e270f9d51cad2977c0a28182b9320bb5edc3c70e6d84ff5837f8d407ed9d676d"
- path() → Optional[str]¶
Get Ethereum wallet path.
- Returns
str – Ethereum wallet path.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.path() "m/44'/60'/0'/0/0"
- address() → str¶
Get Ethereum wallet address.
- Returns
str – Ethereum wallet address.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.address() "0x69e04fe16c9A6A83076B3c2dc4b4Bc21b5d9A20C"
- wif() → str¶
Get Ethereum wallet important format (WIF).
- Returns
str – Ethereum wallet important format.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.wif() "L4AfqFc8aoBWYNTKU6PkiFbP9kbXRfVHXZWde6SpAdTewwJMc5VZ"
- hash(private_key: Optional[str] = None) → str¶
Get Ethereum wallet public key/address hash.
- Returns
str – Ethereum wallet public key/address hash.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.hash() "184847379abdde6617e8438fd4ff0d8fdf512cc2"
- balance(unit: str = 'Wei') → Union[Wei, int, float]¶
Get Ethereum wallet balance.
- Parameters
unit (str) – Ethereum unit, default to
Wei
.- Returns
Wei, int, float – Ethereum wallet balance.
>>> from swap.providers.ethereum.wallet import Wallet >>> wallet: Wallet = Wallet(network="testnet") >>> wallet.from_entropy(entropy="ed0802d701a033776811601dd6c5c4a9") >>> wallet.from_path(path="m/44'/60'/0'/0/0") >>> wallet.balance(unit="Ether") 96.96263982