{"id":15064228,"url":"https://github.com/ndeet/php-ln-lnd-rest","last_synced_at":"2025-04-10T11:51:05.009Z","repository":{"id":57024427,"uuid":"116940977","full_name":"ndeet/php-ln-lnd-rest","owner":"ndeet","description":"A Lightning Network Daemon (LND) package for LND's REST endpoints. PHP classes are generated by the Swagger Codegen project.","archived":false,"fork":false,"pushed_at":"2021-10-15T07:16:44.000Z","size":478,"stargazers_count":8,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T10:38:53.919Z","etag":null,"topics":["bitcoin","lightning-network","lnd","php","rest-api","swagger-codegen"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndeet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-10T10:10:41.000Z","updated_at":"2024-06-07T03:00:01.000Z","dependencies_parsed_at":"2022-08-23T13:50:32.315Z","dependency_job_id":null,"html_url":"https://github.com/ndeet/php-ln-lnd-rest","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndeet%2Fphp-ln-lnd-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndeet%2Fphp-ln-lnd-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndeet%2Fphp-ln-lnd-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndeet%2Fphp-ln-lnd-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndeet","download_url":"https://codeload.github.com/ndeet/php-ln-lnd-rest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248215192,"owners_count":21066619,"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","lightning-network","lnd","php","rest-api","swagger-codegen"],"created_at":"2024-09-25T00:14:03.845Z","updated_at":"2025-04-10T11:51:04.959Z","avatar_url":"https://github.com/ndeet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LndRest\n\nA [Lightning Network Daemon (LND)](https://github.com/lightningnetwork/lnd) package for LND's REST endpoints. PHP classes are generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project using LND's [rpc.swagger.json](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.swagger.json)\n\n- Based on LND version: 0.13.3-beta\n- This package version: 0.13.3\n\n## Requirements\n\nPHP 7.1 and later\n\n## Installation \u0026 Usage\n### Composer\n\nTo install the bindings via [Composer](http://getcomposer.org/), use the following command:\n\n```\ncomposer require ndeet/ln-lnd-rest\n```\n\n## Tests\n\nTo run the unit tests:\n\n```\ncomposer install\n./vendor/bin/phpunit\n```\n\n## Getting Started\n\nNote:   \n- The examples in the generated classes docs are not working out of the box. You will need to pass the port, use SSL and also\nuse macaroons of your properly secured LND installation.   \n- Generated classes with lnd-0.13.3-beta are not tested yet by me due to lack of time currently. Fingers crossed everything works.\n\n```php\n\u003c?php\nrequire_once(__DIR__ . '/vendor/autoload.php');\n\n// Get tls and macaroon paths.\n$tlsPath = '';\n$macaroonPath = '';\n$local_user = posix_getpwuid(posix_getuid());\n\nswitch (PHP_OS) {\n  case \"Darwin\":\n    $tlsPath = $local_user['dir'] . '/Library/Application Support/Lnd/tls.cert';\n    $macaroonPath = $local_user['dir'] . '/Library/Application Support/Lnd/macaroon.admin';\n    break;\n\n  case \"Linux\":\n    $tlsPath = $local_user['dir'] . '/.lnd/tls.cert';\n    $macaroonPath = $local_user['dir'] . '/.lnd/macaroon.admin';\n}\n\nif (! $sslCert = file_get_contents($tlsPath)) {\n  $certError = \u003c\u003c\u003cEOT\n    tls.cert not found in \"example\" directory. Make sure to copy it from your\n    LND config directory.\n    MacOS: ~/Library/Application Support/Lnd/tls.cert\n    Linux: ~/.lnd/tls.cert\nEOT;\n\n  throw new Exception($certError);\n}\n\n// We need to use Configuration class for the url and can't pass it directly in GuzzleClient.\n$apiConfig = new \\Lnd\\Rest\\Configuration();\n$apiConfig-\u003esetHost('https://localhost:8001');\n\n// First we need to unlock the encrypted wallet. This needs only run once.\n$walletInstance = new Lnd\\Rest\\Api\\WalletUnlockerApi(\n// If you want use custom http client, pass your client which implements `GuzzleHttp\\ClientInterface`.\n// This is optional, `GuzzleHttp\\Client` will be used as default.\n  new GuzzleHttp\\Client([\n    'debug' =\u003e TRUE,\n    'verify' =\u003e $tlsPath,\n    'headers' =\u003e [\n      'Grpc-Metadata-macaroon' =\u003e $macaroon\n    ]\n  ]),\n  $apiConfig\n);\n\n$unlockRequest = new \\Lnd\\Rest\\Model\\LnrpcUnlockWalletRequest([\n  'walletPassword' =\u003e base64_encode('YOUR_WALLET_PASS')\n]);\n\ntry {\n  $unlocked = $walletInstance-\u003eunlockWallet($unlockRequest);\n  // gives 408 timeout but unlock successful, afterwards 404 not found\n} catch (Exception $e) {\n  echo 'Exception when calling WalletUnlockerApi-\u003eunlockWallet(): ', $e-\u003egetMessage(), PHP_EOL;\n}\n\n// We can now use the getInfo endpoint:\n$apiInstance = new Lnd\\Rest\\Api\\LightningApi(\n// If you want use custom http client, pass your client which implements `GuzzleHttp\\ClientInterface`.\n// This is optional, `GuzzleHttp\\Client` will be used as default.\n  new GuzzleHttp\\Client([\n    'debug' =\u003e TRUE,\n    'verify' =\u003e $tlsPath,\n    'headers' =\u003e [\n      'Grpc-Metadata-macaroon' =\u003e bin2hex(file_get_contents($macaroonPath))\n    ]\n  ]),\n  $apiConfig\n);\n\ntry {\n  $result = $apiInstance-\u003egetInfo();\n  var_dump($result);\n} catch (Exception $e) {\n  echo 'Exception when calling LightningApi-\u003egetInfo: ', $e-\u003egetMessage(), PHP_EOL;\n}\n\n// Let's generate an lightning invoice.\n$invoice = new \\Lnd\\Rest\\Model\\LnrpcInvoice([\n  'memo' =\u003e 'testinvoice memo',\n  'value' =\u003e 1001,\n  'expiry' =\u003e 3600\n]);\n\ntry {\n  $invoiceResult = $apiInstance-\u003eaddInvoice($invoice);\n  var_dump($invoiceResult);\n} catch (Exception $e) {\n  echo 'Exception when calling LightningApi-\u003eaddInvoice: ', $e-\u003egetMessage(), PHP_EOL;\n}\n\n?\u003e\n```\n\n## How to generate the code yourself\n\nYou can use swagger-codegen to create this whole package out of the rpc.swagger.json of LND. To do this you need swagger-codegen and (for this package as example) this `lnrest-config.json`:\n\n```\n{\n  \"variableNamingConvention\": \"camelCase\",\n  \"invokerPackage\": \"Lnd\\\\Rest\",\n  \"packagePath\": \"LndRest\",\n  \"srcBasePath\": \"src\",\n  \"composerVendorName\": \"ndeet\",\n  \"gitUserId\": \"ndeet\",\n  \"composerProjectName\": \"ln-lnd-rest\",\n  \"gitRepoId\": \"php-ln-lnd-rest\",\n  \"artifactVersion\": \"0.13.3\",\n  \"license\": \"MIT\"\n}\n```\n\nYou can generate the code by having the official [lightningnetwork/lnd](https://github.com/lightningnetwork/lnd) repo checked out to the tag you need and then use that rpc.swagger.json for the code genration like this.\n```\nswagger-codegen generate -c lnrest-config.json -l php -o php-ln-lnd-rest -i /path/to/lightningnetwork/lnd/lnrpc/rpc.swagger.json\n```\n\n\n## Notice regarding to `subscribeInvoices` endpoint\nThe REST endpoints are generated from the same gRPC `rpc.proto` file and it seems the streaming does not work on REST services according to LND's lead developer [@roasbeef](https://github.com/roasbeef). But they plan to provide Websockets in a future release. So you may need to do some custom long polling using [**lookupInvoice**](docs/Api/LightningApi.md#lookupinvoice) endpoint.\n\nThis are some autogenerated docs pointing to classes docs:\n\n## Documentation for API endpoints\n\n[Lightning API Endpoints](docs/Api/LightningApi.md)   \n[Wallet Unlocker API](docs/Api/WalletUnlockerApi.md)\n\n## Documentation for authorization\n\nAll endpoints do not require authorization. Make sure that those endpoints provided \nby this package are not publicly accessible. If you set a wallet password you need\nto unlock your wallet first, see documentation and example above.\n\n## Author\n\nAndreas Tasch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndeet%2Fphp-ln-lnd-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndeet%2Fphp-ln-lnd-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndeet%2Fphp-ln-lnd-rest/lists"}