Author

Topic: Simple Dump Bitcoins Script (JSON-RPC) (Read 1813 times)

newbie
Activity: 14
Merit: 0
January 05, 2014, 09:31:42 AM
#4
Thanks for sharing! I hope this helps out other members.
newbie
Activity: 26
Merit: 0
January 05, 2014, 01:43:36 AM
#3
thanks this is useful
newbie
Activity: 10
Merit: 0
I simplified it a bit for my needs,

Code:

$bitcoin = new jsonRPCClient('http://bitsuer:bitpw@localhost:1234/');

$to = "toaddresshere";

$amount = floatval($bitcoin->getbalance());

echo("Sending ".$amount." to ".$to."
");
echo($bitcoin->sendtoaddress($to, $amount));


I suspect it may have to do with getbalance returning unconfirmed transactions as part of my balance.
newbie
Activity: 10
Merit: 0
I'm writing a PHP script to dump Bitcoins from my website's wallet to my other wallet, I put this in a cron job that runs every few minutes to keep my coins pretty safe. The script works if I don't try to send anywhere near the full balance however if I send slightly less it fails and I believe it's due to the fact of TX fees. Below is my current code. I'd like some suggestions as to how to calculate the TX fee if this is causing the problem and how to account for it.

Code:
require_once 'jsonRPCClient2.php';
error_reporting(-1);

$bitcoin = new jsonRPCClient('http://coinusr:coinpw:1234/');

$to = "otherwalletaddresshere";

$amount = 0.00;

foreach($bitcoin->listreceivedbyaccount() as $key=>$value){

if($bitcoin->getbalance((string)$value['account']) > "0")
{
$amount = $amount + $value['amount'];
echo($value['account']." has ".$value['amount']."
");
}

}



echo("Sending ".$amount." to ".$to."
");
echo($bitcoin->sendtoaddress($to, $amount));


?>

Jump to: