Bitcoin Forum

Bitcoin => Project Development => Topic started by: schalk on May 22, 2011, 01:56:01 AM



Title: Bitcoin PHP [OPEN SOURCE]
Post by: schalk on May 22, 2011, 01:56:01 AM
Bitcoin Class (JSON-RPC Communication)
Integrating Bitcoin into your website can be hard at first and rather frustrating, this class was designed to make it easier and to ease confusion. This script simply connect to a Bitcoin Server and then send a command to get the balance of your account. As the title says it is opensource. I paid for a VPS yesterday which is currently being setup, once it is setup I will record a video demonstrating how to integrate Bitcoin into your website (because I love you guys ;).

Link:
https://github.com/schalk-b/Simple-Bitcoin-PHP (https://github.com/schalk-b/Simple-Bitcoin-PHP)

API/Methods:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list)

How to run server:
https://en.bitcoin.it/wiki/Running_Bitcoin (https://en.bitcoin.it/wiki/Running_Bitcoin)

Example:
Code:
include_once("Bitcoin.php");

$rpcUser = "username";
$rpcPass = "password";
$url = "http://localhost:8332";

// create bitcoin object
$bitcoin = new Bitcoin($url, $rpcUser, $rpcPass);

/**
 * Refer to https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
 * for a list of methods
 */
$balance = $bitcoin->getBalance();
echo("<p>Balance: $balance");

Donations
14bBEcMwwnDVXAYR8n2iTk9PTF5wqYLGR2



Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: bitfreak! on May 22, 2011, 07:04:32 AM
So I still need to install Bitcoin on the web server?

Is there a public server I can use or something?

I am very new at this whole Bitcoin thing, but I love it too!


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: schalk on May 22, 2011, 07:58:31 AM
Yeah bitcoins are so fascinating, take quite a bit to fully understand though.

From what I understand you can write a php script that connect to MtGox's API - https://mtgox.com/support/tradeAPI
This however does require you to have a mtgox account with "cash" on it.


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: carlerha on May 22, 2011, 03:10:08 PM
I don't see exactly what kind of work you did here, you copied the JSON-RPC-PHP (http://JSON-RPC-PHP) class and changed the name of it? I'm sorry if I'm missing something.


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: matt.collier on May 22, 2011, 03:42:11 PM
This is excellent!

I have written a class that includes methods that interface with blockexplorer.com (http://blockexplorer.com/q).

Would these methods be welcome additions to this class?


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: schalk on May 22, 2011, 07:49:05 PM
Actually I didn't use the JSON-RPC-PHP class at all. I recreated this from scratch, since it is using the same kind of communication it will ofcourse have some similarities. One of the main differences are that this uses cURL instead of fopen and just has a nicer way of handling errors. Also, I know it's not much, but this one is case sensitive, I personally find getBalance() better practice then getbalance(). If you don't prefer this version, by all means do use the JSON-RPC-PHP verison.

@Matt: :) thanks mate. This class has MIT license so anyone can do with it what they want, if I have time I will see if I can develop a open source system like blockexplorer.com using this as a base class. I'm pretty busy at the moment though, still attending school.


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: matt.collier on May 22, 2011, 08:23:41 PM
Let me ask my question another way?

Are you looking for contributors to the project?  And if so, are methods that communicate with the blockexplorer.com API in keeping with the direction you would like to see this project take?

I could see incorporating methods that ease interfacing with any number of bitcoin related APIs (e.g. MTGOX, ClearCoin, BitcoinID)


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: carlerha on May 23, 2011, 08:18:42 AM
Actually I didn't use the JSON-RPC-PHP class at all. I recreated this from scratch, since it is using the same kind of communication it will ofcourse have some similarities. One of the main differences are that this uses cURL instead of fopen and just has a nicer way of handling errors. Also, I know it's not much, but this one is case sensitive, I personally find getBalance() better practice then getbalance(). If you don't prefer this version, by all means do use the JSON-RPC-PHP verison.
I had no intention of mocking you or saying that your php class was not good, it was just me thinking "why re-invent the wheel" etc. But hey, the incentive is great, and perhaps you'll even develop your script to a stage where it's really awesome! :)


Title: Re: Bitcoin PHP [OPEN SOURCE]
Post by: zellfaze on May 25, 2011, 08:48:13 PM
I think the idea of using cURL instead of fopen() is a good idea if it means anything.