Bitcoin Forum
May 04, 2024, 06:46:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Using the Data field in OP_RETURN transactions, and converting text to hex  (Read 136 times)
FractalEncrypt (OP)
Newbie
*
Offline Offline

Activity: 21
Merit: 11


View Profile
January 08, 2021, 01:22:36 AM
Last edit: January 08, 2021, 01:33:22 AM by FractalEncrypt
Merited by ABCbits (2), HCP (1)
 #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:


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...)
1714805205
Hero Member
*
Offline Offline

Posts: 1714805205

View Profile Personal Message (Offline)

Ignore
1714805205
Reply with quote  #2

1714805205
Report to moderator
Each block is stacked on top of the previous one. Adding another block to the top makes all lower blocks more difficult to remove: there is more "weight" above each block. A transaction in a block 6 blocks deep (6 confirmations) will be very difficult to remove.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
January 08, 2021, 03:47:23 AM
Merited by ABCbits (2), FractalEncrypt (1)
 #2

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"
}
...

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
FractalEncrypt (OP)
Newbie
*
Offline Offline

Activity: 21
Merit: 11


View Profile
January 08, 2021, 12:28:21 PM
 #3



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!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!