<p>Create a unique address, log it to a DB with a reference to the user id. The accounts feature was <a href="https://github.com/bitcoin-dot-org/bitcoin.org/issues/1287" rel="nofollow noreferrer">deprecated in 2016</a>     </p>

<p>Use the walletnotify feature in your bitcoin.conf instead of a cronjob. This will call a file that can take the transaction id(passed as <code>%s</code>) as an input whenever a new transaction is received in your mempool and again once confirmed. Use the transaction id to find the output address(es), if they match an address in your DB credit that account with the value sent to that output.    </p>

<p><strong>Example</strong> of passing the transaction id into a GET of "tx"<br>
     <code>walletnotify = curl http://mysite.com/newdeposit.php?tx=%s</code>   </p>

<p><strong>Example</strong> of what your newdeposit.php file could look like      </p>

<pre><code>&lt;?php
//db connection
$conn = mysqli_connect("localhost", "root", "password", "database_name");
    if (mysqli_connect_errno()){
    echo "Connection to DB failed" . mysqli_connect_error();
    }

//bitcoin node connection
require("easybitcoin.php");
$bitcoin = new Bitcoin("someusername", "somepassword");
$tx = $_GET['tx'];
//sanitize
$tx = mysqli_real_escape_string($conn, $tx);
$getTrans = $bitcoin-&gt;gettransaction($tx);
$confirmations = $getTrans["confirmations"];
if($confirmations !== 1){
die();
} else {
//loop through the outputs
    $countDetails = count($getTrans['details']);
    for($i=0;$i&lt;$countDetails;$i++){
    $getAddress = $getTrans['details'][$i]['address'];
    $getReceive = $getTrans['details'][$i]['category'];
        if($getReceive == "receive"){
        $checkAddy = mysqli_query($conn, "SELECT * FROM users WHERE DEPOSIT_ADDRESS = '$getAddress'");
        $doCheckAddy = mysqli_num_rows($checkAddy);
            if($doCheckAddy == 1){
            $amount = $getTrans['details'][$i]['amount'];
            $amount = $amount * 100000000;
            $updateBalance = "UPDATE users SET BALANCE = BALANCE + '$amount' WHERE DEPOSIT_ADDRESS = '$getAddress'";
            $doUpdateBalance = mysqli_query($conn, $updateBalance);
            }
        }
    }
}
?&gt;
</code></pre>

<p>As for re-launching after a crash you could look into using a bash script on a cronjob. I found the below example on <a href="https://bitcointalk.org/index.php?topic=2208506.msg22239706#msg22239706" rel="nofollow noreferrer">bitcointalk</a>    </p>

<pre><code>#!/bin/sh

ps auxw | grep bitcoind | grep -v grep &gt; /dev/null

if [ $? != 0 ]
then
        /bitcoind start &gt; /dev/null
fi
</code></pre>

<p>EDIT: It's important to note this is not meant as a hack-proof solution, but a simple example to show how you could approach your solution. </p>

CC BY-SA 4.0
2018-05-05T02:35:45.877Z
2018-05-05T02:49:49.093Z
2018-05-05T02:49:49.093Z
m1xolyd1an
<p>You should check out <code>walletnotify</code>: everytime a transaction hits your wallet it will fire a command or script off.</p>

<blockquote>
  <p>Walletnotify will run a shell command everytime something changes in your wallet.</p>
</blockquote>

<p>I like <a href="https://github.com/damonp/walletnotify" rel="nofollow noreferrer">this repo</a>.</p>

CC BY-SA 3.0
2016-09-29T13:40:40.677Z
2018-02-23T04:02:37.157Z
2018-02-23T04:02:37.157Z
Web Weave
<p>As Web Weave mentioned, definitely check out the <code>walletnotify</code> callback. this is the easiest way.</p>

<p>the only thing that I want to mention tho (without knowing the nitty gritty), is that I don't know if this <code>walletnotify</code> is guaranteed to run, and what error do we get when it doesn't. I suppose it's logged but error-handling on the bitcoind layer isn't very clear.</p>

<p>alternatively, to have a supposedly more robust process, it's possible to scan transactions in every block, and find the relevant ones. you need to write more code in this case, but you are making active calls instead of listening for notifications.</p>

CC BY-SA 4.0
2018-05-05T02:40:27.483Z
2018-05-05T02:40:27.483Z
Will Gu
<p>I want to implement payments using Bitcoin without any 3rd party services. I already installed full node on my server and configured RPC API. What should I do next?</p>

<p>Now I plan to work in the following way:</p>

<ol>
<li>Create wallets for all existing and new users using <strong>getaccountaddress</strong> method and store address in DB.</li>
<li>Set up an every minute cron job which will calls <strong>listtransactions * 1000</strong>, loop through transactions to find new which has more than <strong>N</strong> confirmations. </li>
<li>Store filtered transactions in DB, find user by address and add money to balance.</li>
<li>Send received bitcoins to another (main) wallet using <strong>sendfrom</strong> method.</li>
</ol>

