Closed chrisyy2003 closed 1 year ago
There is already an answer here, the contract address is only related to the account address and nonce
import rlp
from eth_utils import keccak, to_checksum_address, to_bytes
from tqdm import tqdm
def mk_contract_address(sender: str, nonce: int) -> str:
"""Create a contract address using eth-utils.
# https://ethereum.stackexchange.com/a/761/620
"""
sender_bytes = to_bytes(hexstr=sender)
raw = rlp.encode([sender_bytes, nonce])
h = keccak(raw)
address_bytes = h[12:]
return to_checksum_address(address_bytes)
myaddress = 0xd69a77bE38f2Fb35De1aCC3AC3626E6d6c8d6928
nonce = 224
suffix = 'b1b1'
with tqdm() as t:
while mk_contract_address(to_checksum_address(myaddress), nonce)[-4:] != suffix:
nonce += 1
t.update()
print(mk_contract_address(to_checksum_address(myaddress), nonce), nonce)
so great!!! thank you so much
In other words, can it generate a contract address we hope