Builder's Guide
  • Welcome to the Builder's Guide to the LND Galaxy!
  • The Lightning Network
    • Overview
    • Payment Channels
      • Lifecycle of a Payment Channel
      • Watchtowers
      • Understanding Sweeping
      • Etymology
    • The Gossip Network
      • Identifying Good Peers on the Lightning Network
    • Pathfinding
      • Finding routes in the Lightning Network
      • Channel Fees
      • Multipath Payments (MPP)
    • Lightning Network Invoices
      • Understanding Lightning Invoices
    • Making Payments
      • The Payment Cycle
      • Timelocks
      • ⭐Hashed Timelock Contract (HTLC)
      • Payment Etymology
      • ⭐What Makes a Good Routing Node
      • Understanding Submarine Swaps
      • Instant Submarine Swaps
    • Liquidity
      • ⭐Understanding Liquidity
      • Managing Liquidity on the Lightning Network
      • Liquidity Management for Lightning Merchants
      • How to Get Inbound Capacity on the Lightning Network
      • Lightning Service Provider
    • L402: Lightning HTTP 402 Protocol
      • Macaroons
      • L402
      • 📋Protocol Specification
      • Implementations and Links
    • Taproot Assets
      • Taproot Assets Protocol
      • Taproot Assets on Lightning
      • Edge Nodes
      • Taproot Assets Trustless Swap
      • FAQ
      • Glossary
  • Lightning Network Tools
    • LND
      • 🛠️Get Started
      • lnd.conf
      • First Steps With LND
      • Wallet Management
      • Sending Payments
      • Atomic Multi-path Payments (AMP)
      • Receiving Payments
      • Unconfirmed Bitcoin Transactions
      • Channel Fees
      • Inbound Channel Fees
      • Macaroons
      • Configuring Watchtowers
      • Pathfinding
      • Blinded Paths
      • Key Import
      • Secure Your Lightning Network Node
      • Configuration of a Routing Node
      • Quick Tor Setup
      • Configuring Tor
      • Enable ‘Neutrino mode’ in Bitcoin Core
      • Send Messages With Keysend
      • Partially Signed Bitcoin Transactions
      • Bulk onchain actions with PSBTs
      • Sweeper
      • Debugging LND
      • Fuzzing LND
      • LND API documentation
      • Channel Acceptor
      • RPC Middleware Interceptor
      • HTLC Interceptor
      • NAT Traversal
      • Recovery: Planning for Failure
      • Migrating LND
      • Disaster recovery
      • Contribute to LND
    • Lightning Terminal
      • What is Lightning Terminal?
      • 🛠️Get litd
      • Run litd
      • Integrating litd
      • Demo: Litd Speed Run
      • Connect to Terminal
      • Recommended Channels
      • Rankings
      • Health Checks
      • Liquidity Report
      • Opening Lightning Network Channels
      • Managing Channel Liquidity
      • Autofees
      • AutoOpen
      • LND Accounts
      • Loop and Lightning Terminal
      • Loop Fees
      • Pool and Lightning Terminal
      • Command Line Interface
      • Troubleshooting
      • Lightning Node Connect: Under the hood
      • LNC Node Package
      • LITD API Documentation
      • Privacy and Security
      • Privacy Policy
      • Terms of Use
    • Loop
      • 🛠️Get Started
      • The Loop CLI
      • Autoloop
      • Static Loop In Addresses
      • Instant Loop Outs
      • Peer with Loop
      • Loop API Documentation
    • Pool
      • Overview
      • Quickstart
      • 🛠️Installation
      • First Steps
      • Accounts
      • Orders and Asks
      • Sidecar Channels
      • Zero-confirmation Channels
      • Channel Leases
      • Batch Execution
      • Account Recovery
      • Pool API Documentation
      • FAQs
    • Taproot Assets
      • Get Started
      • First Steps
      • Taproot Assets Channels
      • Asset Decimal Display
      • Become an Edge Node
      • RFQ
      • Collectibles
      • Universes
      • Asset Loop
      • Debugging Tapd
      • Multisignature
      • Minting Assets With an External Signer
      • Lightning Polar
      • Operational Safety Guidelines
      • Taproot Assets API Documentation
    • Aperture
      • ⚒️Get Aperture
      • LNC Backend
      • LNC Mailbox
      • Pricing
    • Faraday
      • 🛠️Get Started
      • The Faraday CLI
      • Faraday API Documentation
  • LAPPs
    • Guides
      • Use Polar to Build Your First LAPP
        • Setup: Local Cluster with Polar
        • Setup: Run the Completed App
        • Setup: Run the App Without LND
      • Add Features
        • Feature 1: Connect to LND
        • Feature 2: Display Node Alias and Balance
        • Feature 3: Sign and Verify Posts
        • Feature 4: Modify Upvote Action
      • Make Your own LNC-powered Application
    • Next Steps
  • Community Resources
    • Resource List
    • Lightning Bulb 💡
    • Glossary
    • FAQ
