<p>I would suggest using Python to accomplish this. <a href="https://github.com/vbuterin/pybitcointools" rel="nofollow noreferrer">pybitcointools</a> have what you need to be able to <strong>deserialize</strong> a hex transaction to JSON, and manipulate that and then <strong>serialize</strong> again to be able to sign and broadcast via support for blockchain.info.</p>

<p>This example will rebuild the standard script from the ground up:</p>

<pre><code>&gt;&gt;&gt; opdup = 0x76
&gt;&gt;&gt; ophash160 = 0xA9
&gt;&gt;&gt; push20 = 0x14
&gt;&gt;&gt; opeqver = 0x88
&gt;&gt;&gt; opchecksig = 0xAC
&gt;&gt;&gt; pubkeyhash = 0x2dbde30815faee5bf221d6688ebad7e12f7b2b1a
</code></pre>

<p>We are going to <a href="https://stackoverflow.com/questions/15629382/append-2-hex-values-in-python">append hex values</a> by moving them bitwise.</p>

<ul>
<li>OP_DUP OP_HASH160 2dbde30815faee5bf221d6688ebad7e12f7b2b1a OP_EQUALVERIFY OP_CHECKSIG</li>
<li>This is the <a href="https://coinb.in/decode-raw-transaction.html" rel="nofollow noreferrer">hex</a> we want <strong>76a9142dbde30815faee5bf221d6688ebad7e12f7b2b1a88ac</strong></li>
</ul>

<p>This is one way of doing it</p>

<pre><code>&gt;&gt;&gt; quickfix = 0xff
&gt;&gt;&gt; asm = quickfix
&gt;&gt;&gt; asm = asm &lt;&lt; 8 | opdup
&gt;&gt;&gt; asm = asm &lt;&lt; 8 | ophash160
&gt;&gt;&gt; asm = asm &lt;&lt; 8 | push20
&gt;&gt;&gt; asm = asm &lt;&lt; 8*20 | pubkeyhash
&gt;&gt;&gt; asm = asm &lt;&lt; 8 | opeqver
&gt;&gt;&gt; asm = asm &lt;&lt; 8 | opchecksig
</code></pre>

<p>Ant then to check if its the same:</p>

<pre><code>&gt;&gt;&gt; almost = hex(asm)
&gt;&gt;&gt; ready = almost.partition("0xff")[2]
&gt;&gt;&gt; print(ready)
</code></pre>

<p>Hope this is what you are after :-)</p>

CC BY-SA 3.0
2013-11-03T17:41:28.910Z
there is a bug if 0x00 (OP_FALSE) is used, if we try to left shift that nothing will happen. a quick fix is to add 0xff first, and then remove it at the last step
Jonas Oestman
CC BY-SA 3.0
2013-11-03T07:44:40.640Z
2013-11-03T17:45:32.007Z
2017-05-23T12:34:59.703Z
Jonas Oestman
<p>ABSOLUTELY Go!</p>

<pre><code>import(
    "github.com/btcsuite/btcd/txscript"
    "github.com/btcsuite/btcd/wire"
)

tx := wire.NewMsgTx(2)
tx.AddTxOut(wire.NewTxOut(int64(*outputvalueFlag*1e8), script()))

func script() ([]byte) {
    script := txscript.NewScriptBuilder()
    script.AddInt64(1)
    script.AddData(bytes[0:65])
    script.AddInt64(1)
    script.AddOp(txscript.OP_CHECKMULTISIG)
    return script.Script()
}
...
</code></pre>

CC BY-SA 3.0
2017-11-25T06:00:08.953Z
2017-11-25T06:00:08.953Z
MCCCS
<p>Is there a step-by-step tutorial or any documentation covering how to create a transaction that is not a standard <code>OP_DUP OP_HASH160 &lt;pubKeyHash&gt; OP_EQUALVERIFY OP_CHECKSIG</code>?</p>

<p>It seems very odd that there is absolutely no documentation or information covering how to create a transaction like this, when it is one of Bitcoin's greatest advantages.</p>

<p>Maybe a link to some open-source software which creates custom script transactions would be helpful. I don't know of any that exist off hand though.</p>

