Author

Topic: Electrum Wallet Python and OP-Return (Read 57 times)

legendary
Activity: 2268
Merit: 18503
January 21, 2023, 11:02:31 AM
#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.
legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
January 19, 2023, 10:12:15 PM
#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".
newbie
Activity: 5
Merit: 0
January 19, 2023, 04: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
Jump to: