Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: vintosalgos223 on May 21, 2013, 04:13:43 PM



Title: Simple Dump Bitcoins Script (JSON-RPC)
Post by: vintosalgos223 on May 21, 2013, 04:13:43 PM
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']."<BR>");
}

}



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


?>



Title: Re: Simple Dump Bitcoins Script (JSON-RPC)
Post by: vintosalgos223 on May 21, 2013, 04:46:13 PM
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."<br>");
echo($bitcoin->sendtoaddress($to, $amount));


I suspect it may have to do with getbalance returning unconfirmed transactions as part of my balance.


Title: Re: Simple Dump Bitcoins Script (JSON-RPC)
Post by: afr0m3n on January 05, 2014, 06:43:36 AM
thanks this is useful


Title: Re: Simple Dump Bitcoins Script (JSON-RPC)
Post by: NoahBuscher on January 05, 2014, 02:31:42 PM
Thanks for sharing! I hope this helps out other members.