Walletnotify must be outlined in your bitcoin.conf file,
instance:
walletnotify = /usr/bin/php some/path/newdeposit.php?tx=%s
Within the above instance each time there’s a new transaction in your pockets, the newdeposit.php script will run and the transaction ID shall be saved in a GET named “tx”.
Then we will pull the transaction id from the tx GET and put it via a gettransaction
command.
$tx = $_GET['tx'];
$getTrans = $bitcoin->gettransaction($tx);
From there we have to look via the API response, see if it has at the least as soon as affirmation, and the way a lot was despatched. We’ll do that by working a loop, checking for the “obtain” class. If there’s a match you are able to do no matter you need in your database.
$confirmations = $getTrans["confirmations"];
if($confirmations < 1){
die();
} else {
$countDetails = rely($getTrans['details']);
for($i=0;$i<$countDetails;$i++){
$getAddress = $getTrans['details'][$i]['address'];
$getReceive = $getTrans['details'][$i]['category'];
if($getAddress == $myAddress && $getReceive == "obtain"){
$quantity = $getTrans['details'][$i]['amount'];
$quantity = $quantity * 100000000;
//do one thing with $quantity
}
}
}
Walletnotify solely fires twice. As soon as when the transaction first seems on the community, and a second time after it has been included in a block(one affirmation).
Remember to multiply the quantity by 100 million to show it into satoshis so you are not working with floats.