IceColdTommy (OP)
|
|
August 08, 2014, 03:25:17 AM Last edit: August 08, 2014, 10:10:59 AM by IceColdTommy |
|
What am i doing wrong i have [code] $json = json_encode($unspent); $funds = $calc - '0.0001'; $sfunds = ('{\"TTBVKPAqc6wvE3UHHYDDnshxyPEu33Zxjf\":'.$funds.'}'); $crt = $btc->createrawtransaction("$json,$sfunds"); print_r ($crt);
$json,$sfunds output is ["{\"txid\":\"9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820\",\"vout\":0}","{\"txid\":\"c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9\",\"vout\":1}"],{\"TTBVKPAqc6wvE3UHHYDDnshxyPEu33Zxjf\":1099.9599}
If i type it directly in console it creates the rawtransaction But when i try from php i get Array ( [.code] => -1 [message] => createrawtransaction [{"txid":txid,"vout":n},...] {address:amount,...} Create a transaction spending given inputs (array of objects containing transaction id and output number), sending to given address(es). Returns hex-encoded raw transaction. Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network. )
[/code]
|
|
|
|
elbandi
|
|
August 08, 2014, 10:22:04 AM |
|
["{...}","{..}"]
$unspent variable is wrong format, because json_encode create a string array, not a object array.
use var_dump($unpent); to view the variable data type
|
|
|
|
IceColdTommy (OP)
|
|
August 08, 2014, 10:30:36 AM |
|
["{...}","{..}"]
$unspent variable is wrong format, because json_encode create a string array, not a object array.
use var_dump($unpent); to view the variable data type
this is the var_dump output array (size=2) 0 => string '{"txid":"9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820","vout":0}' (length=84) 1 => string '{"txid":"c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9","vout":1}' (length=84)
|
|
|
|
fbueller
|
|
August 08, 2014, 01:44:07 PM |
|
Since you're using a JSON rpc interface, you pass PHP arrays, which get converted to JSON by your library.
$inputs = array( array('txid' => '9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820', 'vout' => 0), array('txid' => 'c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9', 'vout' => 1) );
$outputs = array('TTBVKPAqc6wvE3UHHYDDnshxyPEu33Zxjf' => 1.01234567); $raw = $btc->createrawtransaction($inputs, $outputs);
FYI, your JSON before didn't look correct, since you have quotes around the individual inputs? Run json_encode() on each of the above to see what bitcoind will accept if you did it by the CLI.
|
Bitwasp Developer.
|
|
|
elbandi
|
|
August 08, 2014, 04:35:49 PM |
|
["{...}","{..}"]
$unspent variable is wrong format, because json_encode create a string array, not a object array.
use var_dump($unpent); to view the variable data type
this is the var_dump output array (size=2) 0 => string '{"txid":"9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820","vout":0}' (length=84) 1 => string '{"txid":"c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9","vout":1}' (length=84)
yeah, this is a string array. you can convert it to object, and back to json, foreach($unspent as $idx => $output) { $unspend[$idx] = json_decode($unspend[$idx]); } $json = json_encode($unspent);
if you dont do other things with $unspent, you can just concat it: $json = "[" . implode(",", $unpsent) . "]";
|
|
|
|
IceColdTommy (OP)
|
|
August 08, 2014, 06:15:20 PM |
|
["{...}","{..}"]
$unspent variable is wrong format, because json_encode create a string array, not a object array.
use var_dump($unpent); to view the variable data type
this is the var_dump output array (size=2) 0 => string '{"txid":"9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820","vout":0}' (length=84) 1 => string '{"txid":"c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9","vout":1}' (length=84)
yeah, this is a string array. you can convert it to object, and back to json, foreach($unspent as $idx => $output) { $unspend[$idx] = json_decode($unspend[$idx]); } $json = json_encode($unspent);
if you dont do other things with $unspent, you can just concat it: $json = "[" . implode(",", $unpsent) . "]"; i don't do anything else with it but both of the codes, turn $json in string so its not accepted by bitcoind
|
|
|
|
IceColdTommy (OP)
|
|
August 08, 2014, 06:32:04 PM |
|
Since you're using a JSON rpc interface, you pass PHP arrays, which get converted to JSON by your library.
$inputs = array( array('txid' => '9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820', 'vout' => 0), array('txid' => 'c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9', 'vout' => 1) );
$outputs = array('TTBVKPAqc6wvE3UHHYDDnshxyPEu33Zxjf' => 1.01234567); $raw = $btc->createrawtransaction($inputs, $outputs);
FYI, your JSON before didn't look correct, since you have quotes around the individual inputs? Run json_encode() on each of the above to see what bitcoind will accept if you did it by the CLI.
i passed this directly thru php and it work, thanks but its unusable in my code i get those inputs from listunspent
|
|
|
|
IceColdTommy (OP)
|
|
August 08, 2014, 07:42:09 PM |
|
Well it turns out solution was way to easy, so i finally managed to work it out.
|
|
|
|
|