PHP code example of bitcont / bitcoin

1. Go to this page and download the library: Download bitcont/bitcoin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bitcont / bitcoin example snippets


// choose your parser
$bitcoin = new Bitcont\Bitcoin\Clients\BlockchainInfo\Client; // blockchain.info parser
$bitcoin = new Bitcont\Bitcoin\Clients\BitcoindInfo\Client('bitcoind username', 'bitcoind password'); // blockchain.info + bitcoind parser

// get bitcoin address
$address = $bitcoin->getAddress('1Kug5MazR3c8VsBn61JZdvzdix49K7CCES'); // returns IAddress
$address->getId(); // returns '1Kug5MazR3c8VsBn61JZdvzdix49K7CCES'

// get bitcoin transaction
$transaction = $bitcoin->getTransaction('b26369a892dcc3408afcf96af42d0313e1e3c4eed8124ba57506483b6fa3ffc6'); // returns ITransaction
$transaction->getId(); // returns 'b26369a892dcc3408afcf96af42d0313e1e3c4eed8124ba57506483b6fa3ffc6'

// get transaction inputs
$inputs = $transaction->getInputs(); // returns array of IInput

// get the first input's info
$value = $inputs[0]->getValue(); // returns the number of satoshis (integer)
$sender = $inputs[0]->getAddress(); // returns the sender address

// get transaction outputs
$outputs = $transaction->getOutputs(); // returns array of IOutput

// get the last output's value
$value = end($outputs)->getValue(); // returns the number of satoshis (integer)
$recipient = end($outputs)->getAddress(); // returns the recipient address

// get all transactions for an address
$transactions = $bitcoin->getTransactions($address); // returns array of ITransaction (oldest first)