Anybody have any idea about how to do it?
- User send the bitcoins
- X% goes to fee wallet
- 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:
<?php
require("easybitcoin.php");
$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");
function fee($fee, $bal){
$final = ($fee / 100) * $bal;
return $final;
}
#account
$account = "pizza";
#fee address
$addFee = "2N9xQyV6itnZNBv5NSLUy8ffXcfopVvP19v";
#Rest address
$addRest = "2MtEzMsT9eedTms9ivEQnjuHPRWw1DHnxyT";
#% charged
$tax = 10;
#balance
$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.