API documentation for developers PHP


Add our file to your project

Download the file for PHP by clicking this link


add the file to your PHP code, see this in the example below.


<?php

include "Puce_io.php";


?>


Instance the class so it can be used, at this point you will need to inform your ApiKey, it can be found at Your Settings Remember, you are logged in to your account to do so, if you do not have an account yet, you need to register.


<?php

$Puce 
= new Puce("Your ApiKey Here");

?>


Once this is done, if you have informed a valid ApiKey, the class is already ready to be used, otherwise your system will give an error in the next steps.


How about we check your balance?

You can check your balance in all currencies simply and easily, see the example below:


<?php

    $balances 
$Puce->Balance();

?>


If the query is successful it will return an array of objects similar to this:


stdClass Object
	(
		[status] => success
		[balances] => stdClass Object
		(
			[btc] => 0.87500000
			[bch] => 0.00000000
			[ltc] => 0.00000000
		)
	)
						


You can access each information by following the example below:


<?php

 
//to print the status
echo $balances->status;

//to print the balance in some currency, in this example we use btc, but this is at your discretion
echo $balances->balances->btc;

?>


You can also access the balance data in each currency individually, just follow the example below:


<?php

//change the currency symbol to the currency you want
$balance $Puce->Balance("btc");

?>


If the query is successful it will return an array of objects similar to this:


stdClass Object
	(
		[status] => success
		[coin] => btc
		[balance] => 0.87500000
		[updated] => 2017-11-15 20:04:33
	)
						


You can access each information by following the example below:


<?php

//to print the status
echo $balance->status;

//to print the currency code
echo $balance->coin;

//to print the balance
echo $balance->balance;

//to print the update date of your balance
echo $balance->updated;

?>


How about we consult our main address of each altcoin?

You can consult your main deposit address, this does not change, it will always be the same, see the example below.


<?php

//You need to enter the currency to which you want to get the address, in which case we will use btc as an example.
$address $Puce->getMyAddress("btc");

?>


If your query succeeds, an array of objects similar to this will be returned:


stdClass Object
(
    [status] => success
    [coin] => btc
    [address] => 14g72MNBCtNJMJHxsXepfp5CJroKRPq4Pa
)
						


You can access each information from the following using the example below


<?php

//to print the status
echo $address->status;

//to print the currency code
echo $address->coin;

//o print the address
echo $address->address;
?>


In some currencies, you will have the pubkey information or payment_id you can access them as follows.


<?php

//to print the pubkey
echo $address->pubkey;

//to print the payment_id
echo $address->payment_id;

?>


How to generate a new address for an altcoin?

You can generate a new address for each altcoin whenever you want, with each request made, a new address is generated, see the example below.


<?php

//You need to enter the currency to which you want to get the address, in which case we will use btc as an example.
$NewAddress $Puce->getAddress("btc");

?>


If your request succeeds, an array of objects similar to this will be returned:


stdClass Object
(
    [status] => success
    [coin] => btc
    [address] => 368chY6JcrSARvqSszd7Vi5Szjw8QM7ZaE
)
						


You can access each information from the following using the example below


<?php

//to print the status
echo $NewAddress->status;

//to print the currency code
echo $NewAddress->coin;

//o print the address
echo $NewAddress->address;
?>


In some currencies, you will have the information of pubkey or payment_id you can access them as follows.


<?php

//to print the pubkey
echo $NewAddress->pubkey;

//to print the payment_id
echo $NewAddress->payment_id;

?>

Receiving feedback for auto notifications in your app

You can also receive notifications from each address when there is a change in your account balance, you just need to enter the URL you want to use to receive the notices, see the example below.


<?php
//inform us here the url of the file of your site that will receive and will handle the return of the notifications
$url "yoursite.com/return.php";

//generating an address with return notifications
$NewAddress $Puce->getAddress("btc"$url);

?>


If your request succeeds, an array of objects similar to this will be returned:


stdClass Object
(
    [status] => success
    [coin] => btc
    [address] => 368chY6JcrSARvqSszd7Vi5Szjw8QM7ZaE
)
						


You can access each information from the following using the example below as informed in the example above.


<?php

//to print the status
echo $NewAddress->status;

//to print the currency code
echo $NewAddress->coin;

//o print the address
echo $NewAddress->address;
?>


In some currencies, you will have the pubkey information or payment_id you can access them as follows.


<?php

//to print the pubkey
echo $NewAddress->pubkey;

//to print the payment_id
echo $NewAddress->payment_id;

?>


Once we've identified a balance change at the address you've generated, we'll send you multiple POST fields


To receive our notification you need to create a file called return.php the file name can be any other as long as it has been informed in the creation of the address.


You can receive the POST fields as shown below


<?php

//we are inside our return.php file


