unsure how or why my lockunspent method is not working...
Closed this issue · 6 comments
I have been trying for days, and I cannot seem to understand why the EasyBitcoin.php will not accept my parameters for locking unspent transactions using the rpc calls. Here is the code I am using;
$tx = $bitcoin->masternode('outputs');
$txid = array_keys($tx);
$tx_array = [];
foreach($txid as $locktx) {
$tx_array = [
'txid' => $locktx,
'vout' => (int)$tx[$locktx],
];
$lock = "false";
$lock_mn = $bitcoin->lockunspent($lock, $tx_array);
}
And no matter how I spin it, I keep getting errors like this:
Expected type bool, got string
Has anyone had any success with this rpc command?
$lock = "false";
Have you tried changing this to
$lock = false;
?
@erikdubbelboer yep .... I get this instead;
Expected type array, got object
and here is the var_dump of the txid and vout I am using;
Array
(
[txid] => 14acd0774013685a4cda17246298f21101884f6be7198db36fa5e3ee498fab37
[vout] => 1
)
Try this:
$tx = $bitcoin->masternode('outputs');
$txid = array_keys($tx);
$tx_array = [];
foreach($txid as $locktx) {
$tx_array[] = [
'txid' => $locktx,
'vout' => (int)$tx[$locktx],
];
}
$lock = "false";
$lock_mn = $bitcoin->lockunspent($lock, $tx_array);
some issue @erikdubbelboer ; I get this:
Expected type bool, got string
And my array changed slightly;
Array
(
[0] => Array
(
[txid] => 14acd0774013685a4cda17246298f21101884f6be7198db36fa5e3ee498fab37
[vout] => 1
)
)
Solved!!
$tx = $bitcoin->masternode('outputs');
$txid = array_keys($tx);
$tx_array = [];
foreach($txid as $locktx) {
$tx_array[] = [
'txid' => $locktx,
'vout' => (int)$tx[$locktx],
];
}
$lock = false;
$lock_mn = $bitcoin->lockunspent($lock, $tx_array);
I was missing the []
after $tx_array
in my first comment. I last too many hours on a simple mistake
thanks for the help @erikdubbelboer !
lockunspent
expects an array of objects, you were only giving it one object because you had your call inside your loop instead of out of it.