Skip to content

Instantly share code, notes, and snippets.

@bumi
Created July 14, 2023 12:55
Show Gist options
  • Save bumi/32e8462344060defe6ea4c2d90ea29d9 to your computer and use it in GitHub Desktop.
Save bumi/32e8462344060defe6ea4c2d90ea29d9 to your computer and use it in GitHub Desktop.
NWC, L402, OpenAI example
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