Actually, it might surprise you to learn that the Lightning Network never converts your Bitcoin into a token.
If you are looking through the code (like in lnd, Core Lightning, or the BOLT specifications), you won't find a "mint" or "wrap" function because the Bitcoin stays exactly as it is: a balance on the Bitcoin blockchain.
Instead of "tokenizing" Bitcoin, the code focuses on locking it. Here is where and how that happens in the logic:
1. The "Funding Transaction" (BOLT #2 & #3)
When you open a channel, the code executes what’s called a Funding Transaction.
* In the code: Look at BOLT #2 (Peer Protocol) and BOLT #3 (Transaction Formats).
* What happens: Your Bitcoin is moved into a 2-of-2 multi-signature address on the main Bitcoin blockchain.
* The Key Point: The "balance" you see in your Lightning wallet isn't a new token; it is a signed promise (a Commitment Transaction) that says you are entitled to a specific portion of that locked-up Bitcoin when the channel closes.
2. Commitment Transactions (The "Ledger")
The "code" of a Lightning payment is really just two people passing updated Bitcoin transactions back and forth without broadcasting them to the internet.
* If you have 1 BTC in a channel and send 0.1 BTC to a friend, your node doesn't "send a token."
* Instead, both nodes sign a new Bitcoin transaction where you get 0.9 BTC and they get 0.1 BTC.
* This new transaction replaces the old one. It is still valid Bitcoin code, just "held" off-chain until someone decides to settle.
3. HTLCs: The Logic Gate (BOLT #4)
When you route a payment through multiple people, the code uses Hash Time-Locked Contracts (HTLCs).
* The Code: This is detailed in BOLT #4.
* These are smart contracts that say: "I will give you X amount of Bitcoin IF you can show me the secret password (preimage) within the next 24 hours."
* Again, no tokens are created; it's just a conditional rule applied to the Bitcoin already sitting in the multi-sig wallet.
Why does it feel like a token?
The confusion often comes from the fact that Lightning transactions are instant, whereas Bitcoin transactions take 10 minutes. Because of that speed, many people assume it must be a "synthetic" version of Bitcoin.
However, in the source code, a Lightning payment is literally just a Bitcoin Script (P2WSH) that hasn't been broadcasted to the miners yet.
Would you like me to point you to the specific lines in the lnd or Core Lightning GitHub repositories that handle these "Commitment Transactions"?