Post
Topic
Board Bitcoin Technical Support
Merits 3 from 2 users
Topic OP
Using the Data field in OP_RETURN transactions, and converting text to hex
by
FractalEncrypt
on 08/01/2021, 01:22:36 UTC
⭐ Merited by ETFbitcoin (2) ,HCP (1)
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:

Quote
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