Bitcoin Forum
May 21, 2024, 06:58:32 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I can code PHP, but how do I use JSON for bitcoin transactions?  (Read 1523 times)
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 04, 2013, 10:05:16 PM
 #1

Does anyone have an example PHP script for reading my wallet transactions?
Or for creating new BTC addresses, sending BTC?

I can code in SQL and PHP, HTML, XML.. but I dont get how to use JSON, or anything with BTC.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
elwan
Newbie
*
Offline Offline

Activity: 19
Merit: 0



View Profile
July 04, 2013, 10:18:47 PM
 #2

what kind of wallet you use ?? maybe i can help you  Roll Eyes
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 04, 2013, 11:17:56 PM
 #3

I use Bitcoin-Qt on a Mac.

Help would be very appreciated.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
Brunic
Hero Member
*****
Offline Offline

Activity: 632
Merit: 500



View Profile
July 04, 2013, 11:26:15 PM
 #4

json_decode($yourJSONstring, true)

http://php.net/manual/fr/function.json-decode.php
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 04, 2013, 11:43:28 PM
 #5

json_decode($yourJSONstring, true)

http://php.net/manual/fr/function.json-decode.php

What does that mean?
I do not know how to use JSON.  I don't know what it is.
Your link is in french, I changed it to English, but that is just another bit of helpfulness.
In English, it still does not tell me anything about how to use JSON for a webserver of Bitcoin transactions.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
Brunic
Hero Member
*****
Offline Offline

Activity: 632
Merit: 500



View Profile
July 05, 2013, 01:58:11 AM
 #6

json_decode($yourJSONstring, true)

http://php.net/manual/fr/function.json-decode.php

What does that mean?
I do not know how to use JSON.  I don't know what it is.
Your link is in french, I changed it to English, but that is just another bit of helpfulness.
In English, it still does not tell me anything about how to use JSON for a webserver of Bitcoin transactions.

JSON is simply a string of data. The JSON encoding is just a way to share this data easily.

You can make the test yourself. Create a PHP array, put some data in it. Use something like:
$string = json_encode($array);
var_dump($string);

and you'll see your $array encoded in JSON. To get it back in an array format, you do:
$array = json_decode($string, true);

and you will have your array back.

With JSON, servers can simply broadcast data in a format that any language can read and decode easily.

Sorry for the french link BTW, I sometimes mix up languages.
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 05, 2013, 04:10:17 AM
 #7

json_decode($yourJSONstring, true)

http://php.net/manual/fr/function.json-decode.php

What does that mean?
I do not know how to use JSON.  I don't know what it is.
Your link is in french, I changed it to English, but that is just another bit of helpfulness.
In English, it still does not tell me anything about how to use JSON for a webserver of Bitcoin transactions.

JSON is simply a string of data. The JSON encoding is just a way to share this data easily.

You can make the test yourself. Create a PHP array, put some data in it. Use something like:
$string = json_encode($array);
var_dump($string);

and you'll see your $array encoded in JSON. To get it back in an array format, you do:
$array = json_decode($string, true);

and you will have your array back.

With JSON, servers can simply broadcast data in a format that any language can read and decode easily.

Sorry for the french link BTW, I sometimes mix up languages.


Thanks.
I figured that out reading into it.
Now my problem is, how do I send any data requests to my wallet to get real time data, and make transactions?
curl in php?

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
twobits
Sr. Member
****
Offline Offline

Activity: 574
Merit: 250



View Profile
July 05, 2013, 05:10:09 AM
 #8

json_decode($yourJSONstring, true)

http://php.net/manual/fr/function.json-decode.php

What does that mean?
I do not know how to use JSON.  I don't know what it is.
Your link is in french, I changed it to English, but that is just another bit of helpfulness.
In English, it still does not tell me anything about how to use JSON for a webserver of Bitcoin transactions.

JSON is simply a string of data. The JSON encoding is just a way to share this data easily.

You can make the test yourself. Create a PHP array, put some data in it. Use something like:
$string = json_encode($array);
var_dump($string);

and you'll see your $array encoded in JSON. To get it back in an array format, you do:
$array = json_decode($string, true);

and you will have your array back.

With JSON, servers can simply broadcast data in a format that any language can read and decode easily.

Sorry for the french link BTW, I sometimes mix up languages.


Thanks.
I figured that out reading into it.
Now my problem is, how do I send any data requests to my wallet to get real time data, and make transactions?
curl in php?


Yeah, it is just using http or https as the transport, so curl works just fine for it.

Alternatively, I have https://github.com/mikegogulski/bitcoin-php bookmarked to try if I ever wind up needing to do what you want to do, to save me some time rolling my own.

█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
███
███
███
███
███
███
███
███
███
HyperQuant.net
Platform for Professional Asset Management
███
███
███
███
███
███
███
███
███
WhitePaper
One-Pager
███
███
███
███
███
███
███
███
███
Telegram 
Facebook
Twitter
Medium
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
domob
Legendary
*
Offline Offline

Activity: 1135
Merit: 1166


View Profile WWW
July 05, 2013, 06:00:30 AM
 #9

Now my problem is, how do I send any data requests to my wallet to get real time data, and make transactions?
curl in php?

An alternative if you want to communicate to the local bitcoind on your server is to use the bitcoind executable client via system() or popen().  If you are interested in this solution, I can send you my PHP code I use for that.  Honestly though, I believe HTTP is probably an easier way to communicate with it.

Use your Namecoin identity as OpenID: https://nameid.org/
Donations: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS | GPG 0xA7330737
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 05, 2013, 06:48:39 AM
 #10


Yeah, it is just using http or https as the transport, so curl works just fine for it.

Alternatively, I have https://github.com/mikegogulski/bitcoin-php bookmarked to try if I ever wind up needing to do what you want to do, to save me some time rolling my own.


Do you know where I could find an example of an http transport?  or a curl example?
I don't get how I can transport anything over curl or http when it is on the same server...
that would be talking to itself.
What address? 127.1.1.1? What port? How is Bitcoin even already active listening on that port?

I believe I am lost.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 05, 2013, 06:49:35 AM
 #11

Now my problem is, how do I send any data requests to my wallet to get real time data, and make transactions?
curl in php?

An alternative if you want to communicate to the local bitcoind on your server is to use the bitcoind executable client via system() or popen().  If you are interested in this solution, I can send you my PHP code I use for that.  Honestly though, I believe HTTP is probably an easier way to communicate with it.

Yes I would love to see your PHP code as an example.
I have no idea how bitcoin is suppost to be turned on to listen to incoming requests.  Or where to request them.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
🏰 TradeFortress 🏰
Bitcoin Veteran
VIP
Legendary
*
Offline Offline

Activity: 1316
Merit: 1043

👻


View Profile
July 05, 2013, 09:31:51 AM
 #12

Get jsonrpcclient. Connect to bitcoind RPC. The data is automatically decoded.

Code:
$transactions = $rpc->listtransactions();
var_dump($transactions);

foreach($transactions as $tx){
    echo "TXID: $tx <br />";
}

Alternatively, try Inputs.io's API which is incredibly easy to use. Example callback PHP code is already given to you, you don't need to deal with running your own bitcoind. You can just set a callback URL and get the new transactions pushed to you.

(Btw, WTF is in your linked youtube video? Huh)
twobits
Sr. Member
****
Offline Offline

Activity: 574
Merit: 250



View Profile
July 05, 2013, 11:20:08 AM
 #13

Get jsonrpcclient. Connect to bitcoind RPC. The data is automatically decoded.


I recommend against this for three reasons.

Firstly, unpatched, it can display your login information on errors.
Secondly, it does not work with php 5.4
Thirdly, it is GPLed so anything you make using it has to be GPLed as well.



█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
███
███
███
███
███
███
███
███
███
HyperQuant.net
Platform for Professional Asset Management
███
███
███
███
███
███
███
███
███
WhitePaper
One-Pager
███
███
███
███
███
███
███
███
███
Telegram 
Facebook
Twitter
Medium
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
twobits
Sr. Member
****
Offline Offline

Activity: 574
Merit: 250



View Profile
July 05, 2013, 11:22:58 AM
 #14


Yeah, it is just using http or https as the transport, so curl works just fine for it.

Alternatively, I have https://github.com/mikegogulski/bitcoin-php bookmarked to try if I ever wind up needing to do what you want to do, to save me some time rolling my own.


Do you know where I could find an example of an http transport?  or a curl example?
I don't get how I can transport anything over curl or http when it is on the same server...
that would be talking to itself.
What address? 127.1.1.1? What port? How is Bitcoin even already active listening on that port?

I believe I am lost.

yes,  http://localhost:xxxx or http://127.0.0.1:xxxx,  bitcoin is listening if you run it with -server and/or -daemon.  I dont recall the default port number of hand, but it is in the wiki or source code.   You can also set it in bitcoin.conf with rpcport=1234

█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
███
███
███
███
███
███
███
███
███
HyperQuant.net
Platform for Professional Asset Management
███
███
███
███
███
███
███
███
███
WhitePaper
One-Pager
███
███
███
███
███
███
███
███
███
Telegram 
Facebook
Twitter
Medium
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
███
█████                █████      ███████             
█████                ███    █████████████       
█████                ██  █████████████████   
█████                █  ██████              ██████ 
█████                    ████                      ████ 
█████████████  █████                        ████
█████████████  █████                        ████
█████████████  █████                        ████
█████                    █████                             
█████                █  ██████              ███████
█████                ██  ███████████    █████ 
█████                ███    █████████    ████   
█████                █████      ███████    ██
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 06, 2013, 01:57:00 AM
 #15

Get jsonrpcclient. Connect to bitcoind RPC. The data is automatically decoded.

Code:
$transactions = $rpc->listtransactions();
var_dump($transactions);

foreach($transactions as $tx){
    echo "TXID: $tx <br />";
}

Alternatively, try Inputs.io's API which is incredibly easy to use. Example callback PHP code is already given to you, you don't need to deal with running your own bitcoind. You can just set a callback URL and get the new transactions pushed to you.

(Btw, WTF is in your linked youtube video? Huh)

Thank you but I wish to have everything on my own server.
Otherwise I need to spend a lot of time and effort to decide if I can trust an outside server under the control of god-knows, with the control of my bitcoins. 

My youtube video is just a video of onw of my GPU miners Wink  ha ha

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 06, 2013, 01:58:39 AM
 #16

Get jsonrpcclient. Connect to bitcoind RPC. The data is automatically decoded.


I recommend against this for three reasons.

Firstly, unpatched, it can display your login information on errors.
Secondly, it does not work with php 5.4
Thirdly, it is GPLed so anything you make using it has to be GPLed as well.




Agreed.


Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
MangoJ (OP)
Full Member
***
Offline Offline

Activity: 222
Merit: 100


BTCRaven.com Escrow & Advertising


View Profile WWW
July 06, 2013, 02:20:15 AM
 #17


yes,  http://localhost:xxxx or http://127.0.0.1:xxxx,  bitcoin is listening if you run it with -server and/or -daemon.  I dont recall the default port number of hand, but it is in the wiki or source code.   You can also set it in bitcoin.conf with rpcport=1234


Ok, I can try that.  I just need to find out how to open bitcoin with -server or -daemon flags using the Terminal in Mac.

Automated Escrow  For instant BTC transactions without waiting for a 3rd party.  http://BTCRaven.com
🏰 TradeFortress 🏰
Bitcoin Veteran
VIP
Legendary
*
Offline Offline

Activity: 1316
Merit: 1043

👻


View Profile
July 06, 2013, 02:40:48 AM
 #18

Get jsonrpcclient. Connect to bitcoind RPC. The data is automatically decoded.


I recommend against this for three reasons.

Firstly, unpatched, it can display your login information on errors.
Secondly, it does not work with php 5.4
Thirdly, it is GPLed so anything you make using it has to be GPLed as well.
GPL licenses does not work like that.

If you don't have error reporting set to none on your production server, well....
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!