Title: Electrum Wallet Python and OP-Return Post by: browser528 on January 19, 2023, 08:02:43 PM 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 Title: Re: Electrum Wallet Python and OP-Return Post by: nc50lc on January 20, 2023, 02:12:15 AM Is the Library good I'm not using that library so I can't comment on the accuracy of ChatGPT's answer or the library's performance,What is the hostname Where is the fee...... 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". Title: Re: Electrum Wallet Python and OP-Return Post by: o_e_l_e_o on January 21, 2023, 03:02:31 PM 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. |