PHP developer intro

From Bitcoin Wiki
Revision as of 09:38, 21 March 2011 by Genjix (talk | contribs)
Jump to: navigation, search

For the sake of this tutorial we assume an Ubuntu server running with PHP. The use case here is integrating a shopping system to accept Bitcoins. We assume some knowledge of Bitcoin and experience in PHP.

You can substitute any other language here for PHP. See the associated API reference pages for info on other languages.

Setting up Bitcoin

You will run Bitcoin in daemon mode. The way PHP communicates is through localhost HTTP requests. You use a library called JSON-RPC to call the various functions. It will respond back with a JSON object.

Bitcoins are stored internally as 64 bit integers. Because PHP's JSON implementation does not provide a way to use custom types for decimal numbers, we must use an alternative branch of Bitcoin which returns all decimal amounts as strings.

# install needed packages
$ sudo apt-get install build-essential libboost-all-dev libdb4.7++-dev libssl-dev libglib2.0-dev
$ git clone git://github.com/genjix/bitcoin.git
$ cd bitcoin/
$ make -f makefile.unix bitcoind
$ ./bitcoind
# wait a few seconds for it to start up
$ ./bitcoind getinfo

Bitcoin is now initialising and you must wait until "blocks" is at the current count.