To get started I'd recommend you familiarize yourself with the JSON-RPC API that is built-in with bitcoin-core (https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)).
Once you have installed bitcoin you need to configure it. You do this by creating a bitcoin.conf
file and setting our options inside of it.
Create a new file in your text editor and make sure you have a RPC username/password and activate the daemon by setting it to 1.
rpcuser=someusername
rpcpassword=somepassword
daemon=1
Save your text file as bitcoin.conf in your /bitcoin directory. You may need to do sudo apt-get update
first. Bitcoin will be installed in ~/.bitcoin
You should now be able to execute bitcoind and let it sync with the network. Navigate to your bitcoin directory and type in bitcoind in your shell.
bitcoind
Give it a few minutes to start syncing but you can verify the status of your node by typing
bitcoin-cli getblockchaininfo
Now you need to wait for the syncing to finish.
If you check the bitcoin wiki JSON-RPC page you will see references for many different languages. The library recommended for PHP is the EasyBitcoinPHPLibarary. The easiest way to get the library is to visit the GitHub page (https://github.com/aceat64/EasyBitcoin-PHP)
The easybitcoin library makes cURL requests to bitcoind's JSON-RPC 8332 port.
Copy the contents of the easybitcoin.php and save it as a new php file called easybitcoin.php. Make sure you place this file in your web server directory as you will need to require(); it in you PHP code.
Now you can start making calls to your bitcoind server through PHP, for example to get the balance of your node...
<?php
require("easybitcoin.php");
$bitcoin = new Bitcoin("someusername", "somepassword");
$balance = $bitcoin->getbalance();
print_r($balance);
?>
You can also create new addresses, by changing getbalance()
in the above example to getnewaddress();
. If you want to add a label for this new address just include it in the parenthesis.
$info = $bitcoin->getnewaddress("Nakamoto");
You will see a brand new bitcoin address that has been added to your node and can start accepting transactions.