Bitcoin api not dependant on a running bitcoin daemon?
I'm trying to get a bitcoin-centric website going, and I need to be able to perform the following actions wi开发者_StackOverflow中文版thout having a bitcoin daemon running on any server due to limitations in place by my host:
- Create a new bitcoin address (
getnewaddress($account)
) - Receive coins at that address; determine how much was received (
getreceivedbyaccount($account, $minconf=1)
) - Send coins to an address (
sendfrom($fromaccount, $tobitcoinaddress, $amount, $minconf=1, $comment="", $comment-to="")
)
These are all functions that exist within the existing json-rpc php client, but all of which depend on a running bitcoin daemon on a server.
I did read through the "lazy api" stuff as well, but I would rather not depend on another service to get the block data or send the bitcoins.
tl;dr: I need a version of the bitcoin php api which does not need the daemon running, with at a bare minimum the functions described above.
At present, no such function exists. I've heard talk of bitcoind being ported to native PHP or a Java applet that can run in the browser, but there is no bitcoin without a daemon somewhere - although you could probably manage those basic functions with the MtGox Merchant API.
Alternately, if you have a reliable enough setup at home you could dedicate a rig to bitcoind and forward the appropriate port in your router settings. The only reason you can't usually host sites on your residential internet is that ISPs block port 80; they don't block 8337 (and if they do it's configurable anyway). The PHP API should be capable of connecting to bitcoind just the same across the 'net as if it's on the same box.
Blockchain.info provides a Bitcoind JSON rpc compatible api.
http://blockchain.info/api/json_rpc_api
TL;DR;: not running some sort of Bitcoin client and not trusting a third party will not be possible.
While it is possible to trust a third party to tell you the balance of an account you would have to trust the third party to handle the private keys needed to sign transactions as soon as you use either getnewaddress
or sendfrom
, which is probably not what you want to do.
As far as I see it a possible minimal solution would be to use a third party, such as http://blockchain.info, to keep track of the balances (read the spendable outputs
you can claim when sending a transaction), and use a notification service to tell you about incoming transactions (some are listed as alternatives here https://en.bitcoin.it/wiki/BitcoinNotify).
Now to be able to receive transactions all you need is to create a new address to show the users on your website. It should not be difficult to create such an address in PHP, just take a look at the wiki.
Now for the sending part, that's going to be quite a lot more difficult, as it involves:
- gathering outputs;
- claiming them by providing matching signatures;
- creating new outputs to the desired addresses;
- combining everything in a transaction and serializing it to the P2P protocol specifications;
- connecting to the P2P network and sending the transaction to the peers.
So as you can see it gets complicated quickly as you try to send out transactions. If sending transactions is not absolutely required I'd suggest to just provide the server with a list of addresses to which it can receive transactions BitAddress allows you to create private key / address pairs just for this purpose.
If you want to only generate bitcoin address and private key, give a try to:
https://github.com/zamgo/PHPCoinAddress
And maybe we can build a script only to find 20 bitcoin peer nodes to broadcast our transaction.
from bitseed.xf2.org or hard coded peer list in chainparams.cpp source code: https://en.bitcoin.it/wiki/Satoshi_Client_Node_Discovery
At best you will need an API from a service provider that allows wallet creation and transaction queries.
As you're looking for: create, send, receive - this means that you will need a service that is hosting this already:
Coinkite may be a good option as the majority of bitcoin operations can be done with the API:
Send and request bitcoin by email, sms or bitcoin address
Generate public keys (HD)
Check balances and receive notifications
Safely store bitcoin in the HSM or Multi-signature accounts
Create vouchers and paper wallets (with private key published)
Create P2SH payment addresses, withdraw via M-of-N multisig.
Import and sweep private keys
https://coinkite.com/faq/developers
You can use Open Source GoUrl.io Bitcoin-PHP Payment library -
https://github.com/cryptoapi/Payment-Gateway
<?
require_once( "cryptobox.class.php" );
$options = array(
"private_key" => "", // private key from gourl.io
"orderID" => "your_product1_or_signuppage1_etc",
"amountUSD" => 2 // 2 USD
);
// Initialise Payment Class
$box1 = new Cryptobox ($options);
// Display Payment Box or successful payment result
$paymentbox = $box1->display_cryptobox();
// A. Process Received Payment
if ($box1->is_paid())
{
// Your code here to handle a successful cryptocoin payment
// ...
}
else $message .= "The payment has not been made yet";
?>
<!DOCTYPE html>
<html><head></head>
<body>
<?= $paymentbox ?>
<?= $message ?>
</body>
</html>
精彩评论