<p>You are providing it an Object in JSON, not an array just as the error states. </p>

<pre><code> return {"txid": sourcetransaction['txid'] ,"vout":sourcetransaction['vout']}
</code></pre>

<p>I would try creating it from a dictionary and then adding it to a list instead of building it from a string, something like: </p>

<pre><code>&gt;&gt;&gt; inputs = {}   #create the dictionary
&gt;&gt;&gt; inputs["txid"]=sourcetransaction['txid']  #add the value to the dictionary key 'txid'
&gt;&gt;&gt; inputs["vout"]=sourcetransaction['vout']  #add nout value to key 'vout'  

&gt;&gt;&gt; inputs
{'txid': 'a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c', 'vout': 0}

&gt;&gt;&gt; inputsList=[inputs] #add dictionary input to list 
&gt;&gt;&gt; inputsList
[{'txid': 'a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c', 'vout': 0}]
</code></pre>

<p>Also noted in the example <a href="https://github.com/laanwj/bitcoin-python/blob/master/src/bitcoinrpc/connection.py#L293" rel="nofollow noreferrer">from the source</a>:     </p>

<pre><code>def createrawtransaction(self, inputs, outputs):
    """
    Creates a raw transaction spending given inputs
    (a list of dictionaries, each containing a transaction id and an output number),
    sending to given address(es).
    Returns hex-encoded raw transaction.
    Example usage:
    &gt;&gt;&gt; conn.createrawtransaction(
            [{"txid": "a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c",
              "vout": 0}],
            {"mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT":50})
    Arguments:
    - *inputs* -- A list of {"txid": txid, "vout": n} dictionaries.
    - *outputs* -- A dictionary mapping (public) addresses to the amount
                   they are to be paid.
    """
    return self.proxy.createrawtransaction(inputs, outputs)
</code></pre>

CC BY-SA 4.0
2018-09-01T19:39:00.983Z
thanks! yeah i figured im just still clueless how python typing works .. :)  trying it this way
Sonic Soul
CC BY-SA 4.0
2018-09-01T19:49:08.427Z
thanks! looks like the string is still ok, i just forgot to include []'s around input when calling the actual api
Sonic Soul
CC BY-SA 4.0
2018-09-01T17:59:13.870Z
2018-09-01T18:19:59.070Z
2018-09-01T18:19:59.070Z
m1xolyd1an
<p>experimenting with JSON RPC API using bitcoinrpc.authproxy for python.</p>

<p>so far it works in all instances accept when i try to create a raw transaction.
somewhere along the way im passing parameters in wrong format. </p>

<p>i created helper methods to create my inputs/outputs like this: </p>

<pre><code>def getTransactionJsonInput(self, sourcetransaction) -&gt; str: 
    return {"txid": sourcetransaction['txid'] ,"vout":sourcetransaction['vout']}

def getTransactionJsonOutput(self, new_address, amount, returnaddress, returnamount) -&gt; str: 
    return {
        new_address: amount,
        returnaddress: returnamount
    }
</code></pre>

<p>and when i print my call to createrawtransaction it appears to be correct </p>

<pre><code>    print('TRANSACTION inputs', [input], type([input]))
    print('TRANSACTION outputs', output, type(output))
    return svc.createrawtransaction(input, output)
</code></pre>

<blockquote>
  <p>TRANSACTION inputs [{'txid': 'sourcetransactionid', 'vout': 1}] &lt;class 'list'&gt;</p>
  
  <p>TRANSACTION outputs {'destinationaddress': 0.012, 'changeaddress': 2.56559703} &lt;class 'dict'&gt;</p>
</blockquote>

<p>error: </p>

<blockquote>
  <p>bitcoinrpc.authproxy.JSONRPCException: -3: Expected type array, got object</p>
</blockquote>

<p><strong>solution</strong></p>

<p>thanks to @m1xolyd1an i was steered in the right direction. All that was missing in my implementation was adding [] around inputs. i added them in print statement but not in the actual call! </p>

<p>before</p>

<pre><code>return svc.createrawtransaction(input, output)
</code></pre>

<p>after</p>

<pre><code>return svc.createrawtransaction([input], output)
</code></pre>

<p>new result: </p>

<blockquote>
  <p>new transaction:  0200000001005134d493cb536a5000b491b0b6dbca6c5187eec67ffb8769fdedac9ec25db40100000000ffffffff02804f12000000000017a914190150e1a961a2509b1d48c4d6cf6b644454cd968757ca4a0f0000000017a91496711dceda7240a6c492b2fabc5d44ab5d4bd19e8700000000</p>
</blockquote>

