Skip to content

go JSON API client for interacting with an Acinq Elcair Lightning node

Notifications You must be signed in to change notification settings

edobtc/go-eclair

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go eclair

what?

A simple API client for Acinq's Eclair lightning node JSON API

Examples

Some helpful examples are available in the examples folder

Create Invoice

client = client.WithBaseURL("http://localhost:8282")

invoice, err := client.CreateInvoice({
    Description: "Groceries"
    Amount: 100000,
})
if err != nil {
    panic(err)
}

fmt.Println(invoice.Serialized)

Pay Invoice

resp, err := client.PayInvoice(eclair.PayInvoiceRequest{
    Invoice: resp.Serialized,
})
fmt.Println(resp.Message)

Watching Events

It is possible to listen for a handful of events that the node emits. This is done over websocket. Events that be subscribed to:

Event Type Description
payment-received A payment has been received
payment-relayed A payment has been successfully relayed
payment-sent A payment has been successfully sent
payment-settling-onchain A payment wasn't fulfilled and its HTLC is being redeemed on-chain
payment-failed A payment failed
channel-created A channel opening flow has started
channel-opened A channel opening flow has completed
channel-state-changed A channel state changed (e.g. going from offline to connected)
channel-closed A channel has been closed
onion-message-received An onion message was received

To open a channel and watch for events

client = client.WithBaseURL("http://localhost:8282") // if you are using polar for a local setup

channel, err := client.Subscribe()
if err != nil {
    panic(err)
    return
}

// example fo handling events
for message := range channel {
    switch message.Type {
    case eclair.ChannelOpenedEvent:
        // handle channel opened event
    case eclair.ChannelClosedEvent:
        // handle channel closed event
    case eclair.PaymentReceivedEvent
        // handle channel closed event
    //...etc for all/any message type
    }
}

About

go JSON API client for interacting with an Acinq Elcair Lightning node

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages