InitWallet
InitWallet is used when lnd is starting up for the first time to fully initialize the daemon and its internal wallet. At the very least a wallet password must be provided. This will be used to encrypt sensitive material on disk.
In the case of a recovery scenario, the user can also specify their aezeed mnemonic and passphrase. If set, then the daemon will use this prior state to initialize its internal wallet.
Alternatively, this can be used along with the GenSeed RPC to obtain a seed, then present it to the user. Once it has been verified by the user, the seed can be fed into this RPC in order to commit the new wallet.
Source: walletunlocker.proto
gRPC
rpc InitWallet (InitWalletRequest) returns (InitWalletResponse);
REST
HTTP Method | Path |
---|---|
POST | /v1/initwallet |
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', 'walletunlocker.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.WalletUnlocker(GRPC_HOST, sslCreds);
let request = {
wallet_password: <bytes>,
cipher_seed_mnemonic: <string>,
aezeed_passphrase: <bytes>,
recovery_window: <int32>,
channel_backups: <ChanBackupSnapshot>,
stateless_init: <bool>,
extended_master_key: <string>,
extended_master_key_birthday_timestamp: <uint64>,
watch_only: <WatchOnly>,
macaroon_root_key: <bytes>,
};
client.initWallet(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "admin_macaroon": <bytes>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the walletunlocker.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import walletunlocker_pb2 as lnrpc, walletunlocker_pb2_grpc as walletunlockerstub
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 = walletunlockerstub.WalletUnlockerStub(channel)
request = lnrpc.InitWalletRequest(
wallet_password=<bytes>,
cipher_seed_mnemonic=<string>,
aezeed_passphrase=<bytes>,
recovery_window=<int32>,
channel_backups=<ChanBackupSnapshot>,
stateless_init=<bool>,
extended_master_key=<string>,
extended_master_key_birthday_timestamp=<uint64>,
watch_only=<WatchOnly>,
macaroon_root_key=<bytes>,
)
response = stub.InitWallet(request)
print(response)
# {
# "admin_macaroon": <bytes>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
let requestBody = {
wallet_password: <string>, // <bytes> (base64 encoded)
cipher_seed_mnemonic: <array>, // <string>
aezeed_passphrase: <string>, // <bytes> (base64 encoded)
recovery_window: <integer>, // <int32>
channel_backups: <object>, // <ChanBackupSnapshot>
stateless_init: <boolean>, // <bool>
extended_master_key: <string>, // <string>
extended_master_key_birthday_timestamp: <string>, // <uint64>
watch_only: <object>, // <WatchOnly>
macaroon_root_key: <string>, // <bytes> (base64 encoded)
};
let options = {
url: `https://${REST_HOST}/v1/initwallet`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "admin_macaroon": <string>, // <bytes>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/initwallet'
data = {
'wallet_password': base64.b64encode(<bytes>),
'cipher_seed_mnemonic': <string>,
'aezeed_passphrase': base64.b64encode(<bytes>),
'recovery_window': <int32>,
'channel_backups': <ChanBackupSnapshot>,
'stateless_init': <bool>,
'extended_master_key': <string>,
'extended_master_key_birthday_timestamp': <uint64>,
'watch_only': <WatchOnly>,
'macaroon_root_key': base64.b64encode(<bytes>),
}
r = requests.post(url, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "admin_macaroon": <bytes>,
# }
# There is no CLI command for this RPC
Messages
lnrpc.InitWalletRequest
Source: walletunlocker.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
wallet_password | bytes | string | body |
cipher_seed_mnemonic | string[] | array | body |
aezeed_passphrase | bytes | string | body |
recovery_window | int32 | integer | body |
channel_backups | ChanBackupSnapshot | object | body |
stateless_init | bool | boolean | body |
extended_master_key | string | string | body |
extended_master_key_birthday_timestamp | uint64 | string | body |
watch_only | WatchOnly | object | body |
macaroon_root_key | bytes | string | body |
lnrpc.InitWalletResponse
Source: walletunlocker.proto
Field | gRPC Type | REST Type |
---|---|---|
admin_macaroon | bytes | string |
Nested Messages
lnrpc.ChanBackupSnapshot
Field | gRPC Type | REST Type |
---|---|---|
single_chan_backups | ChannelBackups | object |
multi_chan_backup | MultiChanBackup | object |
lnrpc.ChannelBackups
Field | gRPC Type | REST Type |
---|---|---|
chan_backups | ChannelBackup[] | array |
lnrpc.ChannelBackup
Field | gRPC Type | REST Type |
---|---|---|
chan_point | ChannelPoint | object |
chan_backup | bytes | string |
lnrpc.ChannelPoint
Field | gRPC Type | REST Type |
---|---|---|
funding_txid_bytes | bytes | string |
funding_txid_str | string | string |
output_index | uint32 | integer |
lnrpc.MultiChanBackup
Field | gRPC Type | REST Type |
---|---|---|
chan_points | ChannelPoint[] | array |
multi_chan_backup | bytes | string |
lnrpc.WatchOnly
Field | gRPC Type | REST Type |
---|---|---|
master_key_birthday_timestamp | uint64 | string |
master_key_fingerprint | bytes | string |
accounts | WatchOnlyAccount[] | array |
lnrpc.WatchOnlyAccount
Field | gRPC Type | REST Type |
---|---|---|
purpose | uint32 | integer |
coin_type | uint32 | integer |
account | uint32 | integer |
xpub | string | string |