<p>Blockcypher API shows only the example of how to compose a transaction with a single input, therefore, it might look like the array of addresses will do the job, but no. If you'll do this by passing addresses into one array of inputs:</p>
<pre><code>curl -d '{&quot;inputs&quot;:[{&quot;addresses&quot;:[&quot;addr1&quot;, &quot;addr2&quot;]}],&quot;outputs&quot;:[{&quot;addresses&quot;:[&quot;addr3&quot;],&quot;value&quot;:100000000}]}' https://api.blockcypher.com/v1/btc/test3/txs/new
</code></pre>
<p>You'll have only zero element grabbed from the addresses array from the inputs:</p>
<pre><code>&quot;tx&quot;: {
    &quot;block_height&quot;: -1,
    &quot;block_index&quot;: -1,
    &quot;hash&quot;: &quot;002407bd35a6d0026cf0f5a018bd27311702560c03f1f64478105a547c91d895&quot;,
    &quot;addresses&quot;: [
      &quot;addr1&quot;, (inputs.addresses[0])
      &quot;addr3&quot; (outputs.addresses[0])
    ] ...
</code></pre>
<p><em>(Please note that I haven't included the whole tx blocks, only the ones containing the addresses.)</em></p>
<p>API will consider that you're using only one input, and may throw you an error if the value will be too big than the input's wallet balance.</p>
<pre><code>&quot;Not enough funds in 1 inputs to pay for 1 outputs, missing -X&quot;
</code></pre>
<p><strong>To create the tx with several inputs</strong>,  you'll have to pass arrays of addresses separately:</p>
<pre><code>curl -d '{&quot;inputs&quot;:[{&quot;addresses&quot;:[&quot;addr1&quot;]}, {&quot;addresses&quot;:[&quot;addr2&quot;]}],&quot;outputs&quot;:[{&quot;addresses&quot;:[&quot;addr3&quot;],&quot;value&quot;:100000000}]}' https://api.blockcypher.com/v1/btc/test3/txs/new
</code></pre>
<p>This will give you the correct response, and the correct amount of inputs:</p>
<pre><code>&quot;tx&quot;: {
    &quot;block_height&quot;: -1,
    &quot;block_index&quot;: -1,
    &quot;hash&quot;: &quot;ebcc8132c33a672cdd695a8953db503954abefa18bfd4727ea44f67b92c5ab6c&quot;,
    &quot;addresses&quot;: [
      &quot;addr1&quot;,
      &quot;addr2&quot;,
      &quot;addr3&quot;
    ] ...
</code></pre>
<p>In conclusion, it seems that the API itself is designed that way, at least at the moment of writing this answer.</p>

CC BY-SA 4.0
2020-07-04T21:44:44.540Z
Oh wow… Not at all what I expected. Thank you for digging into that and providing the correction!
Murch
CC BY-SA 4.0
2020-07-06T07:42:54.940Z
You're welcome! :) I've been struggling with it myself, and eventually came up with such a solution.
eirlis
CC BY-SA 4.0
2020-07-03T07:30:06.057Z
2020-07-03T07:30:06.057Z
eirlis
<p>Disclaimer: I have not tried this, I just glanced at the API documentation. H/T to <a href="https://bitcoin.stackexchange.com/a/96803/5406">eirlis</a> for providing the correct syntax.</p>
<p>As the API documentation for <a href="https://www.blockcypher.com/dev/bitcoin/#creating-transactions" rel="nofollow noreferrer">Creating Transactions</a> specifies, you provide the addresses that you received your funds to in the <code>inputs</code> parameter. The API documentation has this example using curl:</p>
<pre><code>curl -d '{&quot;inputs&quot;:[{&quot;addresses&quot;: [&quot;CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9&quot;]}],&quot;outputs&quot;:[{&quot;addresses&quot;: [&quot;C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn&quot;], &quot;value&quot;: 1000000}]}' https://api.blockcypher.com/v1/bcy/test/txs/new
</code></pre>
<p>For multiple addresses, you need to provide each address in a separate object with the property <code>addresses</code> to the inputs object: <code>{&quot;inputs&quot;:[{&quot;addresses&quot;:&quot;addr1&quot;}, {&quot;addresses&quot;:&quot;addr2&quot;}],&quot;outputs&quot;:…}</code>. According to the documentation, the response will be an unsigned transaction which you'll have to sign locally with the corresponding private keys. The BlockCypher documentation links to their &quot;signer tool&quot; at this point.</p>
<p>Note: all value not explicitly assigned to a recipient in a Bitcoin transaction will go to transaction fees. If you are using two 1 BTC inputs and are sending 1.5 BTC to a recipient, be sure that you add a second output to assign your <code>0.5 BTC – transaction fees</code> of change to one of your own addresses. Otherwise you will pay 0.5 BTC to the miner confirming your transaction. Be sure to verify that the transaction is doing what you intend to before signing it.</p>
<p><strong>I would firmly recommend that you build a few transactions with testnet coins to get the hang of it.</strong></p>

CC BY-SA 4.0
2020-04-25T20:38:58.080Z
2020-07-04T21:49:52.290Z
2020-07-04T21:49:52.290Z
Murch
<p>For example, I have two addresses and each of them has received 1 BTC. Now, I want to transfer 1.5 BTC to another address. How can I achieve this using the Blockcypher create transaction API?</p>

<api><sending><blockcypher>
How can you create a transaction with multiple inputs from the Blockcypher API?
Amirhosein Rajabi
# How can you create a transaction with multiple inputs from the Blockcypher API?

(Asked by: username_0 on 2020-04-25)

For example, I have two addresses and each of them has received 1 BTC. Now, I want to transfer 1.5 BTC to another address. How can I achieve this using the Blockcypher create transaction API?

**Tags:** api, sending, blockcypher


---

## 2 answers

### Answer by username_1 on 2020-07-03. Score: 3

Blockcypher API shows only the example of how to compose a transaction with a single input, therefore, it might look like the array of addresses will do the job, but no. If you'll do this by passing addresses into one array of inputs:

```
curl -d '{"inputs":[{"addresses":["addr1", "addr2"]}],"outputs":[{"addresses":["addr3"],"value":100000000}]}' https://api.blockcypher.com/v1/btc/test3/txs/new

```

You'll have only zero element grabbed from the addresses array from the inputs:

```
"tx": {
    "block_height": -1,
    "block_index": -1,
    "hash": "002407bd35a6d0026cf0f5a018bd27311702560c03f1f64478105a547c91d895",
    "addresses": [
      "addr1", (inputs.addresses[0])
      "addr3" (outputs.addresses[0])
    ] ...

```

*(Please note that I haven't included the whole tx blocks, only the ones containing the addresses.)*

API will consider that you're using only one input, and may throw you an error if the value will be too big than the input's wallet balance.

```
"Not enough funds in 1 inputs to pay for 1 outputs, missing -X"

```

**To create the tx with several inputs**, you'll have to pass arrays of addresses separately:

```
curl -d '{"inputs":[{"addresses":["addr1"]}, {"addresses":["addr2"]}],"outputs":[{"addresses":["addr3"],"value":100000000}]}' https://api.blockcypher.com/v1/btc/test3/txs/new

```

This will give you the correct response, and the correct amount of inputs:

```
"tx": {
    "block_height": -1,
    "block_index": -1,
    "hash": "ebcc8132c33a672cdd695a8953db503954abefa18bfd4727ea44f67b92c5ab6c",
    "addresses": [
      "addr1",
      "addr2",
      "addr3"
    ] ...

```

In conclusion, it seems that the API itself is designed that way, at least at the moment of writing this answer.

> **Comments:**
> **username_2**: Oh wow… Not at all what I expected. Thank you for digging into that and providing the correction!  
> **username_1**: You're welcome! :) I've been struggling with it myself, and eventually came up with such a solution.  

---

### Answer by username_2 on 2020-04-25. Score: 1

Disclaimer: I have not tried this, I just glanced at the API documentation. H/T to [username_1](https://bitcoin.stackexchange.com/a/96803/5406) for providing the correct syntax.

As the API documentation for [Creating Transactions](https://www.blockcypher.com/dev/bitcoin/#creating-transactions) specifies, you provide the addresses that you received your funds to in the `inputs` parameter. The API documentation has this example using curl:

```
curl -d '{"inputs":[{"addresses": ["CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9"]}],"outputs":[{"addresses": ["C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn"], "value": 1000000}]}' https://api.blockcypher.com/v1/bcy/test/txs/new

```

For multiple addresses, you need to provide each address in a separate object with the property `addresses` to the inputs object: `{"inputs":[{"addresses":"addr1"}, {"addresses":"addr2"}],"outputs":…}`. According to the documentation, the response will be an unsigned transaction which you'll have to sign locally with the corresponding private keys. The BlockCypher documentation links to their "signer tool" at this point.

Note: all value not explicitly assigned to a recipient in a Bitcoin transaction will go to transaction fees. If you are using two 1 BTC inputs and are sending 1.5 BTC to a recipient, be sure that you add a second output to assign your `0.5 BTC – transaction fees` of change to one of your own addresses. Otherwise you will pay 0.5 BTC to the miner confirming your transaction. Be sure to verify that the transaction is doing what you intend to before signing it.

**I would firmly recommend that you build a few transactions with testnet coins to get the hang of it.**


---

