Title: createrawtransaction help php Post by: IceColdTommy on August 08, 2014, 03:25:17 AM Code: What am i doing wrong $json,$sfunds output is Code: ["{\"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 Code: 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. ) Title: Re: createrawtransaction help php Post by: elbandi on 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 Title: Re: createrawtransaction help php Post by: IceColdTommy on 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 Code: array (size=2) Title: Re: createrawtransaction help php Post by: fbueller on 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. Title: Re: createrawtransaction help php Post by: elbandi on 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 Code: array (size=2) Code: foreach($unspent as $idx => $output) { if you dont do other things with $unspent, you can just concat it: Code: $json = "[" . implode(",", $unpsent) . "]"; Title: Re: createrawtransaction help php Post by: IceColdTommy on 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 Code: array (size=2) Code: foreach($unspent as $idx => $output) { if you dont do other things with $unspent, you can just concat it: Code: $json = "[" . implode(",", $unpsent) . "]"; Title: Re: createrawtransaction help php Post by: IceColdTommy on 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. i passed this directly thru php and it work, thanks$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. but its unusable in my code i get those inputs from listunspent Title: Re: createrawtransaction help php Post by: IceColdTommy on August 08, 2014, 07:42:09 PM Well it turns out solution was way to easy, so i finally managed to work it out.
|