history008 commited on
Commit
5d811d7
·
verified ·
1 Parent(s): b75fa9a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from bitcoinlib.wallets import Wallet
3
+ from bitcoinlib.services.services import Service
4
+
5
+ # === CONFIG ===
6
+ WIF_KEY = "L48QruWQTMm7oqKpCu3iZhKBAQsXGLHmgCaoLvtELMdciPrbxxpA"
7
+ WALLET_NAME = "testnet_wallet_auto"
8
+
9
+ def process_btc_address(to_address, amount):
10
+ try:
11
+ # Delete old wallet if already exists (avoids duplication)
12
+ try:
13
+ Wallet.delete(WALLET_NAME)
14
+ except:
15
+ pass
16
+
17
+ # Create/import wallet from WIF key
18
+ wallet = Wallet.import_key(WALLET_NAME, WIF_KEY, network='testnet')
19
+
20
+ # Show sender address
21
+ from_address = wallet.get_key().address
22
+
23
+ # Refresh balance
24
+ balance = wallet.get_balance()
25
+ if balance < amount:
26
+ return f"❌ Not enough funds. Your balance: {balance:.8f} tBTC"
27
+
28
+ # Send BTC
29
+ tx = wallet.send_to(to_address, amount, fee=500, network='testnet')
30
+
31
+ return f"✅ Sent {amount:.8f} tBTC from {from_address} to {to_address}\n\nTXID:\n{tx.txid}"
32
+
33
+ except Exception as e:
34
+ return f"❌ Error: {str(e)}"
35
+
36
+ iface = gr.Interface(
37
+ fn=process_btc_address,
38
+ inputs=[
39
+ gr.Textbox(label="Enter Testnet BTC Address"),
40
+ gr.Number(label="Amount (BTC)", precision=8)
41
+ ],
42
+ outputs="text",
43
+ title="Send Bitcoin Testnet BTC",
44
+ description="⚠️ Must have testnet BTC in your wallet before sending. Uses fixed WIF key."
45
+ )
46
+
47
+ if __name__ == "__main__":
48
+ iface.launch()