Author

Topic: How to send tx in Electrum using its console Python shell? (Read 191 times)

HCP
legendary
Activity: 2086
Merit: 4363
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,
                    nocheck=False, unsigned=False, rbf=None, password=None, locktime=None, addtransaction=False, wallet: Abstract_Wallet = 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)
Exception: Cannot specify both 'fee' and 'feerate' at the same time!

- 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

- 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.
legendary
Activity: 3472
Merit: 3217
Playbet.io - Crypto Casino and Sportsbook
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.
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
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
jr. member
Activity: 36
Merit: 27
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?
Jump to: