Bitcoin Forum
May 01, 2024, 08:37:00 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Simple Dump Bitcoins Script (JSON-RPC)  (Read 1796 times)
vintosalgos223 (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
May 21, 2013, 04:13:43 PM
 #1

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));


?>

1714595820
Hero Member
*
Offline Offline

Posts: 1714595820

View Profile Personal Message (Offline)

Ignore
1714595820
Reply with quote  #2

1714595820
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714595820
Hero Member
*
Offline Offline

Posts: 1714595820

View Profile Personal Message (Offline)

Ignore
1714595820
Reply with quote  #2

1714595820
Report to moderator
1714595820
Hero Member
*
Offline Offline

Posts: 1714595820

View Profile Personal Message (Offline)

Ignore
1714595820
Reply with quote  #2

1714595820
Report to moderator
vintosalgos223 (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 0


View Profile
May 21, 2013, 04:46:13 PM
 #2

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.
afr0m3n
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
January 05, 2014, 06:43:36 AM
 #3

thanks this is useful
NoahBuscher
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile WWW
January 05, 2014, 02:31:42 PM
 #4

Thanks for sharing! I hope this helps out other members.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!