GetState
GetState returns the current wallet state without streaming further changes.
Source: stateservice.proto
gRPC
rpc GetState (GetStateRequest) returns (GetStateResponse);
REST
HTTP Method | Path |
---|---|
GET | /v1/state |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:10009'
const TLS_PATH = 'LND_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'stateservice.proto'], loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
let client = new lnrpc.State(GRPC_HOST, sslCreds);
let request = {};
client.getState(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "state": <WalletState>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the stateservice.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import stateservice_pb2 as lnrpc, stateservice_pb2_grpc as stateservicestub
GRPC_HOST = 'localhost:10009'
TLS_PATH = 'LND_DIR/tls.cert'
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# make the request
channel = grpc.secure_channel(GRPC_HOST, ssl_creds)
stub = stateservicestub.StateStub(channel)
request = lnrpc.GetStateRequest()
response = stub.GetState(request)
print(response)
# {
# "state": <WalletState>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
let options = {
url: `https://${REST_HOST}/v1/state`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
}
request.get(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "state": <string>, // <WalletState>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/state'
r = requests.get(url, verify=TLS_PATH)
print(r.json())
# {
# "state": <WalletState>,
# }
# There is no CLI command for this RPC
Messages
lnrpc.GetStateRequest
Source: stateservice.proto
note
This request has no parameters.
lnrpc.GetStateResponse
Source: stateservice.proto
Field | gRPC Type | REST Type |
---|---|---|
state | WalletState | string |
Enums
lnrpc.WalletState
Name | Number |
---|---|
NON_EXISTING | 0 |
LOCKED | 1 |
UNLOCKED | 2 |
RPC_ACTIVE | 3 |
SERVER_ACTIVE | 4 |
WAITING_TO_START | 255 |