Installation
composer require lightningsale/lnd-client
Ensure your project uses PHP 7.2+ (LND compatibility may require newer versions).
Basic Connection
use LightningSale\LndClient\LndClient;
$client = new LndClient(
'your-lnd-grpc-url:10009', // Default gRPC port
'macaroon-file-path', // Path to macaroon file
'admin-macaroon' // Macaroon hex string or file content
);
First Use Case: Check Node Info
$nodeInfo = $client->getNodeInfo();
dump($nodeInfo->getIdentityPubkey());
src/LndClient.php – Core client class with all RPC methods.src/Protobuf/ – Generated protobuf classes (auto-generated from LND’s .proto files).tests/ – Example usage and edge cases.$invoice = $client->addInvoice([
'value' => 1000, // Satoshis
'memo' => 'Test payment',
]);
$paymentResult = $client->sendPayment($invoice->getPaymentRequest());
$client->subscribeToInvoices();
$invoices = $client->listInvoices();
$client->openChannel([
'public_key' => 'node_pubkey',
'local_funding_amount' => 1000000, // Satoshis
]);
$channels = $client->listChannels();
foreach ($channels as $channel) {
dump($channel->getRemotePubkey());
}
$address = $client->newAddress();
$balance = $client->walletBalance();
dump($balance->getTotalBalance());
Grpc\RpcException or LightningSale\LndClient\Exception\LndException.try {
$client->sendPayment($invoice);
} catch (\Grpc\RpcException $e) {
log::error("Payment failed: " . $e->getMessage());
}
revokeMacaroon if needed).lnd.conf for tlsextradomain and listen=0.0.0.0).$client = new LndClient(
'lnd-grpc.example.com:10009',
'macaroon_path',
'admin_macaroon',
['credentials' => Grpc\ChannelCredentials::createSsl()]
);
sendPaymentSync() for blocking calls or sendPayment() with callbacks for async.listInvoices with pagination).putenv('GRPC_VERBOSITY=DEBUG');
Deprecated Protobufs
protoc.Macaroon Permissions
invoice, sendpayments).listMacaroons in LND’s CLI to verify permissions.gRPC Timeouts
$client->setTimeout(30); // 30 seconds
Protobuf Type Mismatches
int64 for satoshis, but PHP may convert to float. Cast explicitly:
$amount = (int) $client->walletBalance()->getTotalBalance();
WebSocket Limitations
tail -f ~/.lnd/logs/bitcoin/debug.log
putenv('GRPC_TRACE=all');
var_dump() or json_encode() to inspect raw responses:
$rawResponse = $client->getRawResponse('GetInfo');
Custom Protobuf Extensions
Protobuf/ to add helper methods:
namespace App\Extensions;
use LightningSale\LndClient\Protobuf\Invoice;
class InvoiceExtension extends Invoice {
public function isPaid(): bool {
return $this->getState() === Invoice::SETTLED;
}
}
Middleware for Requests
class LoggingClient {
public function __call($method, $args) {
\Log::debug("Calling $method", $args);
return $client->$method(...$args);
}
}
Event Dispatching
event(new PaymentReceived($invoice));
Fallback for Deprecated Methods
public function deprecatedMethod() {
return $this->getClient()->newRpcMethod();
}
Macaroon File Paths
LND Version Mismatch
.proto files.Network Isolation
lnd --nolisten for dev) before deploying to production.How can I help you explore Laravel packages today?