<p>So... I found out what was wrong. The problem was in this part of the code when i was adding the inputs. I was adding an index to each input based on which number of input it was. </p>

<pre><code>for(var a = 0; a &lt; input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,a)
    sum_outputs+=parseInt(input_utxos[a].amount);
}
</code></pre>

<p>but the index i was supossed to send was actually the index on the transaction outputs. so it had to be like this</p>

<pre><code>for(var a = 0; a &lt; input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,input_utxos[a].n)
    sum_outputs+=parseInt(input_utxos[a].amount);
}
</code></pre>

<p>The index was gettable from the api that provided me all the utxos for an account. In this case, it was called <code>n</code> and was inside the transaction object itself.</p>

CC BY-SA 3.0
2015-09-17T15:06:34.407Z
2015-09-17T15:06:34.407Z
caxco93
<p>I'm making a full-service wallet, I already made the UTXOs selection algorithm and now I want to push the transaction hex bytes. <strong>It works when I push only a transaction with only 1 input</strong>, but if I try to push the hex from a tx I made with 2 inputs from the same account, I get this: </p>

<pre><code>OP_EQUALVERIFY: non-equal data
</code></pre>

<p>Here is my decoded hex:</p>

<pre><code>{
   "lock_time":0,
   "size":339,
   "inputs":[
      {
         "prev_out":{
            "index":0,
            "hash":"3a896625fce1f18ce4c3139863359631d5677cff4e4fd8dac25ca6327c0dadd8"
         },
         "script":"473044022070f3b03cca6a75038ffe150be347a97d0e07adc857cc93e245739db55e3a6d36022051eb72b21e35a5e7309e1864f00e1b107a5b5262d80b1128e9fb45fbe7971c7b012102bb05325000709d3a3d8063f9913777859b8fa30b83e4c4f981bb2d9781b7c91a"
      },
      {
         "prev_out":{
            "index":1,
            "hash":"436094120d4412c32b97738f9051a32a237c037abe31cafbdc8a02d16f2a659c"
         },
         "script":"483045022100da7abc59e24d2afea9219ee24d1f3df4e1b9a2efa154d9704ed903210abfdb40022015a8237d38e18f558172872af1aa5c244b38c3ad8f594463c0dcad18dbfcf5f5012102bb05325000709d3a3d8063f9913777859b8fa30b83e4c4f981bb2d9781b7c91a"
      }
   ],
   "version":1,
   "vin_sz":2,
   "hash":"c5991f9f044f9d829fc01eeda76f36a514271270f9f891ea7b584f504ed404ea",
   "vout_sz":1,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 7ff85ee854794422531b7b5c3d380c5f50011a4e OP_EQUALVERIFY OP_CHECKSIG",
         "address":"1CfeMTtDP9HNjc8vsuuHGgUfABexvW5Qkf",
         "value":350000,
         "script":"76a9147ff85ee854794422531b7b5c3d380c5f50011a4e88ac"
      }
   ]
}
</code></pre>

<p>Links for the transactions being used:  </p>

<ul>
<li><a href="https://blockchain.info/tx/3a896625fce1f18ce4c3139863359631d5677cff4e4fd8dac25ca6327c0dadd8" rel="nofollow">https://blockchain.info/tx/3a896625fce1f18ce4c3139863359631d5677cff4e4fd8dac25ca6327c0dadd8</a></li>
<li><a href="https://blockchain.info/tx/436094120d4412c32b97738f9051a32a237c037abe31cafbdc8a02d16f2a659c" rel="nofollow">https://blockchain.info/tx/436094120d4412c32b97738f9051a32a237c037abe31cafbdc8a02d16f2a659c</a></li>
</ul>

<p>My address is 1FebYgpxQ1exSNdJENkbmNPmSfsiP3kZiT.</p>

<p>And my code using the BitcoinJS library is the following:</p>

<pre><code>key = bitcoin.ECPair.fromWIF(privatekey);
var tx = new bitcoin.TransactionBuilder()
var sum_outputs = 0;

var input_utxos = defineInputs(utxos, amount);

for(var a = 0; a &lt; input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,a)
    sum_outputs+=parseInt(input_utxos[a].amount);
}

tx.addOutput(to, parseInt(amount));
var change_amount = sum_outputs - parseInt(amount);
if(change_amount &gt; 0) {
    tx.addOutput(from, change_amount);
}

for(var a = 0; a &lt; input_utxos.length; a++) {
    tx.sign(a, key);
}

result = tx.build().toHex();

console.log(result);
</code></pre>

<p>So my questions are:</p>

<ol>
<li>Why is this working with 1 input from my address and not for 2 inputs?</li>
<li>How can I correctly sign the second input that I assume is the cause for the error?</li>
</ol>

CC BY-SA 3.0
2015-09-16T23:20:41.640Z
At the current moment, I looked at both of the source transactions and the indexes have been spent already. Did you successfully solve your problem?
Nayuki
CC BY-SA 3.0
2015-09-17T14:59:54.490Z
@NayukiMinase yes. thanks. i will post my own answer
caxco93
<address><signature><bitcoinjs><javascript><node.js>
OP_EQUALVERIFY Problem
caxco93
# OP_EQUALVERIFY Problem

(Asked by: username_0 on 2015-09-15)

I'm making a full-service wallet, I already made the UTXOs selection algorithm and now I want to push the transaction hex bytes. **It works when I push only a transaction with only 1 input**, but if I try to push the hex from a tx I made with 2 inputs from the same account, I get this:

```
OP_EQUALVERIFY: non-equal data

```

Here is my decoded hex:

```
{
   "lock_time":0,
   "size":339,
   "inputs":[
      {
         "prev_out":{
            "index":0,
            "hash":"3a896625fce1f18ce4c3139863359631d5677cff4e4fd8dac25ca6327c0dadd8"
         },
         "script":"473044022070f3b03cca6a75038ffe150be347a97d0e07adc857cc93e245739db55e3a6d36022051eb72b21e35a5e7309e1864f00e1b107a5b5262d80b1128e9fb45fbe7971c7b012102bb05325000709d3a3d8063f9913777859b8fa30b83e4c4f981bb2d9781b7c91a"
      },
      {
         "prev_out":{
            "index":1,
            "hash":"436094120d4412c32b97738f9051a32a237c037abe31cafbdc8a02d16f2a659c"
         },
         "script":"483045022100da7abc59e24d2afea9219ee24d1f3df4e1b9a2efa154d9704ed903210abfdb40022015a8237d38e18f558172872af1aa5c244b38c3ad8f594463c0dcad18dbfcf5f5012102bb05325000709d3a3d8063f9913777859b8fa30b83e4c4f981bb2d9781b7c91a"
      }
   ],
   "version":1,
   "vin_sz":2,
   "hash":"c5991f9f044f9d829fc01eeda76f36a514271270f9f891ea7b584f504ed404ea",
   "vout_sz":1,
   "out":[
      {
         "script_string":"OP_DUP OP_HASH160 7ff85ee854794422531b7b5c3d380c5f50011a4e OP_EQUALVERIFY OP_CHECKSIG",
         "address":"1CfeMTtDP9HNjc8vsuuHGgUfABexvW5Qkf",
         "value":350000,
         "script":"76a9147ff85ee854794422531b7b5c3d380c5f50011a4e88ac"
      }
   ]
}

```

Links for the transactions being used:

* <https://blockchain.info/tx/3a896625fce1f18ce4c3139863359631d5677cff4e4fd8dac25ca6327c0dadd8>
* <https://blockchain.info/tx/436094120d4412c32b97738f9051a32a237c037abe31cafbdc8a02d16f2a659c>

My address is 1FebYgpxQ1exSNdJENkbmNPmSfsiP3kZiT.

And my code using the BitcoinJS library is the following:

```
key = bitcoin.ECPair.fromWIF(privatekey);
var tx = new bitcoin.TransactionBuilder()
var sum_outputs = 0;

var input_utxos = defineInputs(utxos, amount);

for(var a = 0; a < input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,a)
    sum_outputs+=parseInt(input_utxos[a].amount);
}

tx.addOutput(to, parseInt(amount));
var change_amount = sum_outputs - parseInt(amount);
if(change_amount > 0) {
    tx.addOutput(from, change_amount);
}

for(var a = 0; a < input_utxos.length; a++) {
    tx.sign(a, key);
}

result = tx.build().toHex();

console.log(result);

```

So my questions are:

1. Why is this working with 1 input from my address and not for 2 inputs?
2. How can I correctly sign the second input that I assume is the cause for the error?

**Tags:** address, signature, bitcoinjs, javascript, node.js

> **Comments:**
> **username_1**: At the current moment, I looked at both of the source transactions and the indexes have been spent already. Did you successfully solve your problem?  
> **username_0**: @NayukiMinase yes. thanks. i will post my own answer  

---

## 1 answers

### Answer by username_0 on 2015-09-17. Score: 2 | Accepted answer

So... I found out what was wrong. The problem was in this part of the code when i was adding the inputs. I was adding an index to each input based on which number of input it was.

```
for(var a = 0; a < input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,a)
    sum_outputs+=parseInt(input_utxos[a].amount);
}

```

but the index i was supossed to send was actually the index on the transaction outputs. so it had to be like this

```
for(var a = 0; a < input_utxos.length ; a++){
    tx.addInput(input_utxos[a].tx,input_utxos[a].n)
    sum_outputs+=parseInt(input_utxos[a].amount);
}

```

The index was gettable from the api that provided me all the utxos for an account. In this case, it was called `n` and was inside the transaction object itself.


---

