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 @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!
before
return svc.createrawtransaction(input, output)
after
return svc.createrawtransaction([input], output)
new result:
new transaction: 0200000001005134d493cb536a5000b491b0b6dbca6c5187eec67ffb8769fdedac9ec25db40100000000ffffffff02804f12000000000017a914190150e1a961a2509b1d48c4d6cf6b644454cd968757ca4a0f0000000017a91496711dceda7240a6c492b2fabc5d44ab5d4bd19e8700000000