<p>I figured this out, the new transaction code should look like this with the address generated using <code>fromString()</code> method using bitcore. </p>

<pre><code>var address = bitcore.Address.fromString('2NEvGYDNxcVPZ2ThtmPKYoKBCEa3aJNjPL3');
var multiSigTx = new bitcore.Transaction()
    .from(utxo, pubs, 2)
    .to("mntnnj64W4po96m2ck4GXQJTAiKZQChpWB", 10000)
    .to("msR1bBwUWjTTNYFU5UTVNCXDUnEx1y2MMQ", 10000)
    .fee(5430)
    .change(address)
    .sign(["7e925007e09447fa6160597391d7a24f8f47e40222d6c94b06bd9cecee5eddff" ,"6b8adfd22b8dd3186ea5333602b39a59fc1c40c543dc3848ea88c6cd6b738594"]);

var txSerialized = multiSigTx.serialize(true);
</code></pre>

<p>This will then show the correct change output for the transaction.</p>

<p><code>console.log(multiSigTx.getChangeOutput());</code></p>

CC BY-SA 3.0
2017-10-18T21:11:41.900Z
with this you send 10000 Satoshis to each of the two different addresses? How could we send an amount (10000 Satoshis) to an Array of addresses?
Suisse
CC BY-SA 3.0
2015-05-27T15:15:26.670Z
2015-05-27T15:15:26.670Z
rxjmx
<p>I'm playing around with bitcore transactions and multi-sig transactions and was wondering how to send a transaction to more than one address, and keep the change.</p>

<p>Currently when I try to send the transaction it is sent, but the <code>fee</code> is calculated as:</p>

<p><code>unspent - satoshis</code></p>

<p>An example of this transaction I've made in the block chain can be seen here:</p>

<p><a href="http://tbtc.blockr.io/tx/info/114bc54b62641cba2e4f1a96e03a3997a5fbe0f582b5ef277415145a82cb440c" rel="nofollow">Example Transaction</a></p>

<p>Ad you can see it's calculated like this:</p>

<p><strong>Original unspent amount: 0.09000000</strong></p>

<p><strong>Fee: 0.08990000</strong></p>

<p><strong>Traded: 0.00010000</strong></p>

<p><strong>Transaction sum: 0.00010000</strong></p>

<p>Now I understand that one must spend all of the unspent outputs in a transaction, but how can I stop the fee from being as above, the remaining unspent balance?</p>

<p>Basically I want to split the transaction for two addresses, and send the rest to a change address.</p>

<p>Code:</p>

<pre><code>var utxo = new bitcore.Transaction.UnspentOutput({
  "txid" : "f42af6ab8b4dc3c636c5bfc6ce819063a55060c5619d31a6fa45a36413cb7953",
  "vout" : 0,
  "address" : "2MzuRYCXSHcBDEsSS4rziShvEzWSfoDe2zL",
  "scriptPubKey" : "OP_HASH160 20 0x54025426880aa847ec86f4d2488bbe260bfe0fcb OP_EQUAL",
  "satoshis" : 10000
});

var pubs = [
    "02758b89e56bfa8da41f2c1701aa5927bc026cc3b51bbeff399c53a15f2ae52e28",
    "02987ab3466118bd3fb5cb0c4fddbdd7ff8e21188314ffed4ecad83fb7689d57d7",
    "037b7f8cea06cfd5a96023341441b52431e31867c6f3716e5f20be24b709d023eb"
];

var multiSigTx = new bitcore.Transaction()
    .from(utxo, pubs, 2)
    .to("n1fqBkX6GtUsaV3EPqjpHcTuWhAQQgKXov", 10000)
    .fee(5430)
    .change("2MzuRYCXSHcBDEsSS4rziShvEzWSfoDe2zL")
    .sign(["083b63f9dbaa100c1714e05a04c20ab32f83f7726ba54a682013a13df6a92949" ,"5bef634cdcc7f9c2fd2b429d1ddf6cae56923433b6e8b2c5515cf87d84751e0a"]);

var txSerialized = multiSigTx.serialize(true);

// Broadcast

