Account

class cheb3.account.Account(private_key: Optional[str] = None)

Please use cheb3.Connection.account() interface to create an account instance associated with the connection.

To create an account instance with the given private key:

>>> account = conn.account("0xpr1vateK3y")

If no private key is provided, a randomly generated private key will be used to create an account instance.

call(to: HexStr, data: HexStr = '0x', **kwargs) HexBytes

Without a Contract instance, interacts with a smart contract without creating a new transaction on the blockchain.

Parameters:
  • to (HexStr) – The address of the contract.

  • data (HexStr) – The transaction data, defaults to 0x.

Keyword Arguments:

state_override (dict) – Specify the state override set. View Geth documentation for more details.

Return type:

HexBytes

create_access_list(to: Optional[HexStr], value: int = 0, data: HexStr = '0x', **kwargs) AccessList

Creates an EIP-2930 type access list based on the given transaction data.

Parameters:
  • to (Union[HexStr, None]) – The address of the receiver.

  • value (int) – The amount to transfer, defaults to 0 (wei).

  • data (HexStr) – The transaction data, defaults to 0x.

Keyword Arguments:
  • block_identifier (str) – A string representing a block number (hexadecimal) or latest or pending, defaults is latest.

  • gas_price (int) – Specifies the gas price for the LEGACY transaction.

  • max_priority_fee_per_gas (int) – Specifies the fee that goes to the miner, defaults to the value of max_priority_fee.

  • max_fee_per_gas (int) – Specifies the maximum amount you are willing to pay, inclusive of baseFeePerGas and maxPriorityFeePerGas. Its default value is the sum of maxPriorityFeePerGas and twice the baseFeePerGas of the latest block.

  • gas_limit (int) – Specifies the maximum gas the transaction can use.

  • authorization_list (List[SignedSetCodeAuthorization]) – Specifies a list of signed authorizations (EIP-7702).

Returns:

An access list contains all storage slots and addresses read and written by the transaction, except for the sender account and the precompiles.

Return type:

AccessList

get_balance() int

Returns the balance of the account instance.

send_transaction(to: Optional[HexStr], value: int = 0, data: HexStr = '0x', **kwargs) Union[TxReceipt, HexStr]

Transfers ETH or interacts with a smart contract without a Contract instance.

Parameters:
  • to (Union[HexStr, None]) – The address of the receiver.

  • value (int) – The amount to transfer, defaults to 0 (wei).

  • data (HexStr) – The transaction data, defaults to 0x.

Keyword Arguments:
  • gas_price (int) – Specifies the gas price for the LEGACY transaction.

  • max_priority_fee_per_gas (int) – Specifies the fee that goes to the miner, defaults to the value of max_priority_fee.

  • max_fee_per_gas (int) – Specifies the maximum amount you are willing to pay, inclusive of baseFeePerGas and maxPriorityFeePerGas. Its default value is the sum of maxPriorityFeePerGas and twice the baseFeePerGas of the latest block.

  • gas_limit (int) – Specifies the maximum gas the transaction can use.

  • nonce (int) – Allows to overwrite pending transactions that use the same nonce.

  • access_list (List[Dict]) – Specifies a list of addresses and storage keys that the transaction plans to access (EIP-2930).

  • authorization_list (List[SignedSetCodeAuthorization]) – Specifies a list of signed authorizations (EIP-7702).

  • wait_for_receipt (bool) – Waits for the transaction receipt, defaults to True.

Returns:

The transaction receipt or the transaction hash if wait_for_receipt is False.

Return type:

Union[TxReceipt, HexStr]

sign_authorization(target: HexStr, is_sender: bool = True, **kwargs) SignedSetCodeAuthorization

Signs an authorization to be included in a EIP-7702 transaction.

Examples

>>> # If this account is to sign the EIP-7702 transaction next
>>> account.sign_authorization(delegate_contract.address)
>>> # If the EIP-7702 transaction is sent by another account
>>> account.sign_authorization(delegate_contract.address, is_sender=False)
Parameters:
  • target (HexStr) – The address of the smart contract code to be associated with the account.

  • is_sender (bool) – If the account is also the sender of the EIP-7702 transaction. Its default value is True, which means the nonce to be signed will be 1 higher than the current nonce of the account. This is because the nonce is increased before the transaction execution and again when processing the authorization. It is not used when the keyword argument nonce is set.

Keyword Arguments:
  • chain_id (int) – The chain ID for the chain where the account is located, defaults to the chain ID of the current Connection.

  • nonce (int) – Allows to sign an authorization with a specific nonce.

sign_raw_message_hash(message_hash: HexStr) SignedMessage

Signs a raw message hash with the account’s private key.

Examples

>>> msg_hash = Web3.solidity_keccak(["uint256", "address"], [10, account.address])
>>> sig = account.sign_raw_message_hash(msg_hash)
>>> sig
SignedMessage(message_hash=HexBytes('0xe17bbd560054251725995886026ff6de42a496c52d90cc3ba61a5a97e3cda128'),
r=97529042910999732419272940067647801719735539298841301635952986349446066833551,
s=1555140386957721792444331594584329432191181296221261541177951220673132507501,
v=28,
signature=HexBytes('0xd79f7b6a5c832d450820a60ad7a99c2df98708c417c7c5cb52d0ee270cf7888f03702da2e2862f0d30386d32610c3f833d7dbd8d0ea06b7db2beb83d3656316d1c'))
>>> sig.signature.hex()
'd79f7b6a5c832d450820a60ad7a99c2df98708c417c7c5cb52d0ee270cf7888f03702da2e2862f0d30386d32610c3f833d7dbd8d0ea06b7db2beb83d3656316d1c'
>>> sig.r
97529042910999732419272940067647801719735539298841301635952986349446066833551
Parameters:

message_hash (HexStr) – The hash of the message to sign.

Returns:

The signed message as a HexBytes object.

Returns:

Various details about the signature - most importantly the fields: v, r, and s

Return type:

SignedMessage