Bitcoin Forum
June 15, 2024, 02:25:16 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Electrum Wallet Python and OP-Return  (Read 58 times)
browser528 (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
January 19, 2023, 08:02:43 PM
 #1

Hej

Overwelmed by the https://chat.openai.com/ I tested some help for my long time desire to write on the Blockchain, I asked

Please give me some directions how  to write "Hello World" for ever on the Blockchain using Python.

This was the answer:

Here is an example of how to use the "electrum-client" library to create an OP_RETURN transaction with a text message:

from electrum_client import ElectrumClient

# Connect to the Electrum server
client = ElectrumClient('hostname', port=50002, protocol='tcp')

# Create the transaction
tx = client.blockchain.transaction.create(
    inputs=[{'address': 'your_address', 'value': 200000}],
    outputs=[{'address': 'destination_address', 'value': 100000}],
    op_return_data=b"Hello, world!"
)

# Sign the transaction
tx = client.blockchain.transaction.sign(tx, privkey='your_private_key')

# Broadcast the transaction
tx_id = client.blockchain.transaction.broadcast(tx)
print(tx_id)


My Python and Electrum knowledge is below this but I would like some comments on this.

Is the Library good
What is the hostname
Where is the fee......

Best regards
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5714


Self-proclaimed Genius


View Profile
January 20, 2023, 02:12:15 AM
 #2

Is the Library good
What is the hostname
Where is the fee......
I'm not using that library so I can't comment on the accuracy of ChatGPT's answer or the library's performance,
but it's on the right path for using OP_Return.
I'll just reply to your other queries:

The "hostname" is the server of your choosing.
For example, if I want to connect to blockstream's public server, I'd use ('electrum.blockstream.info', port=50002, protocol='tcp')

The fee is the difference between the input(s) and output(s) values.
The "fee rate" is the fee divided by the transaction's size in "virtual bytes".

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18587


View Profile
January 21, 2023, 03:02:31 PM
Merited by pooya87 (2), ABCbits (1)
 #3

Can you use the Electrum GUI to do this instead? It is trivially easy.

Simply go to the send tab, and in the "Pay to" field you enter OP_RETURN followed by your message in hex. So for your string "Hello, world!", your entry would look like this:
Code:
OP_RETURN 48656C6C6F2C20776F726C6421

Then just set the "Amount" to 0 and hit pay. You'll get the usual Electrum pop up to choose your fee, etc.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!