<p>Problem solved using "sendmany":</p>

<pre><code>&lt;?php
#SENDMANY WORKING
require("easybitcoin.php");
$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

$account = "pizza";

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

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

print_r($send);

?&gt;
</code></pre>

CC BY-SA 4.0
2019-03-07T15:05:08.463Z
2019-12-07T00:52:42.717Z
2019-12-07T00:52:42.717Z
Coins Of Pixel
<p>Anybody have any idea about how to do it? </p>

<ol>
<li>User send the bitcoins</li>
<li>X% goes to fee wallet</li>
<li>remaining funds goes to service wallet</li>
</ol>

<p><a href="https://i.sstatic.net/sh5wH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sh5wH.png" alt="Scheme"></a></p>

<p>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.</p>

<pre><code>$sendingFee = $bitcoin-&gt;sendfrom($account, $addFee, $feeFormated, 0);
$sendingRest = $bitcoin-&gt;sendfrom($account, $addRest, $restMath, 0);
</code></pre>

<p>This is my code:</p>

<pre><code>&lt;?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-&gt;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-&gt;sendfrom($account, $addFee, $feeFormated, 0);

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

$err = $bitcoin-&gt;error;

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

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

echo var_dump($sendingFee) . "&lt;br&gt;&lt;br&gt;";
echo var_dump($sendingRest) . "&lt;br&gt;&lt;br&gt;";


?&gt;
</code></pre>

<p>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. </p>

<p>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. </p>

<p>Thanks in advance.</p>

CC BY-SA 4.0
2020-03-11T04:58:20.187Z
Any updates on this?
sdfsdf
<json-rpc><script><php>
How to split the funds and send X% to fee wallet and the remaining funds to another wallet?
Coins Of Pixel
# How to split the funds and send X% to fee wallet and the remaining funds to another wallet?

(Asked by: username_0 on 2019-03-07)

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

[![Scheme](https://i.sstatic.net/sh5wH.png)](https://i.sstatic.net/sh5wH.png)

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.

**Tags:** json-rpc, script, php

> **Comments:**
> **username_1**: Any updates on this?  

---

## 1 answers

### Answer by username_0 on 2019-03-07. Score: 1

Problem solved using "sendmany":

```
<?php
#SENDMANY WORKING
require("easybitcoin.php");
$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

$account = "pizza";

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

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

print_r($send);

?>

```


---

