gnosis/eth/utils.py
def generate_address_2(
    from_: Union[str, bytes], salt: Union[str, bytes], init_code: Union[str, bytes]
) -> str:
    """
    Generates an address for a contract created using CREATE2.

    :param from_: The address which is creating this new address (need to be 20 bytes)
    :param salt: A salt (32 bytes)
    :param init_code: A init code of the contract being created
    :return: Address of the new contract
    """

    from_ = HexBytes(from_)
    salt = HexBytes(salt)
    init_code = HexBytes(init_code)

    assert len(from_) == 20, f"Address {from_.hex()} is not valid. Must be 20 bytes"
    assert len(salt) == 32, f"Salt {salt.hex()} is not valid. Must be 32 bytes"
    assert len(init_code) > 0, f"Init code {init_code.hex()} is not valid"

    init_code_hash = Web3.keccak(init_code)
    contract_address = Web3.keccak(HexBytes("ff") + from_ + salt + init_code_hash)
    return Web3.toChecksumAddress(contract_address[12:])

    Generates an address for a contract created using CREATE2.

    :param from_: The address which is creating this new address (need to be 20 bytes)
    :param salt: A salt (32 bytes)
    :param init_code: A init code of the contract being created
    :return: Address of the new contract
    
Generates an address for a contract created using CREATE2.
Generates an address for a contract created using CREATE2 .
def generate_address_2(
    from_: Union[str, bytes], salt: Union[str, bytes], init_code: Union[str, bytes]
) -> str:
    from_ = HexBytes(from_)
    salt = HexBytes(salt)
    init_code = HexBytes(init_code)
    assert len(from_) == 20, f"Address {from_.hex()} is not valid. Must be 20 bytes"
    assert len(salt) == 32, f"Salt {salt.hex()} is not valid. Must be 32 bytes"
    assert len(init_code) > 0, f"Init code {init_code.hex()} is not valid"
    init_code_hash = Web3.keccak(init_code)
    contract_address = Web3.keccak(HexBytes("ff") + from_ + salt + init_code_hash)
    return Web3.toChecksumAddress(contract_address[12:])
def generate_address_2 ( from_ : Union [ str , bytes ] , salt : Union [ str , bytes ] , init_code : Union [ str , bytes ] ) -> str : from_ = HexBytes ( from_ ) salt = HexBytes ( salt ) init_code = HexBytes ( init_code ) assert len ( from_ ) == 20 , f"Address {from_.hex()} is not valid. Must be 20 bytes" assert len ( salt ) == 32 , f"Salt {salt.hex()} is not valid. Must be 32 bytes" assert len ( init_code ) > 0 , f"Init code {init_code.hex()} is not valid" init_code_hash = Web3 . keccak ( init_code ) contract_address = Web3 . keccak ( HexBytes ( "ff" ) + from_ + salt + init_code_hash ) return Web3 . toChecksumAddress ( contract_address [ 12 : ] )
Generates an address for a contract created using CREATE2.
Generates an address for a contract created using CREATE2 .
"""
    Generates an address for a contract created using CREATE2.

    :param from_: The address which is creating this new address (need to be 20 bytes)
    :param salt: A salt (32 bytes)
    :param init_code: A init code of the contract being created
    :return: Address of the new contract
    """
Address of the new contract
Address of the new contract
from_
Union[str, bytes]
The address which is creating this new address (need to be 20 bytes)
The address which is creating this new address ( need to be 20 bytes )
salt
Union[str, bytes]
A salt (32 bytes)
A salt ( 32 bytes )
init_code
Union[str, bytes]
A init code of the contract being created
A init code of the contract being created