OpenChannelSync
OpenChannelSync is a synchronous version of the OpenChannel RPC call. This call is meant to be consumed by clients to the REST proxy. As with all other sync calls, all byte slices are intended to be populated as hex encoded strings.
Source: lightning.proto
gRPC
rpc OpenChannelSync (OpenChannelRequest) returns (ChannelPoint);
REST
HTTP Method | Path |
---|---|
POST | /v1/channels |
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 MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
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', 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);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new lnrpc.Lightning(GRPC_HOST, creds);
let request = {
sat_per_vbyte: <uint64>,
node_pubkey: <bytes>,
node_pubkey_string: <string>,
local_funding_amount: <int64>,
push_sat: <int64>,
target_conf: <int32>,
sat_per_byte: <int64>,
private: <bool>,
min_htlc_msat: <int64>,
remote_csv_delay: <uint32>,
min_confs: <int32>,
spend_unconfirmed: <bool>,
close_address: <string>,
funding_shim: <FundingShim>,
remote_max_value_in_flight_msat: <uint64>,
remote_max_htlcs: <uint32>,
max_local_csv: <uint32>,
commitment_type: <CommitmentType>,
zero_conf: <bool>,
scid_alias: <bool>,
base_fee: <uint64>,
fee_rate: <uint64>,
use_base_fee: <bool>,
use_fee_rate: <bool>,
remote_chan_reserve_sat: <uint64>,
fund_max: <bool>,
memo: <string>,
outpoints: <OutPoint>,
};
client.openChannelSync(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "funding_txid_bytes": <bytes>,
// "funding_txid_str": <string>,
// "output_index": <uint32>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lightning.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
GRPC_HOST = 'localhost:10009'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = lightningstub.LightningStub(channel)
request = lnrpc.OpenChannelRequest(
sat_per_vbyte=<uint64>,
node_pubkey=<bytes>,
node_pubkey_string=<string>,
local_funding_amount=<int64>,
push_sat=<int64>,
target_conf=<int32>,
sat_per_byte=<int64>,
private=<bool>,
min_htlc_msat=<int64>,
remote_csv_delay=<uint32>,
min_confs=<int32>,
spend_unconfirmed=<bool>,
close_address=<string>,
funding_shim=<FundingShim>,
remote_max_value_in_flight_msat=<uint64>,
remote_max_htlcs=<uint32>,
max_local_csv=<uint32>,
commitment_type=<CommitmentType>,
zero_conf=<bool>,
scid_alias=<bool>,
base_fee=<uint64>,
fee_rate=<uint64>,
use_base_fee=<bool>,
use_fee_rate=<bool>,
remote_chan_reserve_sat=<uint64>,
fund_max=<bool>,
memo=<string>,
outpoints=<OutPoint>,
)
response = stub.OpenChannelSync(request)
print(response)
# {
# "funding_txid_bytes": <bytes>,
# "funding_txid_str": <string>,
# "output_index": <uint32>,
# }
- Javascript
- Python
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let requestBody = {
sat_per_vbyte: <string>, // <uint64>
node_pubkey: <string>, // <bytes> (base64 encoded)
node_pubkey_string: <string>, // <string>
local_funding_amount: <string>, // <int64>
push_sat: <string>, // <int64>
target_conf: <integer>, // <int32>
sat_per_byte: <string>, // <int64>
private: <boolean>, // <bool>
min_htlc_msat: <string>, // <int64>
remote_csv_delay: <integer>, // <uint32>
min_confs: <integer>, // <int32>
spend_unconfirmed: <boolean>, // <bool>
close_address: <string>, // <string>
funding_shim: <object>, // <FundingShim>
remote_max_value_in_flight_msat: <string>, // <uint64>
remote_max_htlcs: <integer>, // <uint32>
max_local_csv: <integer>, // <uint32>
commitment_type: <string>, // <CommitmentType>
zero_conf: <boolean>, // <bool>
scid_alias: <boolean>, // <bool>
base_fee: <string>, // <uint64>
fee_rate: <string>, // <uint64>
use_base_fee: <boolean>, // <bool>
use_fee_rate: <boolean>, // <bool>
remote_chan_reserve_sat: <string>, // <uint64>
fund_max: <boolean>, // <bool>
memo: <string>, // <string>
outpoints: <array>, // <OutPoint>
};
let options = {
url: `https://${REST_HOST}/v1/channels`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
form: JSON.stringify(requestBody),
}
request.post(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "funding_txid_bytes": <string>, // <bytes>
// "funding_txid_str": <string>, // <string>
// "output_index": <integer>, // <uint32>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/channels'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
data = {
'sat_per_vbyte': <uint64>,
'node_pubkey': base64.b64encode(<bytes>),
'node_pubkey_string': <string>,
'local_funding_amount': <int64>,
'push_sat': <int64>,
'target_conf': <int32>,
'sat_per_byte': <int64>,
'private': <bool>,
'min_htlc_msat': <int64>,
'remote_csv_delay': <uint32>,
'min_confs': <int32>,
'spend_unconfirmed': <bool>,
'close_address': <string>,
'funding_shim': <FundingShim>,
'remote_max_value_in_flight_msat': <uint64>,
'remote_max_htlcs': <uint32>,
'max_local_csv': <uint32>,
'commitment_type': <CommitmentType>,
'zero_conf': <bool>,
'scid_alias': <bool>,
'base_fee': <uint64>,
'fee_rate': <uint64>,
'use_base_fee': <bool>,
'use_fee_rate': <bool>,
'remote_chan_reserve_sat': <uint64>,
'fund_max': <bool>,
'memo': <string>,
'outpoints': <OutPoint>,
}
r = requests.post(url, headers=headers, data=json.dumps(data), verify=TLS_PATH)
print(r.json())
# {
# "funding_txid_bytes": <bytes>,
# "funding_txid_str": <string>,
# "output_index": <uint32>,
# }
# There is no CLI command for this RPC
Messages
lnrpc.OpenChannelRequest
Source: lightning.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
sat_per_vbyte | uint64 | string | body |
node_pubkey | bytes | string | body |
node_pubkey_string deprecated | string | string | body |
local_funding_amount | int64 | string | body |
push_sat | int64 | string | body |
target_conf | int32 | integer | body |
sat_per_byte deprecated | int64 | string | body |
private | bool | boolean | body |
min_htlc_msat | int64 | string | body |
remote_csv_delay | uint32 | integer | body |
min_confs | int32 | integer | body |
spend_unconfirmed | bool | boolean | body |
close_address | string | string | body |
funding_shim | FundingShim | object | body |
remote_max_value_in_flight_msat | uint64 | string | body |
remote_max_htlcs | uint32 | integer | body |
max_local_csv | uint32 | integer | body |
commitment_type | CommitmentType | string | body |
zero_conf | bool | boolean | body |
scid_alias | bool | boolean | body |
base_fee | uint64 | string | body |
fee_rate | uint64 | string | body |
use_base_fee | bool | boolean | body |
use_fee_rate | bool | boolean | body |
remote_chan_reserve_sat | uint64 | string | body |
fund_max | bool | boolean | body |
memo | string | string | body |
outpoints | OutPoint[] | array | body |
lnrpc.ChannelPoint
Source: lightning.proto
Field | gRPC Type | REST Type |
---|---|---|
funding_txid_bytes | bytes | string |
funding_txid_str | string | string |
output_index | uint32 | integer |
Nested Messages
lnrpc.ChannelPoint
Field | gRPC Type | REST Type |
---|---|---|
funding_txid_bytes | bytes | string |
funding_txid_str | string | string |
output_index | uint32 | integer |
lnrpc.ChanPointShim
Field | gRPC Type | REST Type |
---|---|---|
amt | int64 | string |
chan_point | ChannelPoint | object |
local_key | KeyDescriptor | object |
remote_key | bytes | string |
pending_chan_id | bytes | string |
thaw_height | uint32 | integer |
musig2 | bool | boolean |
lnrpc.FundingShim
Field | gRPC Type | REST Type |
---|---|---|
chan_point_shim | ChanPointShim | object |
psbt_shim | PsbtShim | object |
lnrpc.KeyDescriptor
Field | gRPC Type | REST Type |
---|---|---|
raw_key_bytes | bytes | string |
key_loc | KeyLocator | object |
lnrpc.KeyLocator
Field | gRPC Type | REST Type |
---|---|---|
key_family | int32 | integer |
key_index | int32 | integer |
lnrpc.OutPoint
Field | gRPC Type | REST Type |
---|---|---|
txid_bytes | bytes | string |
txid_str | string | string |
output_index | uint32 | integer |
lnrpc.PsbtShim
Field | gRPC Type | REST Type |
---|---|---|
pending_chan_id | bytes | string |
base_psbt | bytes | string |
no_publish | bool | boolean |
Enums
lnrpc.CommitmentType
Name | Number |
---|---|
UNKNOWN_COMMITMENT_TYPE | 0 |
LEGACY | 1 |
STATIC_REMOTE_KEY | 2 |
ANCHORS | 3 |
SCRIPT_ENFORCED_LEASE | 4 |
SIMPLE_TAPROOT | 5 |
SIMPLE_TAPROOT_OVERLAY | 6 |