Bitcoin Forum
May 26, 2024, 11:25:08 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: [PHP] Blockchain API  (Read 1696 times)
WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 25, 2015, 11: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.

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
August 26, 2015, 12:24:01 AM
 #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"]."<br>".$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

WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 26, 2015, 12:57:14 AM
 #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.

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1179



View Profile WWW
August 26, 2015, 03:17:02 AM
 #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.

WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 26, 2015, 03:45:54 AM
 #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!

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10589



View Profile
August 26, 2015, 12:30:11 PM
 #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

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
WingTsun (OP)
Member
**
Offline Offline

Activity: 120
Merit: 10

❖ Bitcoin Enthusiast / Developer ❖


View Profile
August 26, 2015, 11: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.

❖ Professional Bitcoin Developer ❖ Ignore the negative feedback ❖
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!