Author

Topic: [PHP] Blockchain API (Read 1697 times)

member
Activity: 120
Merit: 10
❖ Bitcoin Enthusiast / Developer ❖
August 26, 2015, 07:07:34 PM
#7
I just stumbled across a new problem, now with the "CALLBACK" part. Everything is working fine, except I can not find how can I grab the SENDERS Wallet.

I have red the BlockChain API, and it shows only how to grab receivers wallet (Your Own, which received the transaction). Here are the parameters they provide:

    value - The value of the payment received in satoshi (not including fees). Divide by 100000000 to get the value in BTC.
    transaction_hash - The transaction hash.
    input_address - The bitcoin address that received the transaction.
    confirmations - The number of confirmations of this transaction.
    {Custom Parameters} - Any parameters included in the callback URL will be past back to the callback URL in the notification.

That does not make any sense for me, why there is no example how to grab the senders wallet, since my script needs to save the senders wallet for further use.
legendary
Activity: 3472
Merit: 10611
August 26, 2015, 08:30:11 AM
#6
Thank you, coinableS. I will implement this.. Smiley I have a question tho, the amount needs to be in Satoshi right? Cuz in the script I use Bitcoin values, which gets entered into the DB from incoming payments.
About the topic, I actually tried to delete it, and re-post in the right section, but it said I do not have such permission.

A word of advice, don't use floats (bitcoin values). They can cause errors in calculations with php due to its type juggling. Store your db values in satoshi and then convert them client side for users to view.

why not use decimal?
The main difference is Floats and Doubles are binary floating point types and a Decimal will store the value as a floating decimal point type. So Decimals have much higher precision and are usually used within monetary (financial) applications that require a high degree of accuracy.
using decimal might be a tiny bit slower though, but it has the accuracy you are looking for.

p.s. this if for .Net not sure what it is called in PHP :S
member
Activity: 120
Merit: 10
❖ Bitcoin Enthusiast / Developer ❖
August 25, 2015, 11:45:54 PM
#5
Thank you, coinableS. I will implement this.. Smiley I have a question tho, the amount needs to be in Satoshi right? Cuz in the script I use Bitcoin values, which gets entered into the DB from incoming payments.
About the topic, I actually tried to delete it, and re-post in the right section, but it said I do not have such permission.

A word of advice, don't use floats (bitcoin values). They can cause errors in calculations with php due to its type juggling. Store your db values in satoshi and then convert them client side for users to view.

Thank you again, I actually had a strange problem with bitcoin values in my DB on a previous project, sometimes they just appeared messed up. I am pretty sure this is the cause. Thanks!
legendary
Activity: 1442
Merit: 1179
August 25, 2015, 11:17:02 PM
#4
Thank you, coinableS. I will implement this.. Smiley I have a question tho, the amount needs to be in Satoshi right? Cuz in the script I use Bitcoin values, which gets entered into the DB from incoming payments.
About the topic, I actually tried to delete it, and re-post in the right section, but it said I do not have such permission.

A word of advice, don't use floats (bitcoin values). They can cause errors in calculations with php due to its type juggling. Store your db values in satoshi and then convert them client side for users to view.
member
Activity: 120
Merit: 10
❖ Bitcoin Enthusiast / Developer ❖
August 25, 2015, 08:57:14 PM
#3
Thank you, coinableS. I will implement this.. Smiley I have a question tho, the amount needs to be in Satoshi right? Cuz in the script I use Bitcoin values, which gets entered into the DB from incoming payments.
About the topic, I actually tried to delete it, and re-post in the right section, but it said I do not have such permission.
legendary
Activity: 1442
Merit: 1179
August 25, 2015, 08:24:01 PM
#2
Hello,
  Welcome to Bitcointalk! This post would be better suited for the Service Discussion board (https://bitcointalk.org/index.php?board=85.0), a mod will likely move it for you.

As for blockchain.info's API it is very easy to send a payment using their Wallet API.

Here's a snippet of code that I wrote, feel free to use it.
I included some error catching as well based on the JSON response you get from the API request to BC.info

Code:
          if(isset($_POST['paymentBtn'])){
if(!isset($_POST['userInput']) || trim($_POST['userInput']) ==''){
echo "You must include your bitcoin address";
} else {
$address = $_POST['userInput'];
$address = mysqli_real_escape_string($con, $address); //YOU DONT HAVE TO DO THIS BUT I ALSO PUT THIS INFO INTO A DB
$amount = $balance; //THIS IS THE AMOUNT YOU WANT TO SEND IM JUST USING A VARIABLE
$ID = "a1a1a1-1a1a1-a11a11a1a1-a1a1";   //YOUR BLOCKCHAIN.INFO USER ID
$PW = "abcdefghijk";      //YOUR BLOCKCHAIN.INFO PASSWORD
$sendPayment = json_decode(file_get_contents("https://blockchain.info/merchant/$ID/payment?password=$PW&to=$address&amount=$amount"), true);
if(isset($sendPayment["error"])){
echo "Error: ".$sendPayment["error"];
} else if(isset($sendPayment["tx_hash"])){
echo "tx: ".$sendPayment["tx_hash"]."
".$sendPayment["message"];
} else {
echo "Sorry, Blockchain.info appears to be down. Please try again later.";
}


}
  }

I've created some video tutorials on youtube on how to do this that might help. Blockchain.info has given them their blessings through their blog and twitter.
https://twitter.com/blockchain/status/636197788158676992
http://blog.blockchain.com/2015/07/30/building-bitcoin-websites-using-the-blockchain-api-video-tutorial/
https://www.youtube.com/watch?v=dQbah3IYMOs
member
Activity: 120
Merit: 10
❖ Bitcoin Enthusiast / Developer ❖
August 25, 2015, 07:49:01 PM
#1
Hello guys!

I am working on a Bitcoin Project, which includes automated outgoing payments. The script it-self is ready, I'm only missing the actual Bitcoin sending function. I was checking out the official Blockchain API, but I found the PHP examples there pretty plain and not secure to use like that. I mean, it uses simple $_GET request for the transaction.

So, I am now wondering, if someone could please suggest me any good Blockchain PHP Library to use for this purpose?

Thank you, WingTsun.
Jump to: