# Bitcoin Lightning Network

Source: https://developers.bitgo.com/docs/bitcoin-lightning

## Overview

The Bitcoin Lightning Network is a second-layer protocol that enables fast, low-cost, and scalable bitcoin payments by conducting transactions off-chain through payment channels. These channels enable participants to transact instantly, without waiting for on-chain block confirmations. The Lightning Network also supports microtransactions, making small payments more feasible. Final balances settle on-chain only when a channel closes, reducing load on the Bitcoin base layer.

## Wallets Types

Currently, BitGo offers custody Lightning wallets. However, unlike other custody wallet types at BitGo, Lightning wallets are single-signature hot wallets.

## Ticker Symbols

| Mainnet | Testnet |
| ------- | ------- |
| lnbtc | tlntbc |

## Units

On the Bitcoin network, bitcoin is divisible by 10<sup>-8</sup> and the base unit is a satoshi (sat). However, on the Lightning Network, bitcoin is divisible by 10<sup>-12</sup> and the base unit is a millisatoshi (msat):

- 1 bitcoin = 100,000,000 satoshi or 100,000,000,000 millisatoshi
- 1 satoshi = 0.00000001 bitcoin or 1,000 millisatoshis
- 1 millisatoshi = 0.00000000001 bitcoin or 0.001 satoshi

## Tokens

The Lightning blockchain doesn't natively support tokens.

## Fees

Lightning transactions have no minimum or default fees.

## Create Wallet

When you create a Lightning wallet, BitGo creates a Lightning node with a hosting service provider. This process takes approximately 30 minutes to complete. BitGo sends you an email notification when the wallet is ready to use.

>Endpoint: [Generate Wallet](/reference/expresswalletgenerate)

```shell cURL
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export COIN="tlntbc"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export LABEL="<YOUR_WALLET_NAME>"
export PASSPHRASE="<YOUR_BITGO_LOGIN_PASSPHRASE>"
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"

curl -X POST \
  http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/generate \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "label": "'"$LABEL"'",
    "passphrase": "'"$PASSPHRASE"'",
    "enterprise": "'"$ENTERPRISE_ID"'"
    "type": "hot",
    "subType": "lightningCustody" # required for lightning wallets
}'
```
```js JavaScript
const { BitGo } = require('bitgo');

// Fill in with actual access token
const accessToken = '<YOUR_ACCESS_TOKEN>';

// Initialize the SDK
const bitgo = new BitGo({
accessToken: accessToken,
env: 'test',
});

// Generate hot wallet
async function createCustodialHotWallet() {
const newWallet = await bitgo.coin('tlnbtc').wallets().generateWallet({
    label: '<YOUR_WALLET_NAME>',
    passphrase: '<YOUR_BITGO_LOGIN_PASSPHRASE>',
    enterprise: '<YOUR_ENTERPRISE_ID>'
    subType: 'lightningCustody'
});

console.log(JSON.stringify(newWallet, undefined, 2));
}
```

## Create Address

Creating an address is an important step to opening a channel on the Lightning Network, because it prompts the Lightning node to generate a single-signature address for the funding transaction.

>Endpoint: [Create Address](/reference/v2walletnewaddress)

```shell cURL
export COIN="tlnbtc"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/$COIN/wallet/$WALLET_ID/address \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```
```js JavaScript
const { BitGo } = require('bitgo');
const accessToken = '<YOUR_ACCESS_TOKEN>';

// Initialize the SDK
const bitgo = new BitGo({
  accessToken: accessToken,
  env: 'test',
  customRootURI: 'https://app.bitgo-test.com',
});

// Enter your Lightning wallet
const walletId = '<YOUR_WALLET_ID>'
const existingWallet = await bitgo.coin('tlnbtc').wallets().get({ id: walletId });

const address = await wallet.createAddress(
);
console.log(JSON.stringify(address, undefined, 2));
```

## See Also

- [Concept: BitGo Wallet Types](/docs/wallet-types)
- [Guide: Bitcoin Lightning Network Overview](/docs/wallets-lightning-overview)
- [Guide: Wallets Overview](/docs/wallets-overview)