<p>I have some doubts about the stability of the solution. I do not think that users will perform more than 1,000 transactions per minute, so when all is working as planned, it looks as pretty stable solution. But what, if, for example, bitcoind (or entire server) will hang / fail / break down? How easy will be to handle payments that were not processed before?</p>

<p>Maybe there is a better way for receiving payments? Thank you.</p>

<bitcoind><payment><micropayments>
What is the right way to accept bitcoin payments using bitcoind?
kopaty4
# What is the right way to accept bitcoin payments using bitcoind?

(Asked by: username_0 on 2016-09-29)

I want to implement payments using Bitcoin without any 3rd party services. I already installed full node on my server and configured RPC API. What should I do next?

Now I plan to work in the following way:

1. Create wallets for all existing and new users using **getaccountaddress** method and store address in DB.
2. Set up an every minute cron job which username_3 calls **listtransactions \* 1000**, loop through transactions to find new which has more than **N** confirmations.
3. Store filtered transactions in DB, find user by address and add money to balance.
4. Send received bitcoins to another (main) wallet using **sendfrom** method.

I have some doubts about the stability of the solution. I do not think that users username_3 perform more than 1,000 transactions per minute, so when all is working as planned, it looks as pretty stable solution. But what, if, for example, bitcoind (or entire server) username_3 hang / fail / break down? How easy username_3 be to handle payments that were not processed before?

Maybe there is a better way for receiving payments? Thank you.

**Tags:** bitcoind, payment, micropayments


---

## 3 answers

### Answer by username_1 on 2018-05-05. Score: 1

Create a unique address, log it to a DB with a reference to the user id. The accounts feature was [deprecated in 2016](https://github.com/bitcoin-dot-org/bitcoin.org/issues/1287)

Use the walletnotify feature in your bitcoin.conf instead of a cronjob. This username_3 call a file that can take the transaction id(passed as `%s`) as an input whenever a new transaction is received in your mempool and again once confirmed. Use the transaction id to find the output address(es), if they match an address in your DB credit that account with the value sent to that output.

**Example** of passing the transaction id into a GET of "tx"  
`walletnotify = curl http://mysite.com/newdeposit.php?tx=%s`

**Example** of what your newdeposit.php file could look like

```
<?php
//db connection
$conn = mysqli_connect("localhost", "root", "password", "database_name");
    if (mysqli_connect_errno()){
    echo "Connection to DB failed" . mysqli_connect_error();
    }

//bitcoin node connection
require("easybitcoin.php");
$bitcoin = new Bitcoin("someusername", "somepassword");
$tx = $_GET['tx'];
//sanitize
$tx = mysqli_real_escape_string($conn, $tx);
$getTrans = $bitcoin->gettransaction($tx);
$confirmations = $getTrans["confirmations"];
if($confirmations !== 1){
die();
} else {
//loop through the outputs
    $countDetails = count($getTrans['details']);
    for($i=0;$i<$countDetails;$i++){
    $getAddress = $getTrans['details'][$i]['address'];
    $getReceive = $getTrans['details'][$i]['category'];
        if($getReceive == "receive"){
        $checkAddy = mysqli_query($conn, "SELECT * FROM users WHERE DEPOSIT_ADDRESS = '$getAddress'");
        $doCheckAddy = mysqli_num_rows($checkAddy);
            if($doCheckAddy == 1){
            $amount = $getTrans['details'][$i]['amount'];
            $amount = $amount * 100000000;
            $updateBalance = "UPDATE users SET BALANCE = BALANCE + '$amount' WHERE DEPOSIT_ADDRESS = '$getAddress'";
            $doUpdateBalance = mysqli_query($conn, $updateBalance);
            }
        }
    }
}
?>

```

As for re-launching after a crash you could look into using a bash script on a cronjob. I found the below example on [bitcointalk](https://bitcointalk.org/index.php?topic=2208506.msg22239706#msg22239706)

```
#!/bin/sh

ps auxw | grep bitcoind | grep -v grep > /dev/null

if [ $? != 0 ]
then
        /bitcoind start > /dev/null
fi

```

EDIT: It's important to note this is not meant as a hack-proof solution, but a simple example to show how you could approach your solution.


---

### Answer by username_2 on 2016-09-29. Score: 1

You should check out `walletnotify`: everytime a transaction hits your wallet it username_3 fire a command or script off.

> Walletnotify username_3 run a shell command everytime something changes in your wallet.

I like [this repo](https://github.com/damonp/walletnotify).


---

### Answer by username_3 on 2018-05-05. Score: 0

As username_2 mentioned, definitely check out the `walletnotify` callback. this is the easiest way.

the only thing that I want to mention tho (without knowing the nitty gritty), is that I don't know if this `walletnotify` is guaranteed to run, and what error do we get when it doesn't. I suppose it's logged but error-handling on the bitcoind layer isn't very clear.

alternatively, to have a supposedly more robust process, it's possible to scan transactions in every block, and find the relevant ones. you need to write more code in this case, but you are making active calls instead of listening for notifications.


---

