ethereum.frontier.utils.address

Hardfork Utility Functions For Addresses ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Address specific functions used in this frontier version of specification.

to_address

Convert a Uint or U256 value to a valid address (20 bytes).

Parameters

data : The string to be converted to bytes.

Returns

address : Address The obtained address.

def to_address(data: Uint | U256) -> Address:
24
    """
25
    Convert a Uint or U256 value to a valid address (20 bytes).
26
27
    Parameters
28
    ----------
29
    data :
30
        The string to be converted to bytes.
31
32
    Returns
33
    -------
34
    address : `Address`
35
        The obtained address.
36
    """
37
    return Address(data.to_be_bytes32()[-20:])

compute_contract_address

Computes address of the new account that needs to be created.

Parameters

address : The address of the account that wants to create the new account. nonce : The transaction count of the account that wants to create the new account.

Returns

address: ethereum.frontier.fork_types.Address The computed address of the new account.

def compute_contract_address(address: Address, ​​nonce: Uint) -> Address:
41
    """
42
    Computes address of the new account that needs to be created.
43
44
    Parameters
45
    ----------
46
    address :
47
        The address of the account that wants to create the new account.
48
    nonce :
49
        The transaction count of the account that wants to create the new
50
        account.
51
52
    Returns
53
    -------
54
    address: `ethereum.frontier.fork_types.Address`
55
        The computed address of the new account.
56
    """
57
    computed_address = keccak256(rlp.encode([address, nonce]))
58
    canonical_address = computed_address[-20:]
59
    padded_address = left_pad_zero_bytes(canonical_address, 20)
60
    return Address(padded_address)