Last active
April 29, 2024 14:40
-
-
Save chill117/58f22c073db8f9d230ae to your computer and use it in GitHub Desktop.
Get full transaction history for an address in your default Electrum wallet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where can i find my Bitcoin address