How To connect BItcoin Core with Php

2

i installed a bitcoind core and i access bitcoin-cli command in linux terminal with developer command(getbalance, getaccountaddress etc.) but i want run this command in php file.

my php code is:

chdir('/home/itr/Downloads/bitcoin/bin');
$output = shell_exec("./bitcoin-cli getbalance");
echo var_dump($output); 

bitcoin-cli file path:

/home/itr/Downloads/bitcoin/bin

please tell me what i do?

Mohammad Asif

Posted 2017-01-19T09:53:04.460

Reputation: 21

Answers

3

I would definitely not do it this way and use a RPC client. A very simple one is https://github.com/aceat64/EasyBitcoin-PHP

Alex

Posted 2017-01-19T09:53:04.460

Reputation: 398

0

You have a couple of approaches:

  1. Use some well written JSON/RPC php client like this php-json-rpc-http [For using via HTTPS] or php-json-rpc-ssh [For using via SSH] along with implementing calls on your own based on Bitcoin's Reference API CallsList. Bitcoin RPC quick reference is also very helpful.
  2. Completely rely on PHP-BitconRPC, which is a well unit-tested all-in-one library using Guzzle

Behrad Khodayar

Posted 2017-01-19T09:53:04.460

Reputation: 213