CC BY-SA 3.0
2013-10-25T04:52:32.260Z
As long as no `"; drop table wallet;"` is possible.
LateralFractal
CC BY-SA 3.0
2013-10-25T17:10:28.790Z
Little Bobby Tables, is that you?!
RLH
CC BY-SA 3.0
2013-10-25T20:52:40.833Z
Don't most nodes reject custom scripts? That's what [Blockchain.info](https://blockchain.info/)'s "strange transactions" are, right?
KJ O
CC BY-SA 3.0
2013-10-25T21:17:52.850Z
As far as I know, only transactions containing the "disabled" opcodes found here are rejected by nodes: https://en.bitcoin.it/wiki/Script
bvpx
CC BY-SA 3.0
2013-10-31T05:03:04.113Z
Maybe this Node.js tool can help https://github.com/jgarzik/txtool
Jonas Oestman
CC BY-SA 3.0
2017-08-26T09:05:52.650Z
have a look at bitcore-lib
Badr Bellaj
<transactions><script>
How to create a transaction with a custom script?
bvpx
# How to create a transaction with a custom script?

(Asked by: username_0 on 2013-10-24)

Is there a step-by-step tutorial or any documentation covering how to create a transaction that is not a standard `OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG`?

It seems very odd that there is absolutely no documentation or information covering how to create a transaction like this, when it is one of Bitcoin's greatest advantages.

Maybe a link to some open-source software which creates custom script transactions would be helpful. I don't know of any that exist off hand though.

**Tags:** transactions, script

> **Comments:**
> **username_1**: As long as no `"; drop table wallet;"` is possible.  
> **username_2**: Little Bobby Tables, is that you?!  
> **username_3**: Don't most nodes reject custom scripts? That's what [Blockchain.info](https://blockchain.info/)'s "strange transactions" are, right?  
> **username_0**: As far as I know, only transactions containing the "disabled" opcodes found here are rejected by nodes: https://en.bitcoin.it/wiki/Script  
> **username_4**: Maybe this Node.js tool can help https://github.com/jgarzik/txtool  
> **username_5**: have a look at bitcore-lib  

---

## 2 answers

### Answer by username_4 on 2013-11-03. Score: 3 | Accepted answer

I would suggest using Python to accomplish this. [pybitcointools](https://github.com/vbuterin/pybitcointools) have what you need to be able to **deserialize** a hex transaction to JSON, and manipulate that and then **serialize** again to be able to sign and broadcast via support for blockchain.info.

This example will rebuild the standard script from the ground up:

```
>>> opdup = 0x76
>>> ophash160 = 0xA9
>>> push20 = 0x14
>>> opeqver = 0x88
>>> opchecksig = 0xAC
>>> pubkeyhash = 0x2dbde30815faee5bf221d6688ebad7e12f7b2b1a

```

We are going to [append hex values](https://stackoverflow.com/questions/15629382/append-2-hex-values-in-python) by moving them bitwise.

* OP\_DUP OP\_HASH160 2dbde30815faee5bf221d6688ebad7e12f7b2b1a OP\_EQUALVERIFY OP\_CHECKSIG
* This is the [hex](https://coinb.in/decode-raw-transaction.html) we want **76a9142dbde30815faee5bf221d6688ebad7e12f7b2b1a88ac**

This is one way of doing it

```
>>> quickfix = 0xff
>>> asm = quickfix
>>> asm = asm << 8 | opdup
>>> asm = asm << 8 | ophash160
>>> asm = asm << 8 | push20
>>> asm = asm << 8*20 | pubkeyhash
>>> asm = asm << 8 | opeqver
>>> asm = asm << 8 | opchecksig

```

Ant then to check if its the same:

```
>>> almost = hex(asm)
>>> ready = almost.partition("0xff")[2]
>>> print(ready)

```

Hope this is what you are after :-)

> **Comments:**
> **username_4**: there is a bug if 0x00 (OP_FALSE) is used, if we try to left shift that nothing will happen. a quick fix is to add 0xff first, and then remove it at the last step  

---

### Answer by username_6 on 2017-11-25. Score: 1

ABSOLUTELY Go!

```
import(
    "github.com/btcsuite/btcd/txscript"
    "github.com/btcsuite/btcd/wire"
)

tx := wire.NewMsgTx(2)
tx.AddTxOut(wire.NewTxOut(int64(*outputvalueFlag*1e8), script()))

func script() ([]byte) {
    script := txscript.NewScriptBuilder()
    script.AddInt64(1)
    script.AddData(bytes[0:65])
    script.AddInt64(1)
    script.AddOp(txscript.OP_CHECKMULTISIG)
    return script.Script()
}
...

```


---