CC BY-SA 4.0
2018-09-01T16:53:05.780Z
I think you should use double quotes in input like [{"txid":"id", "vout":n}]
Abhishek Sinha
CC BY-SA 4.0
2018-09-01T16:54:32.357Z
@AbhishekSinha i tried that initially, but then it was '"xxxx"' also the error was the same
Sonic Soul
<bitcoin-core><json-rpc><python><createrawtransaction>
bitcoin rpc api createrawtransaction with python returns -3: Expected type array, got object
Sonic Soul
# bitcoin rpc api createrawtransaction with python returns -3: Expected type array, got object

(Asked by: username_0 on 2018-09-01)

experimenting with JSON RPC API using bitcoinrpc.authproxy for python.

so far it works in all instances accept when i try to create a raw transaction.
somewhere along the way im passing parameters in wrong format.

i created helper methods to create my inputs/outputs like this:

```
def getTransactionJsonInput(self, sourcetransaction) -> str: 
    return {"txid": sourcetransaction['txid'] ,"vout":sourcetransaction['vout']}

def getTransactionJsonOutput(self, new_address, amount, returnaddress, returnamount) -> str: 
    return {
        new_address: amount,
        returnaddress: returnamount
    }

```

and when i print my call to createrawtransaction it appears to be correct

```
    print('TRANSACTION inputs', [input], type([input]))
    print('TRANSACTION outputs', output, type(output))
    return svc.createrawtransaction(input, output)

```

> TRANSACTION inputs [{'txid': 'sourcetransactionid', 'vout': 1}] <class 'list'>
>
> TRANSACTION outputs {'destinationaddress': 0.012, 'changeaddress': 2.56559703} <class 'dict'>

error:

> bitcoinrpc.authproxy.JSONRPCException: -3: Expected type array, got object

**solution**

thanks to @username_2 i was steered in the right direction. All that was missing in my implementation was adding [] around inputs. i added them in print statement but not in the actual call!

before

```
return svc.createrawtransaction(input, output)

```

after

```
return svc.createrawtransaction([input], output)

```

new result:

> new transaction: 0200000001005134d493cb536a5000b491b0b6dbca6c5187eec67ffb8769fdedac9ec25db40100000000ffffffff02804f12000000000017a914190150e1a961a2509b1d48c4d6cf6b644454cd968757ca4a0f0000000017a91496711dceda7240a6c492b2fabc5d44ab5d4bd19e8700000000

**Tags:** bitcoin-core, json-rpc, python, createrawtransaction

> **Comments:**
> **username_1**: I think you should use double quotes in input like [{"txid":"id", "vout":n}]  
> **username_0**: @username_1 i tried that initially, but then it was '"xxxx"' also the error was the same  

---

## 1 answers

### Answer by username_2 on 2018-09-01. Score: 2 | Accepted answer

You are providing it an Object in JSON, not an array just as the error states.

```
 return {"txid": sourcetransaction['txid'] ,"vout":sourcetransaction['vout']}

```

I would try creating it from a dictionary and then adding it to a list instead of building it from a string, something like:

```
>>> inputs = {}   #create the dictionary
>>> inputs["txid"]=sourcetransaction['txid']  #add the value to the dictionary key 'txid'
>>> inputs["vout"]=sourcetransaction['vout']  #add nout value to key 'vout'  

>>> inputs
{'txid': 'a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c', 'vout': 0}

>>> inputsList=[inputs] #add dictionary input to list 
>>> inputsList
[{'txid': 'a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c', 'vout': 0}]

```

Also noted in the example [from the source](https://github.com/laanwj/bitcoin-python/blob/master/src/bitcoinrpc/connection.py#L293):

```
def createrawtransaction(self, inputs, outputs):
    """
    Creates a raw transaction spending given inputs
    (a list of dictionaries, each containing a transaction id and an output number),
    sending to given address(es).
    Returns hex-encoded raw transaction.
    Example usage:
    >>> conn.createrawtransaction(
            [{"txid": "a9d4599e15b53f3eb531608ddb31f48c695c3d0b3538a6bda871e8b34f2f430c",
              "vout": 0}],
            {"mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT":50})
    Arguments:
    - *inputs* -- A list of {"txid": txid, "vout": n} dictionaries.
    - *outputs* -- A dictionary mapping (public) addresses to the amount
                   they are to be paid.
    """
    return self.proxy.createrawtransaction(inputs, outputs)

```

> **Comments:**
> **username_0**: thanks! yeah i figured im just still clueless how python typing works .. :)  trying it this way  
> **username_0**: thanks! looks like the string is still ok, i just forgot to include []'s around input when calling the actual api  

---

