<p>For everyone here who needs this answer too: my friend created a simple program in Python and c++ to do this exact thing. You can download it on <a href="https://github.com/chancoin-core/returnify" rel="nofollow noreferrer">here</a>. </p>

CC BY-SA 3.0
2017-10-11T15:16:39.333Z
2017-10-11T15:16:39.333Z
Alexandre Voloch
<p>I'm reading <a href="https://en.bitcoin.it/wiki/Script" rel="nofollow noreferrer">the specification</a>. Your hex string has to start with <code>6a</code> [OP_RETURN opcode] followed by <code>4c</code> [OP_PUSHDATA1] followed by a one-byte number indicating the size (in bytes) of the following data. You have 10 bytes, so this <code>0a</code>. Then come your actual data, and here I think you made a mistake. In any case, <code>0102030405060708090a</code> (in your by-hand example) is neither the hex encoding of the string <code>"12345678910"</code> nor of the integer <code>12345678910</code>. Look at this python snippets:</p>

<pre><code>&gt;&gt;&gt; from binascii import hexlify
&gt;&gt;&gt; hex(12345678910)
'0x2dfdc1c3e'

&gt;&gt;&gt; hexlify("12345678910".encode()).decode()
'3132333435363738393130'
</code></pre>

<p>So I guess you need to clarify what your data represent and how you want it encoded...</p>

CC BY-SA 3.0
2017-10-08T17:15:10.743Z
2017-10-08T17:15:10.743Z
Charles Bouillaguet
<p>I'm creating a program (for an altcoin I'm developing) that should make it easy to create OP_RETURN transactions. Currently I'm having some trouble with actually creating the script pythonically (I can do it by hand but no idea how to program it). </p>

<p>As an example, the program takes an OP_RETURN script (eg. 6a4c0a0102030405060708090a) and creates a transaction with that script, by itself. However, currently you need to input the actual hex script instead of the string you want to send to the blockchain.</p>

<p>My question is - what's the best way to take a string/int and convert it into a transaction-friendly hex-encoded script? For example:</p>

<pre><code>String: OP_RETURN 12345678910
Output: 6a4c0a0102030405060708090a
</code></pre>

<p>Thanks a bunch to anyone who helps. I'll you all some bitcoin if you manage to find a good solution.</p>

CC BY-SA 3.0
2017-10-07T07:53:16.997Z
This is more of a programming question than a bitcoin-specific question
meshcollider
CC BY-SA 3.0
2017-10-10T14:42:27.847Z
All the bitcoin-related information you need is in the spec: https://en.bitcoin.it/wiki/Script  Other than that, you will need to learn about converting values to binary/hex in python, which is more of a general programming question based asked on the main Stack Overflow site.
Jestin
<transactions><script><python><op-return>
Convert plaintext script into hex-encoded script in python
Alexandre Voloch
# Convert plaintext script into hex-encoded script in python

(Asked by: username_0 on 2017-10-06)

I'm creating a program (for an altcoin I'm developing) that should make it easy to create OP_RETURN transactions. Currently I'm having some trouble with actually creating the script pythonically (I can do it by hand but no idea how to program it). 
As an example, the program takes an OP_RETURN script (eg. 6a4c0a0102030405060708090a) and creates a transaction with that script, by itself. However, currently you need to input the actual hex script instead of the string you want to send to the blockchain.
My question is - what's the best way to take a string/int and convert it into a transaction-friendly hex-encoded script? For example:
String: OP_RETURN 12345678910
Output: 6a4c0a0102030405060708090a

Thanks a bunch to anyone who helps. I'll you all some bitcoin if you manage to find a good solution.

**Tags:** transactions, script, python, op-return

> **Comments:**
> **username_1**: This is more of a programming question than a bitcoin-specific question  
> **username_2**: All the bitcoin-related information you need is in the spec: https://en.bitcoin.it/wiki/Script  Other than that, you will need to learn about converting values to binary/hex in python, which is more of a general programming question based asked on the main Stack Overflow site.  

---

## 2 answers

### Answer by username_0 on 2017-10-11. Score: 0 | Accepted answer

For everyone here who needs this answer too: my friend created a simple program in Python and c++ to do this exact thing. You can download it on [here](https://github.com/chancoin-core/returnify).


---

### Answer by username_3 on 2017-10-08. Score: 0

I'm reading the specification. Your hex string has to start with 6a [OP_RETURN opcode] followed by 4c [OP_PUSHDATA1] followed by a one-byte number indicating the size (in bytes) of the following data. You have 10 bytes, so this 0a. Then come your actual data, and here I think you made a mistake. In any case, 0102030405060708090a (in your by-hand example) is neither the hex encoding of the string "12345678910" nor of the integer 12345678910. Look at this python snippets:
>>> from binascii import hexlify
>>> hex(12345678910)
'0x2dfdc1c3e'

>>> hexlify("12345678910".encode()).decode()
'3132333435363738393130'

So I guess you need to clarify what your data represent and how you want it encoded...


---

