Skip to content

Conversation

@issamhaimour
Copy link

from bitcoinlib.wallets import Wallet
from bitcoinlib.keys import Key

إنشاء مفتاح خاص جديد بدون WIF

def create_new_private_key():
key = Key()
private_key = key.private_hex() # المفتاح الخاص بصيغة Hex
return private_key, key

إنشاء محفظة باستخدام المفتاح الخاص

def create_wallet_from_private_key(private_key):
key = Key.from_hex(private_key) # تحويل المفتاح الخاص من Hex
wallet = Wallet.import_wallet(key)
return wallet

التحقق من الرصيد

def check_balance(wallet):
return wallet.balance()

إرسال الأموال إلى عنوان معين

def send_bitcoin(wallet, recipient_address, amount):
try:
tx = wallet.send_to(recipient_address, amount)
return tx.txid # معرّف المعاملة
except Exception as e:
print(f"حدث خطأ أثناء إرسال الأموال: {e}")
return None

الوظيفة الرئيسية لتنفيذ العمليات

def main():
# إنشاء مفتاح خاص جديد
private_key, key = create_new_private_key()
print(f"تم إنشاء مفتاح خاص جديد بصيغة Hex: {private_key}")

# إنشاء المحفظة باستخدام المفتاح الخاص
wallet = create_wallet_from_private_key(private_key)

# التحقق من الرصيد
balance = check_balance(wallet)
print(f"الرصيد المتاح: {balance} ساتوشي")

if balance > 100000:  # التأكد من أن الرصيد كافٍ (مثال 0.001 بيتكوين)
    # إرسال الأموال إلى عنوان آخر (استبدل العنوان والمبلغ بالقيم الفعلية)
    recipient_address = '1KNm4K8GUK8sMoxc2Z3zU8Uv5FDVjrA72p'
    amount = 100000  # 0.001 بيتكوين (أو استبدل بالقيمة التي ترغب بها)
    
    txid = send_bitcoin(wallet, recipient_address, amount)
    if txid:
        print(f"تم إرسال الأموال بنجاح! معرّف المعاملة: {txid}")
    else:
        print("فشل إرسال الأموال.")
else:
    print("الرصيد غير كافٍ لإتمام المعاملة.")

تنفيذ الكود

if name == 'main':
main()

@SAK011
Copy link

SAK011 commented Jun 30, 2025

0x20A0Af89515C884EF504b4761B7fF3c17F91479c

@SAK011
Copy link

SAK011 commented Jun 30, 2025

100000

Copy link

@Lilajoon Lilajoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ali

@sam-byng sam-byng closed this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants