bokub / vanity-eth

💎 Browser-based ETH vanity address generator
https://vanity-eth.tk
MIT License
751 stars 266 forks source link

can we generate EOA that with the ability to deploy contract address with specific prefix or suffix for the first time ? #33

Closed chrisyy2003 closed 1 year ago

chrisyy2003 commented 2 years ago

In other words, can it generate a contract address we hope

chrisyy2003 commented 2 years 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)
chrisyy2003 commented 2 years ago

so great!!! thank you so much

bokub commented 2 years ago

If you don't mind using a command-line tool, MyEtherWallet's VanityEth also supports contract addresses.