Skip to content

Instantly share code, notes, and snippets.

@chill117
Last active April 29, 2024 14:40
Show Gist options
  • Save chill117/58f22c073db8f9d230ae to your computer and use it in GitHub Desktop.
Save chill117/58f22c073db8f9d230ae to your computer and use it in GitHub Desktop.
Get full transaction history for an address in your default Electrum wallet.
#!/usr/bin/env python
# Place this file in the Electrum scripts directory. Then run from command line, like this: `~/.electrum/scripts/get_address_history.py <bitcoin_address>`.
import sys
from electrum import bitcoin, Network, print_json, SimpleConfig, Wallet, WalletStorage
try:
addr = sys.argv[1]
except Exception:
print 'Usage: ' + sys.argv[0] + ' <bitcoin_address>'
sys.exit(1)
if not bitcoin.is_valid(addr):
print 'Not a valid bitcoin address'
sys.exit(1)
def initialize():
config = SimpleConfig()
network = Network(config)
network.start(True)
if not network.is_connected:
print 'Not connected'
sys.exit(1)
storage = WalletStorage(config)
wallet = Wallet(storage)
wallet.start_threads(network)
return wallet, network
def get_address_history(addr):
h = wallet.history.get(addr, [])
history = []
for i, dummy in enumerate(h):
tx_hash = h[i][0]
tx = wallet.transactions.get(tx_hash)
if not tx: continue
value = 0
for o in tx.outputs:
o_address, o_value = o
if o_address == addr:
value += o_value
confirmations = wallet.verifier.get_confirmations(tx_hash)[0]
history.append({
'confirmations': confirmations,
'tx_hash': tx_hash,
'value': value / 1.e8
})
return history
def print_address_history(addr):
history = get_address_history(addr)
print_json(history)
wallet, network = initialize()
print_address_history(addr)
sys.exit(0)
@Unique337
Copy link

Where can i get my Bitcoin address

@Unique337
Copy link

Where can i find my Bitcoin address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment