/* Our account's credentials for Bitcoin Testnet */ $apiKey = 'YOUR API KEY'; $pin = 'notNeeded'; $version = 2; // the API version $block_io = new BlockIo($apiKey, $pin, $version); $toAddress = $_GET['to_address']; $paymentExpected = strval($_GET['amount']); $confidenceThreshold = floatval($_GET['min_confidence']); print "Monitoring Address for Payments: " . $toAddress . "\n"; print "Amount Expected: " . $paymentExpected . "\n"; /* Look for a new incoming transaction, and let us know when done. Assumption: The $toAddress is new, and does not have previously received transactions */ while (true) { // Keep checking for a new transaction, end when there is at least one transaction and its confidence has reached 0.90. $txs = $block_io->get_transactions(array('addresses' => $toAddress, 'type' => 'received')); $paymentReceived = "0.0"; // using strings for high precision monetary stuff // print_r($txs); $txs = $txs->data->txs; // iterate over all transactions, check their confidence foreach ($txs as $tx) { foreach ($tx->amounts_received as $amountReceived) { if ($amountReceived->recipient == $toAddress) { print "Amount: " . $amountReceived->amount . " Confidence: " . $tx->confidence . "\n"; if ($tx->confidence > $confidenceThreshold) { $paymentReceived = bcadd($amountReceived->amount, $paymentReceived, 8); } } } }
/** * List all transactions for an specific email * * @author salvipascual * @param String, $publickey * @return Array of Objects [datetime, senderkey, amount, type] * */ private function listTransactions($publickey) { $block_io = new BlockIo($this->apiKey, $this->pin, 2); $transactions = array(); // get all received $received = $block_io->get_transactions(array('type' => 'received', 'addresses' => $publickey)); foreach ($received->data->txs as $data) { $res = new stdClass(); $res->time = $data->time; $res->sender = $data->senders[0]; $res->amount = $data->amounts_received[0]->amount; $res->type = "received"; $transactions[] = $res; } // get all sent $sent = $block_io->get_transactions(array('type' => 'sent', 'addresses' => $publickey)); foreach ($sent->data->txs as $data) { $res = new stdClass(); $res->time = $data->time; $res->sender = $data->senders[0]; $res->amount = $data->amounts_sent[0]->amount; $res->type = "sent"; $transactions[] = $res; } return $transactions; }