Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting the node state API docs

At any point we can fetch our balance from the node and check the lightning and onchain balances.

Rust
let node_state = sdk.node_info()?;
let balance_ln = node_state.channels_balance_msat;
let balance_onchain = node_state.onchain_balance_msat;
Swift
if let nodeInfo = try? sdk.nodeInfo() {
    let lnBalance = nodeInfo.channelsBalanceMsat
    let onchainBalance = nodeInfo.onchainBalanceMsat
    print(lnBalance);
    print(onchainBalance);
}
Kotlin
try {
    val nodeInfo = sdk.nodeInfo()
    val lnBalance = nodeInfo?.channelsBalanceMsat
    val onchainBalance = nodeInfo?.onchainBalanceMsat
} catch (e: Exception) {
    // handle error
}
React Native
try {
  const nodeState = await nodeInfo()
  const balanceLn = nodeState.channelsBalanceMsat
  const balanceOnchain = nodeState.onchainBalanceMsat
} catch (err) {
  console.error(err)
}
Dart
NodeState? nodeInfo = await breezSDK.nodeInfo();
if (nodeInfo != null) {
  int lnBalance = nodeInfo.channelsBalanceMsat;
  int onchainBalance = nodeInfo.onchainBalanceMsat;
  print(lnBalance);
  print(onchainBalance);
}
Python
node_info = sdk_services.node_info()
ln_balance = node_info.channels_balance_msat
onchain_balance = node_info.onchain_balance_msat
Go
nodeInfo, err := sdk.NodeInfo()
if err != nil {
    return err
}

lnBalance := nodeInfo.ChannelsBalanceMsat
onchainBalance := nodeInfo.OnchainBalanceMsat

log.Printf("%#v %#v", lnBalance, onchainBalance)
C#
try
{
    var nodeInfo = sdk.NodeInfo();
    var lnBalance = nodeInfo?.channelsBalanceMsat;
    var onchainBalance = nodeInfo?.onchainBalanceMsat;
}
catch (Exception)
{
    // Handle error
}

You are now ready to receive a Lightning payment.