Bitcoin Forum
September 27, 2018, 10:32:21 PM *
News: ♦♦ New info! Bitcoin Core users absolutely must upgrade to previously-announced 0.16.3 [Torrent]. All Bitcoin users should temporarily trust confirmations slightly less. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Simple Dump Bitcoins Script (JSON-RPC)  (Read 1728 times)
vintosalgos223
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));


?>

1538087541
Hero Member
*
Offline Offline

Posts: 1538087541

View Profile Personal Message (Offline)

Ignore
1538087541
Reply with quote  #2

1538087541
Report to moderator
1538087541
Hero Member
*
Offline Offline

Posts: 1538087541

View Profile Personal Message (Offline)

Ignore
1538087541
Reply with quote  #2

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

Posts: 1538087541

View Profile Personal Message (Offline)

Ignore
1538087541
Reply with quote  #2

1538087541
Report to moderator
vintosalgos223
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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!