getAlby / js-lightning-tools

Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps
https://www.npmjs.com/package/@getalby/lightning-tools
MIT License
34 stars 14 forks source link

Zap does not get posted #131

Closed rafiki71 closed 11 months ago

rafiki71 commented 11 months ago

This is how I Zap:

export async function sendZap(lightningAddress, satoshi, comment, relays, eventId) {
  try {
    if (!lightningAddress) {
      throw new Error("Keine gültige Lightning-Adresse angegeben.");
    }

    const ln = new LightningAddress(lightningAddress);
    await ln.fetch();

    if (!ln.nostrPubkey) {
      throw new Error("Nostr-Pubkey für die Lightning-Adresse fehlt.");
    }

    const zapArgs = {
      satoshi: satoshi,
      comment: comment,
      relays: relays,
      e: eventId,
    };

    if (window.webln) {
      const ret = await ln.zap(zapArgs);
      return ret;
    } else {
      // Alternatives Vorgehen, wenn WebLN nicht verfügbar ist
      const invoice = await ln.zapInvoice(zapArgs);
      console.log("Zap-Rechnung generiert:", invoice.paymentRequest);
      // Weitere Schritte zur Abwicklung der Zahlung
    }
  } catch (error) {
    console.error("Fehler beim Senden des Zaps:", error);
    throw error; // oder benutzerdefinierten Fehler werfen
  }
}

when running this function, getAlby asks me to sign a event which I consider correct. then it does the transaction, and is successful. My Console prints the preimage and says that everything is fine. but after the whole process I cannot find the nostr-event I have signed. this is how I call the method:

 function handleSendSats() {
        // Hier rufen Sie sendZap statt sendSatsLNurl auf
        if (lnAddress && satsAmount > 0) {
            console.log("offerEvent.id:", offerEvent.id);
            sendZap(
                lnAddress,
                satsAmount,
                "Zahlung für Angebot",
                ["wss://relay.damus.io", "wss://relay.plebstr.com"],
                offerEvent.id,
            )
                .then((response) => {
                    console.log(
                        "Zap erfolgreich gesendet, Preimage:",
                        response.preimage,
                    );
                })
                .catch((error) => {
                    console.error("Fehler beim Senden des Zaps:", error);
                });
        } else {
            console.error("Keine gültige Lightning-Adresse oder Sats-Menge");
        }
    }

Could you help me find the problem? from my understanding the nostr-post should be there after successfully sending sats.

Kind regards, a pleb that needs help :)

rafiki71 commented 11 months ago

I was looking for event 9734. But this is the request event. After looking for 9735, it worked. sorry :) I hope this will help someone else anyways.

rolznz commented 11 months ago

@rafiki71 I'm glad you figured it out! I will close this issue for now