HotWallet

Documentation for eth_defi.hotwallet.HotWallet class.

class HotWallet[source]

Hot wallet.

A hot wallet maintains an unecrypted private key of an Ethereum address in the process memory. It is able to sign transactions.

This particular hot wallet implementation carries the information of allocated tx nonces with us. This allows us to prepare multiple transactions from the same account upfront.

See also how to create private keys from command line.

Note

Not thread safe. Manages consumed nonce counter locally.

Attributes summary

address

Get address of the private key of the wallet.

Methods summary

__init__(account)

allocate_nonce()

Get the next free available nonce to be used with a transaction.

from_private_key(key)

Create a hot wallet from a private key that is passed in as a hex string.

get_native_currency_balance(web3)

Get the balance of the native currency (ETH, BNB, MATIC) of the wallet.

sign_transaction_with_new_nonce(tx)

Signs a transaction and allocates a nonce for it.

sync_nonce(web3)

Read the current nonce

__init__(account)[source]
Parameters

account (eth_account.signers.local.LocalAccount) –

property address

Get address of the private key of the wallet.

sync_nonce(web3)[source]

Read the current nonce

Parameters

web3 (web3.main.Web3) –

allocate_nonce()[source]

Get the next free available nonce to be used with a transaction.

Ethereum tx nonces are a counter.

Increase the nonce counter

Return type

int

sign_transaction_with_new_nonce(tx)[source]

Signs a transaction and allocates a nonce for it.

Param

Ethereum transaction data as a dict. This is modified in-place to include nonce.

Parameters

tx (dict) –

Return type

eth_defi.hotwallet.SignedTransactionWithNonce

get_native_currency_balance(web3)[source]

Get the balance of the native currency (ETH, BNB, MATIC) of the wallet.

Useful to check if you have enough cryptocurrency for the gas fees.

Parameters

web3 (web3.main.Web3) –

Return type

decimal.Decimal

static from_private_key(key)[source]

Create a hot wallet from a private key that is passed in as a hex string.

Add the key to web3 signing chain.

Example:

# Generated with  openssl rand -hex 32
wallet = HotWallet.from_private_key("0x54c137e27d2930f7b3433249c5f07b37ddcfea70871c0a4ef9e0f65655faf957")
Parameters

key (str) – 0x prefixed hex string

Returns

Ready to go hot wallet account

Return type

eth_defi.hotwallet.HotWallet