Powered by GitBook
On this page
  • Enable your node to receive keysend
  • Send a spontaneous payment
  • Paying AMP invoices
  • Send a message to other nodes
  • Send keysend messages using RPC

Was this helpful?

  1. Lightning Network Tools
  2. LND

Send Messages With Keysend

Learn how to send messages to anyone in the Lightning Network from the command line

PreviousEnable ‘Neutrino mode’ in Bitcoin CoreNextPartially Signed Bitcoin Transactions

Last updated 8 months ago

Was this helpful?

Keysend allows users in the Lightning network to send payments to others , directly to their public key, as long as their node has public channels and has keysend enabled. Keysend does not require the payee to issue an invoice.

This payment type can also be used to attach messages and other data.

Keysend is currently implemented in LND in two ways, the widely accepted “--keysend” and the newer “”

Enable your node to receive keysend

To make sure you are able to receive spontaneous payments, add the following lines to your lnd.conf file:

accept-amp=true
accept-keysend=true

Then restart your node with lncli stop and lnd.

If you want to accept spontaneous payments using AMP, you may also create an invoice with routing hints and distribute it to prospective payers. You can use the command:

lncli addinvoice –amp

You can optionally also specify an amount (--amt), expiry (--expiry), a memo (--memo) routing hints are needed if your node only has private channels (--private).

Send a spontaneous payment

To send a spontaneous payment, you can craft a command like this:

lncli sendpayment --dest <destination public key> --amt <amount> --keysend

or using AMP (recommended):

lncli sendpayment --dest <destination public key> --amt <amount> --amp

Paying AMP invoices

If the payee has a private node without public channels, they can create an AMP invoice and include routing hints as explained above. The payer can then pay this invoice with the command:

lncli payinvoice <invoice>

If an amount is not set in the invoice, it can be set by the payer with

lncli payinvoice <invoice> –amt <amount>

Send a message to other nodes

You can include messages into your spontaneous payments with the –data flag. It must follow the convention <record_id>=<hex_value>,<record_id>=<hex_value>,..

You can encode any data in hex, either using your favorite command line or web tool.

The phrase “Happy Genesis Block Day!” becomes 48617070792047656E6573697320426C6F636B2044617921

lncli sendpayment --dest 03006fcf3312dae8d068ea297f58e2bd00ec1ffe214b793eda46966b6294a53ce6 --amt 10 --data 34349334=48617070792047656E6573697320426C6F636B2044617921 --keysend

If the payee has created an AMP invoice, the data can also be appended to the command:

lncli payinvoice <invoice> --data 34349334=486170707920477265676F7269616E204E6577205965617220746F2065766572796F6E65206174204C696768746E696E67204C61627321

Send keysend messages using RPC

When using the RPC, it is important to remember to generate a random 32 byte preimage and pass this to LND, as without it LND would not be able to settle a failed HTLC.

def send_keysend(
    amt: int,
    dest_pubkey: str = "",
    keysend_message: str = "sample message",
)

    my_node = "https://127.0.0.1:8080/"
    headers, cert = get_lnd_headers_cert(admin=True, node=node)
    if not dest_pubkey:
        dest_pubkey = destination_public_key
# Base 64 encoded destination bytes
    dest = b64_hex_transform(dest_pubkey)
# We generate a random 32 byte Hex pre_image here.
    pre_image = token_hex(32)
# This is the hash of the pre-image
    payment_hash = sha256(bytes.fromhex(pre_image))
# The record 5482373484 is special: it carries the pre_image to the destination so it can be compared with the hash we pass via the payment_hash
    dest_custom_records = {
        5482373484: b64_hex_transform(pre_image),
        34349334: b64_transform(keysend_message),
    }
    url = f"{node}v1/channels/transactions"
    data = {
        "dest": dest,
        "amt": amt,
        "payment_hash": b64_hex_transform(payment_hash.hexdigest()),
        "dest_custom_records": dest_custom_records,
    }

    response = httpx.post(
        url=url, headers=headers, data=json.dumps(data), verify=cert
        )

Messages are typically sent with the record ID 34349334. You can find a registry for such records . You may also submit your own suggestions.

The full command below will send this message together with 10 satoshis to , where it is displayed publicly.

Below you can find some sample python code courtesy of showing how to send keysend messages using LND’s REST API.

The actual message is sent with record 34349334. Depending on the purpose of the message, may be used.

--amp
here
Amboss.space
@brianoflondon
other records