{"id":15201951,"url":"https://github.com/padrio/php-electrum-api","last_synced_at":"2025-10-02T18:31:03.580Z","repository":{"id":47509749,"uuid":"79497694","full_name":"Padrio/php-electrum-api","owner":"Padrio","description":"💰PHP wrapper for Electrum JSONRPC-API","archived":true,"fork":false,"pushed_at":"2021-08-28T01:27:31.000Z","size":88,"stargazers_count":29,"open_issues_count":10,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-16T02:47:26.026Z","etag":null,"topics":["bitcoin","bitcoin-api","bitcoins","composer","electrum","php-electrum-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Padrio.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":null,"support":null}},"created_at":"2017-01-19T21:36:53.000Z","updated_at":"2024-11-06T20:40:42.000Z","dependencies_parsed_at":"2022-07-22T13:32:32.723Z","dependency_job_id":null,"html_url":"https://github.com/Padrio/php-electrum-api","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padrio%2Fphp-electrum-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padrio%2Fphp-electrum-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padrio%2Fphp-electrum-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padrio%2Fphp-electrum-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Padrio","download_url":"https://codeload.github.com/Padrio/php-electrum-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235031458,"owners_count":18925237,"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":["bitcoin","bitcoin-api","bitcoins","composer","electrum","php-electrum-api"],"created_at":"2024-09-28T03:43:49.377Z","updated_at":"2025-10-02T18:30:58.307Z","avatar_url":"https://github.com/Padrio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Packagist](https://img.shields.io/packagist/dt/padrio/php-electrum-api.svg?color=%234c1)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/padrio/php-electrum-api.svg?color=%234c1)\n\n# php-electrum-api - Electrum library\n```\nLicence: GPL-3.0\nAuthor: Pascal Krason \u003cp.krason@padr.io\u003e\nLanguage: PHP 5.6-7.1\n```\nPlease note, this library is by far not completed and but can be used in production. Until now i only implemented the most commonly used API-Calls. If you think im missing something, just create an issue or fork the project.\n\n# Setting up Electrum\nFirst you need to setup a new Electrum wallet. Follow the instructions according to your OS at the [Electrum Download Page](https://electrum.org/#download). After the successfull installation you need to set a rpcport by typing:\n```\nelectrum setconfig rpcport 7777\nelectrum setconfig rpcuser \"username\"\nelectrum setconfig rpcpassword \"password\"\n```\nThen we can create a default wallet, dont forget to note your generated seed, it's nescessary if you want to recover it one day:\n```\nelectrum create\n```\nNow we can go ahead and start Electrum in daemon mode:\n```\nelectrum daemon start\n```\nSince some new version electrum wants you to load your wallet by hand on startup:\n```\nelectrum daemon load_wallet\n```\n\n# Requirements\nOn the PHP side there are not much requirements, you only need at least PHP 5.6 and the curl-Extension installed. Then you can go ahead ans it through [Composer](http://getcomposer.org) which will do everything else for you.\n\n# Install\nFirst you need to install [Composer](https://getcomposer.org/doc/00-intro.md), after you accomplished this you can go ahead:\n```\ncomposer require padrio/php-electrum-api\n```\nThen you can simply include the autoloader and begin using the library:\n```php\n// Include composer autoloader\nrequire_once 'vendor/autoloader.php';\n```\n\n# Examples\n\n## Basic example\nA very basic useage example. Every API-Call has it's own request-object. You simply create one and execute it.\n```php\n\n$method = new \\Electrum\\Request\\Method\\Version();\n\ntry {\n    $response = $method-\u003eexecute();\n} catch(\\Exception $exception) {\n    die($exception-\u003egetMessage());\n}\n\n$response-\u003egetVersion();\n```\n\n## Create new wallet\n\nCreate default wallet:\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $wallet = new \\Electrum\\Request\\Method\\Wallet\\CreateWallet($client);\n    $response = $wallet-\u003eexecute();\n```\n\nThis code is similar to the command:\n```bash\n$ electrum create\n```\n\nYou can also create more wallets with custom names specifying flag of the new wallet. \n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $wallet = new \\Electrum\\Request\\Method\\Wallet\\CreateWallet($client);\n    $response = $wallet-\u003eexecute(['wallet_path' =\u003e '~/.electrum/wallets/your_wallet']);\n```\n\nThis code is similar to the command:\n```bash\n$ electrum create -w ~/.electrum/wallets/your_wallet\n```\n\nResponse will be:\n```php\n[\n    'seed' =\u003e 'wallet seed',\n    'path' =\u003e 'path where wallet file is stored',\n    'msg'  =\u003e 'Please keep your seed in a safe place; if you lose it, you will not be able to restore your wallet.',\n];\n```\n\n## Load wallet\n\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $load_wallet = new \\Electrum\\Request\\Method\\Wallet\\LoadWallet($client);\n    $load_wallet-\u003eexecute(['wallet_path' =\u003e '~/.electrum/wallets/your_wallet']);\n````\n\n## List wallets\n\nGet list of all loaded wallets:\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $list_wallets = new \\Electrum\\Request\\Method\\Wallet\\ListWallets($client);\n    $list_wallets-\u003eexecute();\n```\n\n## Get new address\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $wallet = new \\Electrum\\Request\\Method\\Payment\\AddRequest($client);\n    $tx     = $wallet-\u003eexecute();\n    echo $tx-\u003egetAddress();\n```\n\n## Create new address for wallet\n\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $newAddress = new \\Electrum\\Request\\Method\\Address\\CreateNewAddress($client);\n    $newAddress-\u003eexecute(['wallet'  =\u003e '~/.electrum/wallets/your_wallet']);\n```\n\n\n## Make a new Payment\n```php\n    $client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'user', 'password');\n    $method = new \\Electrum\\Request\\Method\\Payment\\PayTo($client);\n    $method-\u003esetDestination('BTC4ddress1234'); //Destination parameter is the address where we'll send the btc\n    $method-\u003esetAmount(1); //send 1 BTC = 10k usd\n    \n    $tx = $method-\u003eexecute(); //$tx returns the transaction ID of the payment, this is still not sent to the blockchain\n    /**\n    * @param array ['password' =\u003e '\u003cpassword\u003e']\n    * If the Electrum wallet is encrypted with a password use the following execute method instead\n    * The previous one will return an error of \"Password required\"\n    */\n    //$tx = $method-\u003eexecute(['password' =\u003e 'myPass123']); //\n    \n    $broadcast = new Electrum\\Request\\Method\\Payment\\Broadcast($client);\n    $broadcast-\u003esetTransaction($tx);\n    $result = $broadcast-\u003eexecute(); //broadcasts payment to the blockchain\n    echo $result;\n    \n    A payment has been made\n    \n```\n\n## Custom Client Configuration\nEvery Request/Method takes a `Electrum\\Client`-instance as parameter which replaces the default one. A custom instance can be usefull if you want to set custom config params like another Hostname or Port.\n```php\n$client = new \\Electrum\\Client('http://127.0.0.1', 7777, 0, 'username', 'password');\n$method = new \\Electrum\\Request\\Method\\Version($client);\n\ntry {\n    $response = $method-\u003eexecute();\n} catch (\\Exception $exception) {\n    die($exception-\u003egetMessage());\n}\n\n$response-\u003egetVersion();\n```\n\n## Advanced exception handling\nDealing with exceptions is easy. You can catch two types of exceptions which indicates whether it's an Request or Response fault.\n```php\n$method = new \\Electrum\\Request\\Method\\Version();\n\ntry {\n    $response = $method-\u003eexecute();\n} catch (\\Electrum\\Request\\Exception\\BadRequestException $exception) {\n    die(sprintf(\n        'Failed to send request: %s',\n        $exception-\u003egetMessage()\n    ));\n} catch(\\Electrum\\Response\\Exception\\BadResponseException $exception) {\n    die(sprintf(\n        'Electrum-Client failed to respond correctly: %s',\n        $exception-\u003egetMessage()\n    ));\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadrio%2Fphp-electrum-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadrio%2Fphp-electrum-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadrio%2Fphp-electrum-api/lists"}