<p>Walletnotify needs to be defined in your bitcoin.conf file,
example:</p>
<pre><code>walletnotify = /usr/bin/php some/path/newdeposit.php?tx=%s    
</code></pre>
<p>In the above example every time there is a new transaction on your wallet, the newdeposit.php script will run and the transaction ID will be stored in a GET named &quot;tx&quot;.</p>
<p>Then we can pull the transaction id from the tx GET and put it through a <code>gettransaction</code> command.</p>
<pre><code>$tx = $_GET['tx'];
$getTrans = $bitcoin-&gt;gettransaction($tx);
</code></pre>
<p>From there we need to look through the API response, see if it has at least once confirmation, and how much was sent. We'll do this by running a loop, checking for the &quot;receive&quot; category. If there is a match you can do whatever you want in your database.</p>
<pre><code>$confirmations = $getTrans[&quot;confirmations&quot;];

if($confirmations &lt; 1){
die();

} else {
 $countDetails = count($getTrans['details']);
 for($i=0;$i&lt;$countDetails;$i++){
   $getAddress = $getTrans['details'][$i]['address'];
   $getReceive = $getTrans['details'][$i]['category'];
  
   if($getAddress == $myAddress &amp;&amp; $getReceive == &quot;receive&quot;){
    $amount = $getTrans['details'][$i]['amount'];
    $amount = $amount * 100000000;
    //do something with $amount
   }

 }
 
}
</code></pre>
<p>Walletnotify only fires twice. Once when the transaction first appears on the network, and a second time after it has been included in a block(one confirmation).</p>
<p>Don't forget to multiply the amount by 100 million to turn it into satoshis so you're not working with floats.</p>

CC BY-SA 4.0
2020-12-04T21:55:39.033Z
2020-12-04T22:02:50.893Z
2020-12-04T22:02:50.893Z
m1xolyd1an
<p>If you insist on using bitcoind directly, you could always use the gettransaction rpc call to get transaction info on that transaction.</p>
<p>Hopefully you're using xpubs or at least a list of pre-imported addresses, and not using that bitcoind to manage your wallet/generate new addresses itself though. You shouldn't keep your private key on the live bitcoind node connected to your public ecommerce site.</p>

CC BY-SA 4.0
2020-12-04T17:07:55.313Z
thank you for your answer! actually i'm working on a project for which i have to add bitcoin payment using rpc user and password! i though i can generate a new address using bitcoind node for each payment and i didn't know that it is dangerous...
Valometrics.com
CC BY-SA 4.0
2020-12-04T17:14:41.917Z
Yes, it's risky to have your private keys on a live production server because all someone needs to do is break into your ecommerce site and use RPC calls to empty out your wallet. Generally we like to use xpub keys to generate addresses and that way we can keep the private keys somewhere else.
ieatpizza
CC BY-SA 4.0
2020-12-04T17:02:04.563Z
2020-12-04T17:02:04.563Z
ieatpizza
<p>I'm trying to add bitcoin payment for my ecommerce website. I have installed bitcoind on the server and i've set the notify wallet parameter in bitcoin.conf. the issue i have now is how to know that the client have sent the exact needed amount for products they bought.</p>
<p>Actually, the client can send a lower amount to my wallet and notify wallet will be generated. Please help to handle this issue.</p>

<transactions><bitcoind>
Transaction amount for bitcoin payment gateway
Valometrics.com
# Transaction amount for bitcoin payment gateway

(Asked by: username_0 on 2020-12-04)

I'm trying to add bitcoin payment for my ecommerce website. I have installed bitcoind on the server and i've set the notify wallet parameter in bitcoin.conf. the issue i have now is how to know that the client have sent the exact needed amount for products they bought.

Actually, the client can send a lower amount to my wallet and notify wallet will be generated. Please help to handle this issue.

**Tags:** transactions, bitcoind


---

## 2 answers

### Answer by username_1 on 2020-12-04. Score: 1

Walletnotify needs to be defined in your bitcoin.conf file,
example:

```
walletnotify = /usr/bin/php some/path/newdeposit.php?tx=%s    

```

In the above example every time there is a new transaction on your wallet, the newdeposit.php script will run and the transaction ID will be stored in a GET named "tx".

Then we can pull the transaction id from the tx GET and put it through a `gettransaction` command.

```
$tx = $_GET['tx'];
$getTrans = $bitcoin->gettransaction($tx);

```

From there we need to look through the API response, see if it has at least once confirmation, and how much was sent. We'll do this by running a loop, checking for the "receive" category. If there is a match you can do whatever you want in your database.

```
$confirmations = $getTrans["confirmations"];

if($confirmations < 1){
die();

} else {
 $countDetails = count($getTrans['details']);
 for($i=0;$i<$countDetails;$i++){
   $getAddress = $getTrans['details'][$i]['address'];
   $getReceive = $getTrans['details'][$i]['category'];
  
   if($getAddress == $myAddress && $getReceive == "receive"){
    $amount = $getTrans['details'][$i]['amount'];
    $amount = $amount * 100000000;
    //do something with $amount
   }

 }
 
}

```

Walletnotify only fires twice. Once when the transaction first appears on the network, and a second time after it has been included in a block(one confirmation).

Don't forget to multiply the amount by 100 million to turn it into satoshis so you're not working with floats.


---

### Answer by username_2 on 2020-12-04. Score: 1

If you insist on using bitcoind directly, you could always use the gettransaction rpc call to get transaction info on that transaction.

Hopefully you're using xpubs or at least a list of pre-imported addresses, and not using that bitcoind to manage your wallet/generate new addresses itself though. You shouldn't keep your private key on the live bitcoind node connected to your public ecommerce site.

> **Comments:**
> **username_0**: thank you for your answer! actually i'm working on a project for which i have to add bitcoin payment using rpc user and password! i though i can generate a new address using bitcoind node for each payment and i didn't know that it is dangerous...  
> **username_2**: Yes, it's risky to have your private keys on a live production server because all someone needs to do is break into your ecommerce site and use RPC calls to empty out your wallet. Generally we like to use xpub keys to generate addresses and that way we can keep the private keys somewhere else.  

---

