|
Title: How to send tx in Electrum using its console Python shell? Post by: jiamijiang on November 07, 2020, 07:34:06 AM Does anyone have any tutorials out there to show the steps (an what functions to type in) on how to create and send a tx using the Python shell console of the Electrum wallet?
Title: Re: How to send tx in Electrum using its console Python shell? Post by: ranochigo on November 07, 2020, 07:35:41 AM Electrum's Help Doc is pretty comprehensive and useful for beginners. Try looking there first and feel free to ask if you need help. https://electrum.readthedocs.io/en/latest/cmdline.html
Title: Re: How to send tx in Electrum using its console Python shell? Post by: BitMaxz on November 07, 2020, 10:45:43 PM I think this one below is what you looking.
Code: payto(address, amount, opt_fee, opt_from, opt_change, opt_nocheck, opt_unsigned, opt_rbf, opt_password, opt_locktime) I just found it from here https://bitzuma.com/posts/an-introduction-to-the-electrum-python-console/ So you must check it first and try it with testnet for safety. Title: Re: How to send tx in Electrum using its console Python shell? Post by: HCP on November 08, 2020, 01:02:05 AM I think that guide may be a little out of date as the definition of payto() is incorrect looking at the current code:
Code: (https://github.com/spesmilo/electrum/blob/master/electrum/commands.py#L587) async def payto(self, destination, amount, fee=None, feerate=None, from_addr=None, from_coins=None, change_addr=None, The guide doesn't seem to be including the "feerate" option... Some notes from my brief experimentation using payto(): - fee is the TOTAL fee you want to pay in BTC (so, 0.00000500 would be 500 sats total fee) - feerate is the fee in sats/byte that you want to pay (so 2 would be 2 sats/byte) - You cannot specify the fee and feerate at the same time: Code: >>> payto("AddressGoesHere",0.1,0.00000500,2)- If you don't explicitly set the rbf option, it will use whatever is defined in your global Electrum settings. - payto() will return a signed "rawtransaction" in hex, if you leave unsigned=False... if you set unsigned=True, you'll get a "PSBT" (Partially Signed Bitcoin Transaction) in what I believe is Base64 encoding. This can be viewed in "Tools -> Load Transaction -> From Text". - from_addr is a comma-separated list of addresses that you want to "spend from"... eg "2NGAbopZg9ZpKeAqFQWcsEKNrnqFsg4Qqyb,2Mwv1humoLS5YxARhU8wPb19xDWLxLSKYXi" - from_coin is a comma-separated list of coin "Output point" that you want to "spend from"... an "output point" is effectively the "transactionID:vout" of the UTXO as displayed in the "coins" tab. eg: "a504115e8740e6596ffedafc290c2a9e3ad64329c260764b1b231532be853ced:1" would be 198.58718211 tBTC from this transaction (https://blockstream.info/testnet/tx/a504115e8740e6596ffedafc290c2a9e3ad64329c260764b1b231532be853ced) - Even if you specify multiple addresses or coins using from_addr and/or from_coin... it won't necessarily use ALL of them. Electrum will only use as few as required to meet the "total amount to send"+"total fee" requirements as per it's "normal" method of selecting UTXOs to spend. - You cannot include addrs/coins that have been "frozen". - As noted above, payto() will only create (and optionally sign) the transaction. You will need to use the "broadcast()" function to actually send the transaction to the network. |