- PHP 5.4+
- Composer
- ext-gmp
- ext-mcrypt
- [secp256k1-php] - Install the secp256k1 PHP extension. Blazing speeds, but bleeding edge, beware.
##Installation
You can install this library via Composer:
composer require afk11/bitcoin
or
"require": "afk11\bitcoin"
}```
##Presently supported:
- Blocks, block headers, basic mining, difficulty calculations
- P2SH, Multisignature scripts.
- ECDSA key creation, public & private key types.
- Transactions
- Signature creation & verification
- Deterministic signatures (RFC6979)
- BIP32 deterministic algorithms
- Script builder, parser
- RPC bindings to Bitcoin Core's RPC, getting OOP responses :)
- Easy serialization to binary representation of most classes
- SIGHASH types when creating transactions (not tested)
- Payment Protocol (BIP70)
##Todo:
- TransactionBuilder
- Full script interpreter
- SPV
- P2P
## Implemented BIPs
- BIP0016
- BIP0032
- BIP0070
# Examples
## Generate private keys
// Create private keys use Afk11\Bitcoin\Key\PrivateKeyFactory;
$network = Bitcoin::GetNetwork(); $private = PrivateKeyFactory:create(true); $public = $private->getPublicKey(); echo $private->getBuffer() . "\n"; echo $public->getBuffer() . "\n"; echo $public->getAddress($network) . "\n";
## Explore the blockchain using OOP bindings to the RPC
use Afk11\Bitcoin\Rpc\RpcFactory;
$bitcoind = RpcFactory::bitcoind('127.0.0.1', 18332, 'bitcoinrpc', 'BBpsLqmCCx7Vp8sRd5ygDxFkHZBgWLTTi55QwWgN6Ng6');
$hash = $bitcoind->getbestblockhash(); $block = $bitcoind->getblock($hash); $tx = $bitcoind->getTransactions()->getTransaction(10); echo $tx->getTransactionId();
## Create signed payment requests
use BitWasp\Bitcoin\Address\AddressFactory; use BitWasp\Bitcoin\PaymentProtocol\PaymentRequestBuilder; use BitWasp\Bitcoin\PaymentProtocol\PaymentRequestSigner; use BitWasp\Bitcoin\Script\ScriptFactory; use BitWasp\Bitcoin\Transaction\TransactionOutput;
$time = time(); $amount = 10000; $destination = '18Ffckz8jsjU7YbhP9P44JMd33Hdkkojtc'; $paymentUrl = 'http://192.168.0.223:81/bitcoin-php/examples/bip70.fetch.php?time=' . $time;
// Create a signer for x509+sha256 - this requires a readable private key and certificate chain. // $signer = new PaymentRequestSigner('none'); $signer = new PaymentRequestSigner('x509+sha256', '/var/www/git/paymentrequestold/.keys/ssl.key', '/var/www/git/paymentrequestold/.keys/ssl.pem'); $builder = new PaymentRequestBuilder($signer, 'main', time());
// PaymentRequests contain outputs that the wallet will fulfill $address = AddressFactory::fromString($destination); $builder->addAddressPayment($address, $amount);
// Create the request, send it + headers $request = $builder->send();