//First, lets check if there is any POST field and if it is different from empty, we avoid errors in our application.
if (!empty($_POST)) {

    
$status $_POST["status"]; //type string

    //We need to make sure our notification was a success, for that, we do that.
    
if ($status === "success") {

        
$coin $_POST["coin"]; //type string

        
$address $_POST["address"]; //type string

        
$tx_id $_POST["tx_id"]; //type string

        
$amount $_POST["amount"]; //type float

        /*Here you do all the treatment you find necessary using the data received,
        you are free to do whatever you want, from querys to db or whatever your imagination allows,
        we created this example just to show you how easy it is to create a return notification using Puce.io for PHP
        */
    
}
}

?>


Making the sending and withdrawal of your funds

You can send funds to propro Puce.io users through the registration email, this modality has no fees, see the example below.


<?php

//we first inform you the currency code to be sent
$coin "btc"//string

//then we need to enter the amount to be sent
$amount 0.001//float

/*then we need to enter the address where the currency will be sent, in which case we will send it to another Puce.io user
you can also enter the currency address, this mode has a fee calculated by the network*/
$address "test@yourmail.com";// use a Puce.io email address or a currency address

//Now we need to create the withdrawal, do as the example below, this order must be followed or you will not succeed.

//in this example we do not use payment_id because it is optional

$withdrawal $Puce->Withdrawal($coin$amount$address);


/*
you can also enter a url that will be used to receive the tx id of this withdrawal transaction, 
we can not inform you the id immediately because first the request will be reviewed and then processed, after confirmed by the network,
we will send a notification to the url informing id and tx_id via POST.
*/

//first, we need to enter the complete url to the file of your application that will receive the POST fields
$url "http://yoursite.com/file_return";

//request example with id return and tx_id without payment_id
$withdrawal $Puce->Withdrawal($coin$amount$addressnull$url);

//if the currency you need to withdraw needs a payment_id just create it
$payment_id "ef4b6a5cb7026ea3000000000000000000000000000000000000000000000000";

//the withdrawal request should be made as in the example below, realize that we add an additional parameter, simple right?
$withdrawal $Puce->Withdrawal($coin$amount$address$payment_id);


//request example with id return and tx_id with payment_id
$withdrawal $Puce->Withdrawal($coin$amount$address$payment_id$url);

?>


If your withdrawal request is successful, an array of objects similar to this will be returned:


Using Puce.io email address

stdClass Object
(
    [status] => success
    [message] => Your transfer was successful.
    [coin] => btc
    [amount] => 0.001
    [address] => test@yourmail.com
)

Using currency address
stdClass Object
(
    [status] => success
    [message] => Your transfer was successful.
    [coin] => doge
    [amount] => 10
    [address] => DU3GWKUMGahD12q5qNeNzQEEPvwwBmLZxv
    [id] => 12345
)						

Using currency address with payment_id
stdClass Object
(
    [status] => success
    [message] => Your transfer was successful.
    [coin] => xrp
    [amount] => 10
    [address] => rCoinaUERUrXb1aA7dJu8qRcmvPNiKS3d
    [payment_id] => 1241307740
    [id] => 123456
)						


You can access each information regarding the service according to the examples below

<?php

//printing the status
echo $withdrawal->status;

//printing the message
echo $withdrawal->message;

//printing the coin
echo $withdrawal->coin;

//printing the amount
echo $withdrawal->amount;

//printing the destination address
echo $withdrawal->address;

//printing payment_id
echo $withdrawal->payment_id;

//by printing the unique id, this id will be used to get the tx id of this withdrawal
echo $withdrawal->id;


/*To get the id and tx_id of the loot, just follow this example.*/

if (!empty($_POST)) {

    
$status $_POST["status"]; //type string

    //We need to make sure our notification was a success, for that, we do that.
    
if ($status === "success") {

        
$id $_POST["id"]; //type int

        
$tx_id $_POST["tx_id"]; //type string

        /*Here you do all the treatment you find necessary using the data received,
        you are free to do whatever you want, from querys to db or whatever your imagination allows,
        we created this example just to show you how easy it is to create a return notification using Puce.io for PHP
        ---------------------------------------------------------------------------------------------------------------------------
         Query example "UPDATE table SET tx_id = $tx_id WHERE id_puce = $id"
        */
    
}
}


?>


Taking the transactions from a certain wallet address

You can get all the detailed information of an address by simply following the steps below.


<?php

//To check the transactions for an address, you only need to enter the Puce.io wallet or email address as follows.
$transactions $Puce->getTransactions("DCZJ5HbjU8q8A2KneCtm5p5kXnHQNwpKjQ");

?>


If your request succeeds, an array of objects similar to this will be returned:


stdClass Object
(
    [status] => success
    [transactions] => Array
        (
            [0] => stdClass Object
                (
                    [withdrawal] => stdClass Object
                        (
                            [status] => success
                            [coin] => doge
                            [address] => DCZJ5HbjU8q8A2KneCtm5p5kXnHQNwpKjQ
                            [amount] => 15.00000000
                            [fee] => 1.00000000
                            [tx_id] => 7817563282c97b9e102b4ae633f0f41eda10b6a73232be4fff134d03ab18f010
                            [date] => 2017-12-28 04:36:03
                        )

                )

            [1] => stdClass Object
                (
                    [withdrawal] => stdClass Object
                        (
                            [status] => success
                            [coin] => doge
                            [address] => DCZJ5HbjU8q8A2KneCtm5p5kXnHQNwpKjQ
                            [amount] => 32.00000000
                            [fee] => 1.00000000
                            [tx_id] => 91beda9e04065a8c1fe36a0f790d13f7d4a04e86d1cb848cd9a4247829aa206c
                            [date] => 2017-12-28 04:33:31
                        )

                )

            [2] => stdClass Object
                (
                    [withdrawal] => stdClass Object
                        (
                            [status] => success
                            [coin] => doge
                            [address] => DCZJ5HbjU8q8A2KneCtm5p5kXnHQNwpKjQ
                            [amount] => 32.00000000
                            [fee] => 1.00000000
                            [tx_id] => 4a6312f6da6b261d95db46aada8b2d056307300ff7e92149b472bc7bacfc1850
                            [date] => 2017-12-28 04:33:31
                        )

                )
						


The records are returned in decreasing order, You can access each information from the following using the example below.


If you need more performance or some other reason, you can limit the maximum number of records to be displayed, just pass a second parameter in your query, thus:


<?php

//in this case, it will return only 2 records, but you can enter as many as you like, with a minimum of 1.
$transactions $Puce->getTransactions("DCZJ5HbjU8q8A2KneCtm5p5kXnHQNwpKjQ"2);



//to print the status
echo $transactions[0]->status;

//to print the currency code
echo $transactions[0]->coin;

//o print the address
echo $transactions[0]->address;
?>


In some currencies, you will have the information of pubkey or payment_id you can access them as follows.


<?php

//to print the pubkey
echo $transactions[0]->pubkey;

//to print the payment_id
echo $transactions[0]->payment_id;


//to print the amount
echo $transactions[0]->amount;

//to print the fee
echo $transactions[0]->fee;

//to print the tx_id
echo $transactions[0]->tx_id;


//to print the date
echo $transactions[0]->date;
?>

tting information about currencies

You can get detailed information such as name, fees, and date of last update of the rates of a particular currency or all of them at the same time.


<?php
//To see information for all currencies, use the example below.
$altcoins $Puce->getAltcoins();

?>


If your query succeeds, you should receive an array of objects similar to this.

	Array
	(
	    [status] => success
	    [btc] => Array
	        (
	            [name] => Bitcoin
	            [updated] => 2017-12-17 05:35:39
	            [fees] => Array
	                (
	                    [deposit] => 0.850
	                    [withdrawal] => 0.00100000
	                )

	        )

	    [bch] => Array
	        (
	            [name] => Bitcoin Cash
	            [updated] => 2017-12-12 11:36:00
	            [fees] => Array
	                (
	                    [deposit] => 0.850
	                    [withdrawal] => 0.00000000
	                )

	        )
	)



<?php
//You can access the information in a simple way, in this case we will access the btc currency

//printing the name of the coin
echo $altcoins->btc->name

//printing the currency rate update date
echo $altcoins->btc->updated;

//printing the deposit rate (note that this rate is in percentage)
echo $altcoins->btc->fees->deposit;

//printing the withdrawal rate (note that this rate is fixed)
echo $altcoins->btc->fees->withdrawal;





//You can also view the information for each currency individually
//this mode is much faster to run, follow the example below.

$altcoin $Puce->getAltcoins("btc");
//How simple is it? we just passed the currency code as a parameter, you can use any code
?>


If your query succeeds, you should receive an array of objects similar to this.

	Array
	(
	    [status] => success
	    [coin] => btc
	    [name] => Bitcoin
	    [updated] => 2017-12-17 05:35:39
	    [fees] => Array
	        (
	            [deposit] => 0.850
	            [withdrawal] => 0.00100000
	        )

	)




<?php
//You can access the information in a simple way, see the example below

//printing the currency code
echo $altcoin->coin;

//printing the name of the coin
echo $altcoin->name

//printing the currency rate update date
echo $altcoin->updated;

//printing the deposit rate (note that this rate is in percentage)
echo $altcoin->fees->deposit;

//printing the withdrawal rate (note that this rate is fixed)
echo $altcoin->fees->withdrawal;


?>