Bitcoin.com Mining Pool API v2 - Get PPLNS Payouts or PPS Payouts Using Pure PHP

May 8, 2020 @ 8:25 pm - Mississippi and Louisiana, USA | May 8, 2020 @ 10:25 pm - Greater Antilles, CAR 
May 9, 2020 @ 3:25 am - Rome, ITA | May 9, 2020 @ 4:25 am - Athens, GRC | May 9, 2020 @ 11:25 am - Tokyo, JPN 

by Luke Nandibear  
 
luke-nandibear-bitcoin-com-mining-pool-api-v2-get-pplns-pps-payouts-pure-php

PHP (without cURL) to get only PPLNS Payouts from your Bitcoin.com Mining Pool account

As indicated in the previous article in regard to getting blocks here's another example of using the pool's API (v2).

You can get all transactions (PPLNS, PPS, Withdraws) all together a little easier. Be that as it may, I like checking my PPLNS payouts and don't want to expose any information related to my withdraws (also not particularly interested in seeing blank PPS HashRace transactions).

Will try to share a couple more of these early next week (examples: get pool's BCH hashrate, get your BCH hashrate).

You can either include the following code on the page you want the results to display on or you can save this as a file itself and call it on any page.

<?php

$tomorrowsdate = date('Y-m-d')+86400;

//Today plus 86400 seconds (1 day) to get tomorrow's date.

$settransactions = (array("start" => "2016-09-21", "end" => "$tomorrowsdate", "coin" => "BCH"));
 
//Set the start and end dates (year-month-day) and select coin (BCH or BTC). Use tomorrow's date for end date.

$settransactionsinjson = json_encode($settransactions);

//Why? Because the request must be made in json. Could also use this by itself: $settransactions = json_encode(array("start" => "2016-09-21", "end" => "$tomorrowsdate", "coin" => "BCH"));
                                                                      
$apiurl = "https://console.pool.bitcoin.com/api/v2/user/transactions";

//URL from https://console.pool.bitcoin.com/apidoc/

$apikey = "POOL-BITCOIN-COM-API-KEY:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; 

//Generate API key at https://console.pool.bitcoin.com/settings and replace the x's above with your key.

$apikeyforheader = $apikey;

//Why? It's not necessary but might hide key if dropped in some scenarios.

$context_options = array('http' =>
    array('method'  => "GET",
          'header'  =>  "Content-Type: application/json; charset=UTF-8\n" . "$apikeyforheader",
          'content' => "$settransactionsinjson"
    )
);

/*If you don't want to array use brackets:

$context_options = [
    'http' => [
            'method' => "GET",
            'header' => "Content-Type: application/json; charset=UTF-8\n" . "$apikeyforheader",
            'content' => "$setcoinrequestinjson"
            ]
        ];*/
        
$context  = stream_context_create($context_options);
$together = file_get_contents($apiurl, false, $context);
$info['transactions'] = json_decode($together,true);

$pplns = "Block Reward";
$pps = "PPS Reward";
$manual = "Manual Withdraw";
$auto = "Daily Autowithdrawal";

foreach($info as $itemmaker) {

     if((strpos($pplns, $itemmaker['transactions'][0]['type'])) !== false) {
      echo "Type: " . $itemmaker['transactions'][0]['type']";
        $found = true;

//Why? This example is for getting PPLNS payouts only. Use strpos to compare the value of the 'type' element to the '$pplns' variable we created.  Both need to be 'Block Reward' otherwise the transaction will not be returned.

//You can do the same to get only PPS payouts by using the '$pps' variable and comparing it to the same 'type' element (both need to be 'PPS Reward'). You can use the withdraw variables we created (manual or auto) if you want to display those only.

    echo "Amount: " . $itemmaker['transactions'][0]['totalamount'] . " BCH";
    echo "USD market value of payout (at time of payout): $" . $itemmaker['transactions'][0]['fiat'];
    $timeblockfound = round($itemmaker['transactions'][0]['unixTime']/1000); echo "Date/Time of payout: " . date('M-d-Y H:i:s', $timeblockfound);

//Why? Because the time is in milliseconds. You can divide by 1000 by using the above.

    echo "Block hash (Big Endian): " . "<a href='https://explorer.bitcoin.com/bch/block/" . $itemmaker['transactions'][0]['reference'] . "'>" . $itemmaker['transactions'][0]['reference'] . "</a>";
     }

//Link above is for the block itself. PPLNS payouts (and PPS payouts) are made from the pool to your pool account, not on-chain. Please note that if you're using this code for withdraws the link is for the on-chain transaction sent to your BCH/BTC withdraw address.

//The foregoing will return your most recent PPLNS payout at the Bitcoin.com Mining Pool.  To display more PPLNS payouts copy and paste the code within the foreach construct and change the number [0] in the brackets to number [1] and so on. Continuing below with [1].

if((strpos($pplns, $itemmaker['transactions'][1]['type'])) !== false) {
      echo "Type: " . $itemmaker['transactions'][1]['type'];
        $found = true;
    echo "Amount: " . $itemmaker['transactions'][1]['totalamount'] . " BCH";
    echo "USD market value of payout (at time of payout): $" . $itemmaker['transactions'][1]['fiat'];
    $timeblockfound = round($itemmaker['transactions'][1]['unixTime']/1000); echo "Date/Time of payout: " . date('M-d-Y H:i:s', $timeblockfound);
    echo "Block hash (Big Endian): " . "<a href='https://explorer.bitcoin.com/bch/block/" . $itemmaker['transactions'][1]['reference'] . "'>" . $itemmaker['transactions'][1]['reference'] . "</a>";
     }

if ( ! $found ) {
    echo 'No PPLNS payouts found! Please edit $pplns (Block Reward) to $pps (PPS Reward) to return PPS payouts.';
}}

//Why? If no PPLNS payouts are found in the transactions selected the message above (or any other message you want) will be printed on screen.

?>

Results (ten most recent PPLNS payouts to a pool account) available at nandibear.com/bitcoin-com-mining-pool/get-pplns-payouts-or-pps-payouts/

Article word count: 133

Count including updates (if any): 133

nandibear.com nandi bear luke

Thanks for stopping by and reading!

PLEASE leave some comments! Talk a little!

↓ --- You may also find the Nandi Bear at --- ↓

Bitcoin.com Forum

Hive.blog/@nandibear

BitcoinCashColoredCoins.com