L402 Quickstart

Turn any HTTP endpoint into a profit center. Buy resources from any L402-gated API.

As a client

To buy L402-gated resources, you do not need specialized software, At a minimum, you only need Curlarrow-up-right and access to a Lightning wallet or API. This makes it easy to implement L402 functionality into any client, such as a web browser, a wallet, a python script or your application.

  1. Request a resource Requesting a resource is as simple as: curl https://lightningfaucet.com/api/l402/headers

    import requests
    resource_url = "https://lightningfaucet.com/api/l402/headers"
    requests.get(resource_url)
  2. Extract the macaroon and Lightning invoice

    In the response, you should see the invoice and the macaroon. Save the macaroon and pass the Lightning invoice to your Lightning payment service.

  3. Pay the Lightning invoice

    The invoice may be paid by your nodearrow-up-right, a service you run, a wallet API or another service you subscribe to. The only requirement is that the service you are using is able to provide you with the preimage once the payment is successful.

  4. Assemble the L402 from the macaroon and preimage

    Once you have obtained the preimage, assembling the L402 is straightforward: <macaroon>:<preimage>

  5. Re-request the resource

    You may now re-request the resource while passing the L402 as part of the header:

    curl -X POST -H {"Authorization": L402 <macaroon>:<preimage>"} https://lightningfaucet.com/api/l402/headers

    import requests
    headers = {"Authorization": f"L402 {macaroon}:{preimage}"}
    new_response = requests.get(resource_url, headers=headers)

You should now be able to download or access the gated resource.

See also: Py402, a command line demonstration tool written in Pythonarrow-up-right

As a server

As a server, you will need an L402 proxy, such as Aperture. This proxy will need a connection to a Lightning Network node or service to generate invoices. Whether an L402 is valid can be verified using only the root key of the macaroon, without checking with the node whether the payment was received.

Get Aperturechevron-right

Last updated

Was this helpful?