Author

Topic: Using the Data field in OP_RETURN transactions, and converting text to hex (Read 171 times)

newbie
Activity: 21
Merit: 11


Maybe try wrapping your "data" in " "'s? Huh

I just used this on the Bitcoin Core console:
Code:
createrawtransaction '[{"txid": "TXID", "vout": 0}]' '{"Address1": Amount1, "data": "4920616d204672616374616c456e6372797074"}'

And it immediately created the rawtransaction, which includes the following when I decoderawtransaction:
Code:
...
{
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN 4920616d204672616374616c456e6372797074",
        "hex": "6a134920616d204672616374616c456e6372797074",
        "type": "nulldata"
}
...

#1
This worked perfectly,
#2
I love you
# 3
I think you're the coolest!
HCP
legendary
Activity: 2086
Merit: 4361
When I create the raw transaction, my node is giving me an error about the data I want to include.

For example, I tried to convert "I am FractalEncrypt" to hex and I get this:
4920616d204672616374616c456e6372797074

When I try to insert this string into the data field below I get
Error: Error parsing JSON:

createrawtransaction \
'[{"txid": "txid1", "vout": vout1},
{"txid": "txid2", "vout": vout2}]' \
'{"address1": Amount1,
"address2": Amount2,
"address3": Amount3,
"data": 4920616d204672616374616c456e6372797074}'

Maybe try wrapping your "data" in " "'s? Huh

I just used this on the Bitcoin Core console:
Code:
createrawtransaction '[{"txid": "TXID", "vout": 0}]' '{"Address1": Amount1, "data": "4920616d204672616374616c456e6372797074"}'

And it immediately created the rawtransaction, which includes the following when I decoderawtransaction:
Code:
...
{
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN 4920616d204672616374616c456e6372797074",
        "hex": "6a134920616d204672616374616c456e6372797074",
        "type": "nulldata"
}
...
newbie
Activity: 21
Merit: 11
I am trying to create a transaction using this as my template here (I'm using Bitcoin Core 0.20.1 testnet)


The RPC "createrawtransaction" of Bitcoin Core 0.12 will be extended, and directly supports to create OP_RETURN transactions as follows:


Code:
bitcoin-cli "createrawtransaction" '[{"txid":"hash","vout":n}, ...] '{"data": "0123..."}'

When I create the raw transaction, my node is giving me an error about the data I want to include.

For example, I tried to convert "I am FractalEncrypt" to hex and I get this:
4920616d204672616374616c456e6372797074

When I try to insert this string into the data field below I get
Error: Error parsing JSON:


createrawtransaction \
'[{"txid": "txid1", "vout": vout1},
{"txid": "txid2", "vout": vout2}]' \
'{"address1": Amount1,
"address2": Amount2,
"address3": Amount3,
"data": 4920616d204672616374616c456e6372797074}'

If instead of 4920616d204672616374616c456e6372797074, I just use 49 (the first two digits)
Immediately, createrawtranstion works, and I get my raw tx hex.

I tested the same thing with "hello world"
68656c6c6f20776f726c64

This gives the JSON error, but if I only use the first 2 digits, 68, then it works.

So obviously I am converting from text to the hex strings incorrectly, I'm using "text to hexadecimal" converters online, I've tried 2, they give identical results...
Here's one - https://www.rapidtables.com/convert/number/ascii-to-hex.html
Here's the other - https://www.online-toolz.com/tools/text-hex-convertor.php


EDIT: I tested a few more things, trying more characters, if I try 8 characters(4920616d, I get the same JSON Error, but if I only have 7 characters (4920616), the error tells me it's not in hex format...so maybe something else is going on.

ERROR: Data must be hexadecimal string (not '4920616') (code -8)

EDIT 2: I tried using 4 characters in the data field, that also worked, I get the transaction hx right away (using 4920)
6 characters ALSO works perfectly (characters are 492061)

Bitcoin Client Software and Version Number: Bitcoin Core QT Console Version 0.20.1 (testnet)
Operating System: Windows 10
System Hardware Specs: Desktop

Log Files from the Bitcoin Client: (not sure how to grab these...)
Jump to: