How to get transaction fee info using Python from an Electrum server?


I can get a raw transaction and parse it using electrum and bitcoinlib fairly easily:

import bitcoinlib

from electrum.daemon import Daemon
from electrum.simple_config import SimpleConfig

class TxInfoClient:
    """Transaction info client"""

    def __init__(self):
        common_config = parse_config()
        electrum_config = SimpleConfig(
            {"testnet": False, "server": common_config["electrum"]["server"]}
        self.daemon = Daemon(electrum_config, listen_jsonrpc=False)

    def get_tx(self, tx_id):
        """Returns a bitcoinlib.transactions.Transaction:
        raw_tx =
        return bitcoinlib.transactions.Transaction.parse_hex(raw_tx)

However, the resulting Transaction object won’t contain fee information because it isn’t possible to calculate Bitcoin Tx fees from a single transaction.

I could go through and query input transactions manually, as suggested in that link. However, I am looking for a simple solution that uses well established and maintained libraries to do it.

Is there a way to make this happen using bitcoinlib and electrum, or other mainstream libraries?


Source link






Leave a Reply

Your email address will not be published. Required fields are marked *