-
-
Save tiero/f3e7b511a8bb99f2b5f603418b808b5e to your computer and use it in GitHub Desktop.
NWC, L402, OpenAI example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { fetchWithL402 } from "alby-tools"; | |
import { webln } from "alby-js-sdk"; | |
import 'websocket-polyfill'; | |
import * as crypto from 'crypto'; // or 'node:crypto' | |
globalThis.crypto = crypto; | |
const nwcURL = process.env.NWC_URL; | |
async function main() { | |
const nwc = new webln.NWC({ nostrWalletConnectUrl: nwcURL }); | |
nwc.on("sendPayment", console.log); | |
const payload = { | |
"prompt": "make me a sandwitch", | |
"n": 1, | |
"size": "1024x1024" | |
}; | |
const res = await fetchWithL402( | |
"https://matador-ai.replit.app/v1/images/generations", | |
{ | |
method: "POST", | |
body: JSON.stringify(payload), | |
mode: "cors", | |
headers: { "Content-Type": "application/json", "Accept": "application/json" } | |
}, { | |
header_key: "L402", | |
webln: nwc | |
} | |
); | |
console.log(res); | |
const data = await res.json(); | |
console.log(data); | |
nwc.close(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment