Author

Topic: I can code PHP, but how do I use JSON for bitcoin transactions? (Read 1528 times)

vip
Activity: 1316
Merit: 1043
👻
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....
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising

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.
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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.

full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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
";
}

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
sr. member
Activity: 574
Merit: 250

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
sr. member
Activity: 574
Merit: 250
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.


vip
Activity: 1316
Merit: 1043
👻
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
";
}

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)
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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.
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising

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.
legendary
Activity: 1135
Merit: 1166
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.
sr. member
Activity: 574
Merit: 250
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.
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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?
hero member
Activity: 632
Merit: 500
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.
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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.
hero member
Activity: 632
Merit: 500
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
I use Bitcoin-Qt on a Mac.

Help would be very appreciated.
newbie
Activity: 19
Merit: 0
what kind of wallet you use ?? maybe i can help you  Roll Eyes
full member
Activity: 222
Merit: 100
BTCRaven.com Escrow & Advertising
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.
Jump to: