Author

Topic: createrawtransaction help php (Read 1050 times)

full member
Activity: 168
Merit: 100
August 08, 2014, 02:42:09 PM
#8
Well it turns out solution was way to easy, so i finally managed to work it out.
full member
Activity: 168
Merit: 100
August 08, 2014, 01:32:04 PM
#7
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
full member
Activity: 168
Merit: 100
August 08, 2014, 01:15:20 PM
#6

["{...}","{..}"]

$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
Code:
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,

Code:
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:

Code:
$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
hero member
Activity: 525
Merit: 531
August 08, 2014, 11:35:49 AM
#5

["{...}","{..}"]

$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
Code:
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,

Code:
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:

Code:
$json = "[" . implode(",", $unpsent) .  "]";
sr. member
Activity: 412
Merit: 287
August 08, 2014, 08:44:07 AM
#4
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.
full member
Activity: 168
Merit: 100
August 08, 2014, 05:30:36 AM
#3

["{...}","{..}"]

$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
Code:
array (size=2)
  0 => string '{"txid":"9bfc817178ec318f772f678173ae715a2ef661f08c838b5cf00b62d78ede4820","vout":0}' (length=84)
  1 => string '{"txid":"c3608c3fc55f6560aa411c9adb3703463e25a0cb2025700aa59c4ab13e245cd9","vout":1}' (length=84)
hero member
Activity: 525
Merit: 531
August 08, 2014, 05:22:04 AM
#2

["{...}","{..}"]

$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
full member
Activity: 168
Merit: 100
August 07, 2014, 10:25:17 PM
#1
Code:
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

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. )
[/code]
Jump to: