Anybody have any idea about how to do it?

  1. User send the bitcoins
  2. X% goes to fee wallet
  3. remaining funds goes to service wallet


I'm trying to use the "sendfrom" but it's not working because he only send the fee amount (or the first call), never the rest.

$sendingFee = $bitcoin->sendfrom($account, $addFee, $feeFormated, 0);
$sendingRest = $bitcoin->sendfrom($account, $addRest, $restMath, 0);

This is my code:


$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

function fee($fee, $bal){
    $final = ($fee / 100) * $bal;
    return $final;

$account = "pizza";

#fee address
$addFee = "2N9xQyV6itnZNBv5NSLUy8ffXcfopVvP19v";

#Rest address
$addRest = "2MtEzMsT9eedTms9ivEQnjuHPRWw1DHnxyT";

#% charged
$tax = 10;

$balance = $bitcoin->getbalance($account, 1);

#do a math to remove X%
$feeMath = fee($tax, $balance);

#I was receiving "invalid amount" error. Fixed with this, I was giving 9 instead of 8 after zero. See satoshis for more.
$feeFormated = number_format($feeMath, 8);

#remove the fee from current balance
$restMath = $balance - $feeFormated;

#send the fee to the address xxxx
$sendingFee = $bitcoin->sendfrom($account, $addFee, $feeFormated, 0);

#send the balance minus fee to the address yyy
$sendingRest = $bitcoin->sendfrom($account, $addRest, $restMath, 0);

$err = $bitcoin->error;

#Print message for control
print_r("Fee <b>TXID</b> = " . $sendingFee . " Amount sent = " . "<b>" . $feeFormated . "</b><br><br>");
print_r("Rest <b>TXID</b> = " . $sendingRest . " Amount sent = " . "<b>" . $restMath . "</b><br><br>");

print_r("It's not working because: " . $err);

echo var_dump($sendingFee) . "<br><br>";
echo var_dump($sendingRest) . "<br><br>";


It's not perfect (far from this) but please understand, I'm not a php guy, even a programmer, I'm just working in a personal project as a hobby.

Maybe should I use "sendmany"? If so, how to use this with php? I saw some examples on internet but nothing showing how to use with php and variables.

Thanks in advance.


Problem solved using "sendmany":

$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

$account = "pizza";

$arrayRec = array("2MsWztzmaxnsU3xetrKsD4E9ep4r2gYtXj9" => "0.00111", 
                "2Mt7dkQiyExrNQTXu9D3qoCpWg3J5TJy9Up" => "0.00222" );

$send = $bitcoin->sendmany($account, $arrayRec);



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.