{"id":15628564,"url":"https://github.com/denpamusic/php-bitcoinrpc","last_synced_at":"2025-05-16T13:07:09.635Z","repository":{"id":38361984,"uuid":"77535983","full_name":"denpamusic/php-bitcoinrpc","owner":"denpamusic","description":"Fully unit-tested Bitcoin JSON-RPC client based on GuzzleHttp.","archived":false,"fork":false,"pushed_at":"2022-05-24T01:16:32.000Z","size":345,"stargazers_count":281,"open_issues_count":11,"forks_count":100,"subscribers_count":21,"default_branch":"2.2.x","last_synced_at":"2025-05-13T10:19:32.646Z","etag":null,"topics":["api","api-client","bitcoin","cryptocurrency","guzzlehttp","json-rpc"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denpamusic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2016-12-28T13:48:32.000Z","updated_at":"2025-04-17T16:23:59.000Z","dependencies_parsed_at":"2022-08-21T06:10:23.809Z","dependency_job_id":null,"html_url":"https://github.com/denpamusic/php-bitcoinrpc","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpamusic%2Fphp-bitcoinrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpamusic%2Fphp-bitcoinrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpamusic%2Fphp-bitcoinrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denpamusic%2Fphp-bitcoinrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denpamusic","download_url":"https://codeload.github.com/denpamusic/php-bitcoinrpc/tar.gz/refs/heads/2.2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535829,"owners_count":22087399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-client","bitcoin","cryptocurrency","guzzlehttp","json-rpc"],"created_at":"2024-10-03T10:23:05.754Z","updated_at":"2025-05-16T13:07:09.587Z","avatar_url":"https://github.com/denpamusic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Bitcoin JSON-RPC client based on GuzzleHttp\n\n[![Latest Stable Version](https://poser.pugx.org/denpa/php-bitcoinrpc/v/stable)](https://packagist.org/packages/denpa/php-bitcoinrpc)\n[![License](https://poser.pugx.org/denpa/php-bitcoinrpc/license)](https://packagist.org/packages/denpa/php-bitcoinrpc)\n[![ci](https://github.com/denpamusic/php-bitcoinrpc/actions/workflows/ci.yml/badge.svg)](https://github.com/denpamusic/php-bitcoinrpc/actions/workflows/ci.yml)\n[![Code Climate](https://codeclimate.com/github/denpamusic/php-bitcoinrpc/badges/gpa.svg)](https://codeclimate.com/github/denpamusic/php-bitcoinrpc)\n[![Code Coverage](https://codeclimate.com/github/denpamusic/php-bitcoinrpc/badges/coverage.svg)](https://codeclimate.com/github/denpamusic/php-bitcoinrpc/coverage)\n\n## Installation\nRun ```php composer.phar require denpa/php-bitcoinrpc``` in your project directory or add following lines to composer.json\n```javascript\n\"require\": {\n    \"denpa/php-bitcoinrpc\": \"^2.2\"\n}\n```\nand run ```php composer.phar install```.\n\n## Requirements\nPHP 8.0 or higher  \n_For PHP 5.6 to 7.0 use [php-bitcoinrpc v2.0.x](https://github.com/denpamusic/php-bitcoinrpc/tree/2.0.x)._  \n_For PHP 7.0 to 7.4 use [php-bitcoinrpc v2.0.x](https://github.com/denpamusic/php-bitcoinrpc/tree/2.1.x)._  \n\n## Usage\nCreate new object with url as parameter\n```php\n/**\n * Don't forget to include composer autoloader by uncommenting line below\n * if you're not already done it anywhere else in your project.\n **/\n// require 'vendor/autoload.php';\n\nuse Denpa\\Bitcoin\\Client as BitcoinClient;\n\n$bitcoind = new BitcoinClient('http://rpcuser:rpcpassword@localhost:8332/');\n```\nor use array to define your bitcoind settings\n```php\n/**\n * Don't forget to include composer autoloader by uncommenting line below\n * if you're not already done it anywhere else in your project.\n **/\n// require 'vendor/autoload.php';\n\nuse Denpa\\Bitcoin\\Client as BitcoinClient;\n\n$bitcoind = new BitcoinClient([\n    'scheme'        =\u003e 'http',                 // optional, default http\n    'host'          =\u003e 'localhost',            // optional, default localhost\n    'port'          =\u003e 8332,                   // optional, default 8332\n    'user'          =\u003e 'rpcuser',              // required\n    'password'      =\u003e 'rpcpassword',          // required\n    'ca'            =\u003e '/etc/ssl/ca-cert.pem',  // optional, for use with https scheme\n    'preserve_case' =\u003e false,                  // optional, send method names as defined instead of lowercasing them\n]);\n```\nThen call methods defined in [Bitcoin Core API Documentation](https://bitcoin.org/en/developer-reference#bitcoin-core-apis) with magic:\n```php\n/**\n * Get block info.\n */\n$block = $bitcoind-\u003egetBlock('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');\n\n$block('hash')-\u003eget();     // 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\n$block['height'];          // 0 (array access)\n$block-\u003eget('tx.0');       // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b\n$block-\u003ecount('tx');       // 1\n$block-\u003ehas('version');    // key must exist and CAN NOT be null\n$block-\u003eexists('version'); // key must exist and CAN be null\n$block-\u003econtains(0);       // check if response contains value\n$block-\u003evalues();          // array of values\n$block-\u003ekeys();            // array of keys\n$block-\u003erandom(1, 'tx');   // random block txid\n$block('tx')-\u003erandom(2);   // two random block txid's\n$block('tx')-\u003efirst();     // txid of first transaction\n$block('tx')-\u003elast();      // txid of last transaction\n\n/**\n * Send transaction.\n */\n$result = $bitcoind-\u003esendToAddress('mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6', 0.1);\n$txid = $result-\u003eget();\n\n/**\n * Get transaction amount.\n */\n$result = $bitcoind-\u003elistSinceBlock();\n$bitcoin = $result-\u003esum('transactions.*.amount');\n$satoshi = \\Denpa\\Bitcoin\\to_satoshi($bitcoin);\n```\nTo send asynchronous request, add Async to method name:\n```php\n$bitcoind-\u003egetBlockAsync(\n    '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',\n    function ($response) {\n        // success\n    },\n    function ($exception) {\n        // error\n    }\n);\n```\n\nYou can also send requests using request method:\n```php\n/**\n * Get block info.\n */\n$block = $bitcoind-\u003erequest('getBlock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');\n\n$block('hash');            // 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\n$block['height'];          // 0 (array access)\n$block-\u003eget('tx.0');       // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b\n$block-\u003ecount('tx');       // 1\n$block-\u003ehas('version');    // key must exist and CAN NOT be null\n$block-\u003eexists('version'); // key must exist and CAN be null\n$block-\u003econtains(0);       // check if response contains value\n$block-\u003evalues();          // get response values\n$block-\u003ekeys();            // get response keys\n$block-\u003efirst('tx');       // get txid of the first transaction\n$block-\u003elast('tx');        // get txid of the last transaction\n$block-\u003erandom(1, 'tx');   // get random txid\n\n/**\n * Send transaction.\n */\n$result = $bitcoind-\u003erequest('sendtoaddress', 'mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6', 0.06);\n$txid = $result-\u003eget();\n\n```\nor requestAsync method for asynchronous calls:\n```php\n$bitcoind-\u003erequestAsync(\n    'getBlock',\n    '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',\n    function ($response) {\n        // success\n    },\n    function ($exception) {\n        // error\n    }\n);\n```\n\n## Multi-Wallet RPC\nYou can use `wallet($name)` function to do a [Multi-Wallet RPC call](https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Multi-wallet_RPC_calls):\n```php\n/**\n * Get wallet2.dat balance.\n */\n$balance = $bitcoind-\u003ewallet('wallet2.dat')-\u003egetbalance();\n\necho $balance-\u003eget(); // 0.10000000\n```\n\n## Exceptions\n* `Denpa\\Bitcoin\\Exceptions\\BadConfigurationException` - thrown on bad client configuration.\n* `Denpa\\Bitcoin\\Exceptions\\BadRemoteCallException` - thrown on getting error message from daemon.\n* `Denpa\\Bitcoin\\Exceptions\\ConnectionException` - thrown on daemon connection errors (e. g. timeouts)\n\n\n## Helpers\nPackage provides following helpers to assist with value handling.\n#### `to_bitcoin()`\nConverts value in satoshi to bitcoin.\n```php\necho Denpa\\Bitcoin\\to_bitcoin(100000); // 0.00100000\n```\n#### `to_satoshi()`\nConverts value in bitcoin to satoshi.\n```php\necho Denpa\\Bitcoin\\to_satoshi(0.001); // 100000\n```\n#### `to_ubtc()`\nConverts value in bitcoin to ubtc/bits.\n```php\necho Denpa\\Bitcoin\\to_ubtc(0.001); // 1000.0000\n```\n#### `to_mbtc()`\nConverts value in bitcoin to mbtc.\n```php\necho Denpa\\Bitcoin\\to_mbtc(0.001); // 1.0000\n```\n#### `to_fixed()`\nTrims float value to precision without rounding.\n```php\necho Denpa\\Bitcoin\\to_fixed(0.1236, 3); // 0.123\n```\n\n## License\n\nThis product is distributed under MIT license.\n\n## Donations\n\nIf you like this project, please consider donating:\u003cbr\u003e\n**BTC**: 3L6dqSBNgdpZan78KJtzoXEk9DN3sgEQJu\u003cbr\u003e\n**Bech32**: bc1qyj8v6l70c4mjgq7hujywlg6le09kx09nq8d350\n\n❤Thanks for your support!❤\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenpamusic%2Fphp-bitcoinrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenpamusic%2Fphp-bitcoinrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenpamusic%2Fphp-bitcoinrpc/lists"}