insight.broadcast(txSerialized, function(err, returnedTxId) {
  if (err) {
    console.log(err);
  } else {
    console.log("Sent coins, tx id is: ");
    console.log(returnedTxId);
  }
});
</code></pre>

<api><transaction-fees><multi-signature><change><bitcore>
Using bitcore to create a transaction with two addresses and change address
rxjmx
# Using bitcore to create a transaction with two addresses and change address

(Asked by: username_0 on 2015-05-27)

I'm playing around with bitcore transactions and multi-sig transactions and was wondering how to send a transaction to more than one address, and keep the change.
Currently when I try to send the transaction it is sent, but the fee is calculated as:
unspent - satoshis
An example of this transaction I've made in the block chain can be seen here:
Example Transaction
Ad you can see it's calculated like this:
Original unspent amount: 0.09000000
Fee: 0.08990000
Traded: 0.00010000
Transaction sum: 0.00010000
Now I understand that one must spend all of the unspent outputs in a transaction, but how can I stop the fee from being as above, the remaining unspent balance?
Basically I want to split the transaction for two addresses, and send the rest to a change address.
Code:
var utxo = new bitcore.Transaction.UnspentOutput({
  "txid" : "f42af6ab8b4dc3c636c5bfc6ce819063a55060c5619d31a6fa45a36413cb7953",
  "vout" : 0,
  "address" : "2MzuRYCXSHcBDEsSS4rziShvEzWSfoDe2zL",
  "scriptPubKey" : "OP_HASH160 20 0x54025426880aa847ec86f4d2488bbe260bfe0fcb OP_EQUAL",
  "satoshis" : 10000
});

var pubs = [
    "02758b89e56bfa8da41f2c1701aa5927bc026cc3b51bbeff399c53a15f2ae52e28",
    "02987ab3466118bd3fb5cb0c4fddbdd7ff8e21188314ffed4ecad83fb7689d57d7",
    "037b7f8cea06cfd5a96023341441b52431e31867c6f3716e5f20be24b709d023eb"
];

var multiSigTx = new bitcore.Transaction()
    .from(utxo, pubs, 2)
    .to("n1fqBkX6GtUsaV3EPqjpHcTuWhAQQgKXov", 10000)
    .fee(5430)
    .change("2MzuRYCXSHcBDEsSS4rziShvEzWSfoDe2zL")
    .sign(["083b63f9dbaa100c1714e05a04c20ab32f83f7726ba54a682013a13df6a92949" ,"5bef634cdcc7f9c2fd2b429d1ddf6cae56923433b6e8b2c5515cf87d84751e0a"]);

var txSerialized = multiSigTx.serialize(true);

// Broadcast

insight.broadcast(txSerialized, function(err, returnedTxId) {
  if (err) {
    console.log(err);
  } else {
    console.log("Sent coins, tx id is: ");
    console.log(returnedTxId);
  }
});

**Tags:** api, transaction-fees, multi-signature, change, bitcore


---

## 1 answers

### Answer by username_0 on 2015-05-27. Score: 3

I figured this out, the new transaction code should look like this with the address generated using fromString() method using bitcore. 
var address = bitcore.Address.fromString('2NEvGYDNxcVPZ2ThtmPKYoKBCEa3aJNjPL3');
var multiSigTx = new bitcore.Transaction()
    .from(utxo, pubs, 2)
    .to("mntnnj64W4po96m2ck4GXQJTAiKZQChpWB", 10000)
    .to("msR1bBwUWjTTNYFU5UTVNCXDUnEx1y2MMQ", 10000)
    .fee(5430)
    .change(address)
    .sign(["7e925007e09447fa6160597391d7a24f8f47e40222d6c94b06bd9cecee5eddff" ,"6b8adfd22b8dd3186ea5333602b39a59fc1c40c543dc3848ea88c6cd6b738594"]);

var txSerialized = multiSigTx.serialize(true);

This will then show the correct change output for the transaction.
console.log(multiSigTx.getChangeOutput());

> **Comments:**
> **username_1**: with this you send 10000 Satoshis to each of the two different addresses? How could we send an amount (10000 Satoshis) to an Array of addresses?  

---

