# 生成一个吉利的钱包地址

By [Pango](https://paragraph.com/@pango) · 2024-06-24

---

示例代码如下，只要将下面的8888改成自己的幸运数字即可啦，用自己幸运的钱包能量也会充沛吧。

    from eth_account import Account
    import csv
    import time
    
    def generate_specific_wallet(suffix, output_file):
        wallet = None
        attempts = 0
        start_time = time.time()
    
        while True:
            account = Account.create()
            address = account.address
    
            if address.endswith(suffix):
                private_key = account.key.hex()
                wallet = (private_key, address)
                break
    
            attempts += 1
            if attempts % 100000 == 0:
                elapsed_time = time.time() - start_time
                print(f"Attempts: {attempts}, Elapsed Time: {elapsed_time:.2f} seconds")
    
        with open(output_file, 'w', newline='') as csvfile:
            fieldnames = ['Private Key', 'Address']
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            writer.writerow({'Private Key': wallet[0], 'Address': wallet[1]})
    
        return wallet, attempts, time.time() - start_time
    
    if __name__ == "__main__":
        suffix = '8888'
        output_file = "specific_wallet.csv"
        wallet, attempts, elapsed_time = generate_specific_wallet(suffix, output_file)
        print(f"Wallet with address ending in {suffix} has been generated and saved to {output_file}")
        print(f"Private Key: {wallet[0]}")
        print(f"Address: {wallet[1]}")
        print(f"Total Attempts: {attempts}")
        print(f"Total Time: {elapsed_time:.2f} seconds")

---

*Originally published on [Pango](https://paragraph.com/@pango/4TtHYDRHlUjkAlYughHp)*
