Last active
June 13, 2023 00:24
-
-
Save kdmukai/0d07e6c4470863f458acc7b4d2d14788 to your computer and use it in GitHub Desktop.
Adding an OP_RETURN output to a psbt using `embit`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
dependency: pip install embit | |
""" | |
from embit import compact | |
from embit.psbt import PSBT, OutputScope | |
from embit.script import Script | |
class OPCODES: | |
OP_RETURN = 106 | |
OP_PUSHDATA1 = 76 | |
psbt = PSBT.from_base64("cHNidP8BAHQC...") | |
raw_payload_data = "This is your message".encode() | |
data = (compact.to_bytes(OPCODES.OP_RETURN) + | |
compact.to_bytes(OPCODES.OP_PUSHDATA1) + | |
compact.to_bytes(len(raw_payload_data)) + | |
raw_payload_data) | |
script = Script(data) | |
output = OutputScope() | |
output.script_pubkey = script | |
output.value = 0 | |
psbt.outputs.append(output) | |
print(psbt.to_string()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for sharing!